Skip to content

CORENET-6816: Add NetworkPolicies for CNO and its operands#2892

Open
danwinship wants to merge 1 commit intoopenshift:masterfrom
danwinship:default-networkpolicies
Open

CORENET-6816: Add NetworkPolicies for CNO and its operands#2892
danwinship wants to merge 1 commit intoopenshift:masterfrom
danwinship:default-networkpolicies

Conversation

@danwinship
Copy link
Contributor

@danwinship danwinship commented Jan 27, 2026

NetworkPolicies for CNO and its operands.

For the most part I added default-deny policies to every Namespace yaml, to ensure that Namespaces end up isolated right away, and then added individual policies for each operand after that, based on the current best practices (which aren't always that "best" since we can't really match host-network traffic...)

Summary by CodeRabbit

  • New Features
    • Added network policies across multiple system namespaces to enforce default-deny by default and permit only required service communication (examples: API/webhook and metrics ports such as 6443, 8443, 9443, 8080, 17698, 9108).
  • Tests
    • Test expectations updated to account for the additional network policy resources in rendered manifests.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 27, 2026
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Jan 27, 2026

@danwinship: This pull request references CORENET-2953 which is a valid jira issue.

Details

In response to this:

I'm sure this will work on the first try...

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 27, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Appends multiple Kubernetes NetworkPolicy resources (namespace-wide default-deny and component-scoped policies) across bindata and manifests, and updates unit tests to expect the additional rendered NetworkPolicy objects.

Changes

Cohort / File(s) Summary
Default-Deny Namespace Policies
bindata/kube-proxy/000-ns.yaml, bindata/network-diagnostics/000-ns.yaml, bindata/network/frr-k8s/000-ns.yaml, bindata/network/multus/000-ns.yaml, bindata/network/node-identity/common/001-node-identity-namespace.yaml, bindata/network/ovn-kubernetes/common/000-ns.yaml, bindata/network/ovn-kubernetes/common/openshift-host-network-ns.yaml, bindata/networking-console-plugin/000-namespace.yaml, manifests/0000_70_cluster-network-operator_00_namespace.yaml
Appended NetworkPolicy documents (typically default-deny) to namespace manifests. Policies use podSelector: {}, policyTypes: [Ingress, Egress], and empty ingress/egress lists to enforce default-deny.
Component-Specific NetworkPolicies
bindata/network-diagnostics/networkpolicy.yaml, bindata/network/iptables-alerter/004-networkpolicy.yaml, bindata/network/multus-admission-controller/004-networkpolicy.yaml, bindata/network/network-metrics/003-networkpolicy.yaml, bindata/network/node-identity/managed/node-identity-networkpolicy.yaml, bindata/network/ovn-kubernetes/managed/networkpolicy.yaml, bindata/networking-console-plugin/005-networkpolicy.yaml
Added NetworkPolicy manifests scoped to specific pods/labels and ports (e.g., network-check-source/target ports 17698/8080, iptables-alerter egress to API server, multus admission controller ports 6443/8443, network-metrics port 8443, ovn-kubernetes port 9108, node-identity webhook port).
Unit Test Updates
pkg/network/kube_proxy_test.go, pkg/network/multus_admission_controller_test.go, pkg/network/multus_test.go, pkg/network/network_metrics_test.go, pkg/network/ovn_kubernetes_test.go, pkg/network/render_test.go
Adjusted expected rendered object counts and added assertions to include newly added NetworkPolicy resources in rendered outputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: adding NetworkPolicies for the Cluster Network Operator and its operands, which aligns with the file additions across multiple namespace manifests.
Stable And Deterministic Test Names ✅ Passed All test functions use stable, descriptive names with no dynamic information like timestamps, UUIDs, or generated suffixes.
Test Structure And Quality ✅ Passed Shell command lists test files in pkg/network directory tree.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci openshift-ci bot requested review from jcaamano and oribon January 27, 2026 16:44
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 27, 2026
@danwinship danwinship marked this pull request as draft January 27, 2026 21:29
@danwinship danwinship force-pushed the default-networkpolicies branch from e048e7a to 17fb479 Compare January 27, 2026 21:29
@danwinship
Copy link
Contributor Author

/test e2e-gcp-ovn

@danwinship danwinship force-pushed the default-networkpolicies branch from 17fb479 to cad642b Compare January 28, 2026 13:29
@danwinship
Copy link
Contributor Author

/test e2e-gcp-ovn

1 similar comment
@danwinship
Copy link
Contributor Author

/test e2e-gcp-ovn

@danwinship
Copy link
Contributor Author

/test e2e-metal-ipi-ovn-ipv6

