-
Notifications
You must be signed in to change notification settings - Fork 104
CNTRLPLANE-2699: adding network policies for operator and operands #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
bindata/v3.11.0/openshift-apiserver/networkpolicy-allow.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Network policy for openshift-apiserver operand pods. | ||
| # | ||
| # Unlike kube-apiserver and etcd, the openshift-apiserver pods run on the pod | ||
| # network (they do NOT use hostNetwork), so NetworkPolicy applies to them. | ||
| # | ||
| # Egress: | ||
| # - Allow all egress for API server communication, etcd access, and DNS | ||
| # resolution. All egress is permitted because destination addresses can vary | ||
| # by cluster configuration. | ||
| # | ||
| # Ingress: | ||
| # - Allow ingress on port 8443 for API requests and metrics scraping. | ||
| # The apiserver performs its own authentication/authorization. | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-apiserver | ||
| namespace: openshift-apiserver | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| apiserver: "true" | ||
| ingress: | ||
| - ports: | ||
| - protocol: TCP | ||
| port: 8443 | ||
| egress: | ||
| - {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress | ||
21 changes: 21 additions & 0 deletions
21
bindata/v3.11.0/openshift-apiserver/networkpolicy-default-deny.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Default-deny policy for the openshift-apiserver namespace. | ||
| # This policy selects all pods in the namespace and enables default-deny for both | ||
| # ingress and egress by specifying policyTypes without any allow rules. | ||
| # | ||
| # NetworkPolicies are additive (use OR logic): | ||
| # - This policy enables default-deny for all pods | ||
| # - Subsequent policies add specific allow rules | ||
| # - If any policy allows traffic, that traffic is permitted | ||
| # - Policies cannot override or block traffic allowed by other policies | ||
| # | ||
| # Without this policy, all pods would have unrestricted network access (allow-all). | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: default-deny | ||
| namespace: openshift-apiserver | ||
| spec: | ||
| podSelector: {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Network policy for the openshift-apiserver-operator pod. | ||
| # | ||
| # Egress: | ||
| # - Allow all egress to support communication with the Kubernetes API server, | ||
| # whose IP address and port are not known at manifest time. This implicitly | ||
| # covers DNS resolution as well. | ||
| # | ||
| # Ingress: | ||
| # - Allow ingress on port 8443 (metrics) so that Prometheus can scrape metrics | ||
| # from the operator. | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-operator | ||
| namespace: openshift-apiserver-operator | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app: openshift-apiserver-operator | ||
| ingress: | ||
| - ports: | ||
| - protocol: TCP | ||
| port: 8443 | ||
| egress: | ||
| - {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Default-deny policy for the openshift-apiserver-operator namespace. | ||
| # This policy selects all pods in the namespace and enables default-deny for both | ||
| # ingress and egress by specifying policyTypes without any allow rules. | ||
| # | ||
| # NetworkPolicies are additive (use OR logic): | ||
| # - This policy enables default-deny for all pods | ||
| # - Subsequent policies add specific allow rules | ||
| # - If any policy allows traffic, that traffic is permitted | ||
| # - Policies cannot override or block traffic allowed by other policies | ||
| # | ||
| # Without this policy, all pods would have unrestricted network access (allow-all). | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: default-deny | ||
| namespace: openshift-apiserver-operator | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
egress: - {}removes meaningful egress isolation.This rule allows every destination and port for the selected pods, so the companion
default-denyno longer constrains outbound traffic fromopenshift-apiserver. If the goal is to harden the operand namespace, replace the unconditional allow with only the required DNS / kube-apiserver / etcd paths.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Network policies do not allow us to select endpoints on the host network (which the api server is running on). So we would either need to generate a network policy dynamically that contain the endpoints of the kubernetes service and regenerate it when they change, or we allow any egress (since the port is changeable).
Our guidance for this feature was do to the latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dusk125, understood — sincekube-apiserverandetcdrun on the host network,NetworkPolicypod/namespace selectors can't target them, making static egress restrictions impractical without a dynamic controller. Allowing all egress is the correct approach here. Thanks for the explanation!