-
Notifications
You must be signed in to change notification settings - Fork 156
CNTRLPLANE-2683: Add network policies to openshift-etcd pods #1544
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # NetworkPolicy for etcd operand pods in the openshift-etcd namespace. | ||
| # | ||
| # The etcd static pods use hostNetwork: true and bypass NetworkPolicy entirely. | ||
| # The guard, installer, and pruner pods run on the pod network and are subject to NetworkPolicy. | ||
| --- | ||
| # Documentation-only policy for etcd static pods (hostNetwork bypasses NetworkPolicy) | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: etcd-host-network-documentation | ||
| namespace: openshift-etcd | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| description: "Documentation-only policy - etcd pods use hostNetwork and bypass NetworkPolicy" | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app: etcd | ||
| policyTypes: [] | ||
| --- | ||
| # Allow installer and pruner pods to access the API server | ||
| # These pods manage etcd static pod manifests and need API access. | ||
| # We allow all egress because the API server IP address and port can vary. | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-installer-pruner-to-apiserver | ||
| namespace: openshift-etcd | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: | ||
| matchExpressions: | ||
| - key: app | ||
| operator: In | ||
| values: | ||
| - installer | ||
| - pruner | ||
| egress: | ||
| - {} | ||
| policyTypes: | ||
| - Egress | ||
| --- | ||
| # Allow guard pods to access etcd for health checks | ||
| # Guard pods probe etcd health endpoints. Since etcd uses hostNetwork, | ||
| # we allow egress to etcd's health check ports without destination restrictions. | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-guard-to-etcd | ||
| namespace: openshift-etcd | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| app: guard | ||
| egress: | ||
| - ports: | ||
| - protocol: TCP | ||
| port: 2379 | ||
| - protocol: TCP | ||
| port: 9980 | ||
| policyTypes: | ||
| - Egress | ||
| --- | ||
| # Allow guard, installer, and pruner pods to access DNS | ||
| # These pods may need to resolve service names. | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: allow-operand-helpers-to-dns | ||
| namespace: openshift-etcd | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: | ||
| matchExpressions: | ||
| - key: app | ||
| operator: In | ||
| values: | ||
| - guard | ||
| - installer | ||
| - pruner | ||
| egress: | ||
| - to: | ||
| - namespaceSelector: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| podSelector: | ||
| matchLabels: | ||
| dns.operator.openshift.io/daemonset-dns: default | ||
| ports: | ||
| - protocol: TCP | ||
| port: 5353 | ||
| - protocol: UDP | ||
| port: 5353 | ||
| - protocol: TCP | ||
| port: 53 | ||
| - protocol: UDP | ||
| port: 53 | ||
|
Comment on lines
+70
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Explore repo structure and find DNS-related configs
find . -type f -name "*.yaml" -o -name "*.yml" | head -20Repository: openshift/cluster-etcd-operator Length of output: 802 🏁 Script executed: # Search for openshift-dns references in the codebase
rg "openshift-dns" -t yamlRepository: openshift/cluster-etcd-operator Length of output: 179 🏁 Script executed: # Look for other NetworkPolicy files to understand DNS handling patterns
fd "network" -t f | grep -i "policy\|network"Repository: openshift/cluster-etcd-operator Length of output: 5518 🏁 Script executed: # Check if there are any comments or documentation about DNS networking
rg "hostNetwork" -t yaml -A 3 -B 3Repository: openshift/cluster-etcd-operator Length of output: 8866 🏁 Script executed: cat -n manifests/0000_12_etcd-operand_networkpolicies.yamlRepository: openshift/cluster-etcd-operator Length of output: 5017 🏁 Script executed: # Search for openshift-dns pod definitions or daemonset
rg "daemonset-dns|openshift-dns" -A 10 -B 2 --all-typesRepository: openshift/cluster-etcd-operator Length of output: 488 🏁 Script executed: # Check if there are any direct references to DNS pod specs
rg "dns\.operator\.openshift\.io" -A 5 -B 5 --all-typesRepository: openshift/cluster-etcd-operator Length of output: 488 🏁 Script executed: rg "daemonset-dns|openshift-dns" -A 5 -B 2Repository: openshift/cluster-etcd-operator Length of output: 929 🌐 Web query:
💡 Result:
What changes with
|
||
| policyTypes: | ||
| - Egress | ||
| --- | ||
| # Default-deny policy for the openshift-etcd 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 | ||
| # | ||
| # Note: etcd static pods use hostNetwork: true and bypass all NetworkPolicy rules. | ||
| # This policy only affects pods running on the pod network (guard, installer, pruner). | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: default-deny | ||
| namespace: openshift-etcd | ||
| annotations: | ||
| include.release.openshift.io/self-managed-high-availability: "true" | ||
| include.release.openshift.io/single-node-developer: "true" | ||
| spec: | ||
| podSelector: {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress | ||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: openshift/cluster-etcd-operator
Length of output: 128
🌐 Web query:
Kubernetes NetworkPolicy egress empty object {} allow all traffic semantics💡 Result:
In Kubernetes
NetworkPolicy, theegresslist is a list of allow rules. An empty rule object means “no constraints”, so:egress: - {}allows all egress traffic (all destinations, all ports / protocols supported by the plugin) from the pods selected bypodSelector. (v1-34.docs.kubernetes.io)policyTypes: [Egress]but provides no egress rules (for example,egress: []or omittingegress) is a “default deny egress” policy and allows no egress traffic from those selected pods. (v1-34.docs.kubernetes.io)Citations:
🏁 Script executed:
Repository: openshift/cluster-etcd-operator
Length of output: 1227
egress: - {}is allow-all egress and overly broad.Line 41-42 permits installer/pruner pods unrestricted egress to any destination and port. While the manifest comment (line 24) states the API server IP can vary, the API server ports are well-defined (443, 6443). Constrain egress to these ports to prevent unintended outbound traffic while maintaining functionality.
🔧 Tighten to API-server ports
spec: podSelector: matchExpressions: - key: app operator: In values: - installer - pruner egress: - - {} + - ports: + - protocol: TCP + port: 443 + - protocol: TCP + port: 6443 policyTypes: - Egress📝 Committable suggestion
🤖 Prompt for AI Agents