@danwinship danwinship force-pushed the default-networkpolicies branch from cad642b to 9b46870 Compare January 29, 2026 14:17
@danwinship
Copy link
Contributor Author

/test e2e-metal-ipi-ovn-ipv6

@danwinship danwinship changed the title WIP: CORENET-2953: Add NetworkPolicies for CNO and its operands WIP: CORENET-6816: Add NetworkPolicies for CNO and its operands Jan 29, 2026
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Jan 29, 2026

@danwinship: This pull request references CORENET-6816 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set.

Details

In response to this:

I'm sure this will work on the first try...

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@danwinship danwinship force-pushed the default-networkpolicies branch from 9b46870 to c834076 Compare January 29, 2026 22:51
@danwinship danwinship changed the title WIP: CORENET-6816: Add NetworkPolicies for CNO and its operands CORENET-6816: Add NetworkPolicies for CNO and its operands Jan 30, 2026
@danwinship
Copy link
Contributor Author

/assign @knobunc
CI is on fire right now so it's hard to say for certain that this is completely working yet, but what do you think of the policies in general?

@danwinship
Copy link
Contributor Author

/test e2e-metal-ipi-ovn-ipv6
/test e2e-gcp-ovn

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 2, 2026
@danwinship danwinship force-pushed the default-networkpolicies branch from 2fc5761 to 6f22966 Compare February 3, 2026 21:26
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 3, 2026
@danwinship danwinship marked this pull request as ready for review February 4, 2026 14:03
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 4, 2026
@openshift-ci openshift-ci bot requested a review from arkadeepsen February 4, 2026 14:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@bindata/network/network-metrics/003-networkpolicy.yaml`:
- Around line 1-15: The NetworkPolicy resource (kind: NetworkPolicy,
metadata.name: network-metrics in namespace openshift-multus) currently allows
ingress to port 8443 from any source; update spec.ingress (for the podSelector
matchLabels: app: network-metrics-daemon and port: 8443) to add an ingress.from
that restricts sources to the openshift-monitoring namespace by using a
namespaceSelector matching that namespace (e.g., namespaceSelector.matchLabels:
name: openshift-monitoring), so only pods in the openshift-monitoring namespace
(prometheus-k8s ServiceAccount) can reach the metrics port.

In `@bindata/network/ovn-kubernetes/common/openshift-host-network-ns.yaml`:
- Around line 11-23: The default-deny NetworkPolicy named default-deny in the
openshift-host-network namespace blocks all traffic; add companion allow-list
NetworkPolicy resources in the same namespace to permit required host-network
traffic (e.g., control-plane API/etcd access, node metrics scraping, and any
necessary DNS/NTP) by creating NetworkPolicy objects that target the same
namespace and use podSelector/namespaceSelector/IPBlock and specific
ports/protocols to allow ingress and egress for control-plane endpoints and
metrics endpoints; ensure the new policies are scoped narrowly (use explicit
ports and selectors) and reference the existing NetworkPolicy by name
(default-deny) to make intent clear.
🧹 Nitpick comments (1)
bindata/network-diagnostics/networkpolicy.yaml (1)

35-37: Consider enforcing "no egress" via policyTypes.

The comment states "network-check-target does no egress," but since Egress is not in policyTypes, egress is actually unrestricted. If the intent is defense-in-depth, add Egress to policyTypes without any egress: rules to explicitly deny all outbound traffic.

♻️ Proposed change to enforce no egress
   policyTypes:
     # network-check-target does no egress
     - Ingress
+    - Egress

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Feb 5, 2026

@danwinship: This pull request references CORENET-6816 which is a valid jira issue.

Details

In response to this:

NetworkPolicies for CNO and its operands.

For the most part I added default-deny policies to every Namespace yaml, to ensure that Namespaces end up isolated right away, and then added individual policies for each operand after that, based on the current best practices (which aren't always that "best" since we can't really match host-network traffic...)

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@danwinship
Copy link
Contributor Author

/retest


// Check rendered object
g.Expect(len(objs)).To(Equal(10))
g.Expect(len(objs)).To(Equal(11))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danwinship Is this counting additional object i.e. network policy? In openshift-multus there are two objects increased.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unit test is only calling renderMultusAdmissionController, without calling renderMultus first. So the only new object is the admission controller's new NetworkPolicy.


// It's important that the namespace is first
g.Expect(len(objs)).To(Equal(32), "Expected 32 multus related objects")
g.Expect(len(objs)).To(Equal(34), "Expected 34 multus related objects")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danwinship Could you clarify, in context of the previous response, how does a network policy results in increasing the count by 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case, objs is the result of renderMultus, which renders the contents of bindata/network/multus and bindata/network/network-metrics, so it gets the new default-deny policy from the former and the new "allow ingress to metrics" NetworkPolicy from the latter.

@danwinship
Copy link
Contributor Author

/unassign knobunc

policyTypes:
- Ingress
- Egress
ingress:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check stuff like EIP or services healthcheck? Not sure how those run on managed clusters so just asking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The policy doesn't affect "traffic that is processed by ovn-kubernetes", it affects "traffic that passes through a pod in the openshift-ovn-kubernetes namespace". So EgressIP would only be affected if, say, some ovn-k process was acting as a proxy server. I'm not totally familiar with everything we've done in ovn-k, but I'm pretty sure we don't do anything like that.

And even if we did, it would probably go through the ovnkube-node pods, not ovnkube-control-plane, so it would still be hostNetwork even on HCP (which is also the answer for service health checks).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for the service health checks.

The EIP healthcheck is a connection that ovnkube-control-plane pod does to ovnkube-node pods on port 9107 to check their liveliness. I am not sure it is that same port on hosted clusters since things are proxied there in a number of weird ways. From the perspective of this policy that would be an egress connection, right? If so, it's covered by the allow-all egress rule here but might want to add it as doc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! updated

@jcaamano
Copy link
Contributor

/retest

@danwinship danwinship force-pushed the default-networkpolicies branch from 0a33f49 to 8b63839 Compare February 27, 2026 13:46
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Feb 27, 2026

@danwinship: This pull request references CORENET-6816 which is a valid jira issue.

Details

In response to this:

NetworkPolicies for CNO and its operands.

For the most part I added default-deny policies to every Namespace yaml, to ensure that Namespaces end up isolated right away, and then added individual policies for each operand after that, based on the current best practices (which aren't always that "best" since we can't really match host-network traffic...)

Summary by CodeRabbit

  • New Features
  • Added network security policies across system components to restrict network traffic and enhance cluster security by allowing only necessary communication between services.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
bindata/network/node-identity/managed/node-identity-networkpolicy.yaml (1)

17-19: Comment is misleading — - {} allows all egress, not just apiserver.

The comment on line 18 states "Allow to apiserver", but - {} is an allow-all egress rule. If the intent is to restrict egress to only the apiserver, this rule should be tightened with specific destinations. If allowing all egress is intentional (e.g., because restricting to apiserver is impractical), consider updating the comment to reflect the actual behavior.

📝 Suggested comment clarification (if allow-all is intentional)
  egress:
-   # Allow to apiserver
+   # Allow all egress (apiserver, DNS, etc.)
    - {}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bindata/network/node-identity/managed/node-identity-networkpolicy.yaml`
around lines 17 - 19, The comment "Allow to apiserver" is incorrect because the
egress rule using the empty rule "- {}" under egress allows all outbound
traffic; either replace the allow-all egress rule with a specific egress rule
that targets the apiserver (e.g., by setting hostname/IP/ports in the egress
rule) so egress only goes to the apiserver, or, if the allow-all behavior is
intentional, update the comment to state that this is an intentional allow-all
egress rule; refer to the egress stanza and the "- {}" rule in
node-identity-networkpolicy.yaml when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bindata/network/ovn-kubernetes/managed/networkpolicy.yaml`:
- Around line 13-16: The ingress rule under the ingress block has a malformed
ports structure: the port entry under ports must be a list item. Edit the
ingress -> ports section (the ingress key and its ports list) and change the
single mapping "port: 9108" to be a list entry by prefixing it with a dash so
the ports value is a YAML sequence (e.g., ports: - port: 9108).

---

Nitpick comments:
In `@bindata/network/node-identity/managed/node-identity-networkpolicy.yaml`:
- Around line 17-19: The comment "Allow to apiserver" is incorrect because the
egress rule using the empty rule "- {}" under egress allows all outbound
traffic; either replace the allow-all egress rule with a specific egress rule
that targets the apiserver (e.g., by setting hostname/IP/ports in the egress
rule) so egress only goes to the apiserver, or, if the allow-all behavior is
intentional, update the comment to state that this is an intentional allow-all
egress rule; refer to the egress stanza and the "- {}" rule in
node-identity-networkpolicy.yaml when making the change.

ℹ️ Review info

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 0a33f49 and 8b63839.

📒 Files selected for processing (22)
  • bindata/kube-proxy/000-ns.yaml
  • bindata/network-diagnostics/000-ns.yaml
  • bindata/network-diagnostics/networkpolicy.yaml
  • bindata/network/frr-k8s/000-ns.yaml
  • bindata/network/iptables-alerter/004-networkpolicy.yaml
  • bindata/network/multus-admission-controller/004-networkpolicy.yaml
  • bindata/network/multus/000-ns.yaml
  • bindata/network/network-metrics/003-networkpolicy.yaml
  • bindata/network/node-identity/common/001-node-identity-namespace.yaml
  • bindata/network/node-identity/managed/node-identity-networkpolicy.yaml
  • bindata/network/ovn-kubernetes/common/000-ns.yaml
  • bindata/network/ovn-kubernetes/common/openshift-host-network-ns.yaml
  • bindata/network/ovn-kubernetes/managed/networkpolicy.yaml
  • bindata/networking-console-plugin/000-namespace.yaml
  • bindata/networking-console-plugin/005-networkpolicy.yaml
  • manifests/0000_70_cluster-network-operator_00_namespace.yaml
  • pkg/network/kube_proxy_test.go
  • pkg/network/multus_admission_controller_test.go
  • pkg/network/multus_test.go
  • pkg/network/network_metrics_test.go
  • pkg/network/ovn_kubernetes_test.go
  • pkg/network/render_test.go
🚧 Files skipped from review as they are similar to previous changes (13)
  • pkg/network/ovn_kubernetes_test.go
  • bindata/network/ovn-kubernetes/common/000-ns.yaml
  • pkg/network/network_metrics_test.go
  • manifests/0000_70_cluster-network-operator_00_namespace.yaml
  • bindata/network/iptables-alerter/004-networkpolicy.yaml
  • bindata/networking-console-plugin/000-namespace.yaml
  • bindata/network-diagnostics/000-ns.yaml
  • pkg/network/kube_proxy_test.go
  • bindata/network/ovn-kubernetes/common/openshift-host-network-ns.yaml
  • pkg/network/multus_test.go
  • bindata/network/multus-admission-controller/004-networkpolicy.yaml
  • bindata/network/multus/000-ns.yaml
  • bindata/kube-proxy/000-ns.yaml

@danwinship danwinship force-pushed the default-networkpolicies branch from 8b63839 to 7b431e8 Compare February 27, 2026 14:29
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Feb 27, 2026

@danwinship: This pull request references CORENET-6816 which is a valid jira issue.

Details

In response to this:

NetworkPolicies for CNO and its operands.

For the most part I added default-deny policies to every Namespace yaml, to ensure that Namespaces end up isolated right away, and then added individual policies for each operand after that, based on the current best practices (which aren't always that "best" since we can't really match host-network traffic...)

Summary by CodeRabbit

  • New Features
  • Added network policies across multiple system namespaces to enforce default-deny by default and permit only required service communication (examples: API/webhook and metrics ports such as 6443, 8443, 9443, 8080, 17698, 9108).
  • Tests
  • Test expectations updated to account for the additional network policy resources in rendered manifests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@danwinship danwinship force-pushed the default-networkpolicies branch from 7b431e8 to 11814a6 Compare February 27, 2026 16:50
@danwinship danwinship force-pushed the default-networkpolicies branch from 11814a6 to d8d15af Compare February 28, 2026 14:01
@danwinship
Copy link
Contributor Author

/retest

@jcaamano
Copy link
Contributor

jcaamano commented Mar 3, 2026

The hypershift issues might be legit

/retest

@danwinship
Copy link
Contributor Author

/retest

@knobunc
Copy link
Contributor

knobunc commented Mar 3, 2026

Thanks Dan, this looks good to me.

@knobunc knobunc self-assigned this Mar 3, 2026
@knobunc
Copy link
Contributor

knobunc commented Mar 3, 2026

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 3, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 3, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danwinship, knobunc

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@danwinship
Copy link
Contributor Author

sigh, hypershift-e2e-aks is currently failing to even build images or something, so we can't tell if it's still having the maybe-NetworkPolicy-related failure.

@jcaamano
Copy link
Contributor

jcaamano commented Mar 4, 2026

/retest

@danwinship
Copy link
Contributor Author

/hold
let's give CI a chance to recover... nothing else depends on this PR so it can wait until just before freeze to merge

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 4, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 4, 2026

@danwinship: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/hypershift-e2e-aks d8d15af link true /test hypershift-e2e-aks
ci/prow/e2e-aws-ovn-hypershift-conformance d8d15af link true /test e2e-aws-ovn-hypershift-conformance
ci/prow/security d8d15af link false /test security
ci/prow/e2e-metal-ipi-ovn-dualstack-bgp-local-gw d8d15af link true /test e2e-metal-ipi-ovn-dualstack-bgp-local-gw

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants