Skip to content

CONSOLE-5432: Add NetworkPolicy manifests for openshift-console-operator namespace#1198

Open
redhat-chai-bot wants to merge 1 commit into
openshift:mainfrom
redhat-chai-bot:CONSOLE-5432-networkpolicy-operator
Open

CONSOLE-5432: Add NetworkPolicy manifests for openshift-console-operator namespace#1198
redhat-chai-bot wants to merge 1 commit into
openshift:mainfrom
redhat-chai-bot:CONSOLE-5432-networkpolicy-operator

Conversation

@redhat-chai-bot

@redhat-chai-bot redhat-chai-bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds four CVO-managed NetworkPolicy manifests for the openshift-console-operator namespace, which hosts the operator controller pod.

These policies implement a default-deny baseline with targeted allow rules for the operator's legitimate network needs, improving network isolation for the namespace.

What this PR does

Adds four new files under manifests/:

  • 03-networkpolicy-operator-default-deny.yaml — Default deny all ingress and egress traffic. Uses podSelector: {} to cover all pods in the namespace.
  • 03-networkpolicy-operator-allow-dns-egress.yaml — Allow egress to CoreDNS pods in the openshift-dns namespace (TCP/UDP named ports dns-tcp/dns). The operator needs DNS resolution for Kubernetes service discovery and API server endpoint lookups.
  • 03-networkpolicy-operator-allow-apiserver-egress.yaml — Allow egress to the Kubernetes API server on port 6443. The operator controller needs API server access to watch and reconcile console-related resources.
  • 03-networkpolicy-operator-allow-metrics-ingress.yaml — Allow ingress from the openshift-monitoring namespace to the metrics port (60000). This enables Prometheus to scrape operator metrics.

All manifests include standard CVO release annotations, capability.openshift.io/name: Console for capability gating, and kubernetes.io/description annotations describing each policy's purpose.

Why

Part of the HPSTRAT-104 initiative to ship tailored NetworkPolicy resources with every control-plane operator by OCP 5.0. The default-deny with targeted allow rules improves network isolation by ensuring the operator controller pod only communicates through explicitly authorized paths.

References

Validation

  • make verify passes with no diff

@wking requested in Slack thread

Summary by CodeRabbit

  • New Features
    • Added network security policies for the console operator.
    • Enforced default-deny ingress and egress traffic across the operator namespace.
    • Allowed required operator egress traffic, including access to cluster services.
    • Enabled metrics traffic on the designated TCP port for monitoring and testing.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 24, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@redhat-chai-bot: This pull request references CONSOLE-5432 which is a valid jira issue.

Details

In response to this:

Summary

Adds four CVO-managed NetworkPolicy manifests for the openshift-console-operator namespace, which hosts the operator controller pod.

These policies implement a default-deny baseline with targeted allow rules for the operator's legitimate network needs, improving network isolation for the namespace.

What this PR does

Adds four new files under manifests/:

  • 03-networkpolicy-operator-default-deny.yaml — Default deny all ingress and egress traffic. Uses podSelector: {} to cover all pods in the namespace.
  • 03-networkpolicy-operator-allow-dns-egress.yaml — Allow egress to CoreDNS pods in the openshift-dns namespace (TCP/UDP named ports dns-tcp/dns). The operator needs DNS resolution for Kubernetes service discovery and API server endpoint lookups.
  • 03-networkpolicy-operator-allow-apiserver-egress.yaml — Allow egress to the Kubernetes API server on port 6443. The operator controller needs API server access to watch and reconcile console-related resources.
  • 03-networkpolicy-operator-allow-metrics-ingress.yaml — Allow ingress from the openshift-monitoring namespace to the metrics port (60000). This enables Prometheus to scrape operator metrics.

All manifests include standard CVO release annotations, capability.openshift.io/name: Console for capability gating, and kubernetes.io/description annotations describing each policy's purpose.

Why

Part of the HPSTRAT-104 initiative to ship tailored NetworkPolicy resources with every control-plane operator by OCP 5.0. The default-deny with targeted allow rules improves network isolation by ensuring the operator controller pod only communicates through explicitly authorized paths.

References

Validation

  • make verify passes with no diff

@wking requested in Slack thread

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 requested review from jhadvig and spadgett July 24, 2026 17:16
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Walkthrough

Adds three Kubernetes NetworkPolicy manifests for the openshift-console-operator namespace: a namespace-wide default deny, unrestricted egress for console-operator pods, and TCP metrics ingress for console-operator pods.

Changes

Operator network policies

Layer / File(s) Summary
Default-deny policy
manifests/03-networkpolicy-operator-default-deny.yaml
Applies ingress and egress default-deny behavior to all pods in the namespace.
Operator traffic allowances
manifests/03-networkpolicy-operator-allow-egress.yaml, manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
Allows all egress from console-operator pods and permits TCP ingress on the metrics port from any source.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: spadgett, jhadvig

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding NetworkPolicy manifests for the openshift-console-operator namespace.
Description check ✅ Passed The description covers the change, rationale, references, and validation, but leaves several template sections empty.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Only NetworkPolicy YAML manifests changed; no Ginkgo test titles were added or modified.
Test Structure And Quality ✅ Passed The PR changes only three YAML NetworkPolicy manifests; no Ginkgo or test code was added or modified.
Microshift Test Compatibility ✅ Passed No Ginkgo/e2e test code was added; the PR only changes three NetworkPolicy manifests, so MicroShift compatibility is not implicated.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PASS: The PR only adds YAML NetworkPolicy manifests; no Ginkgo e2e tests or test code were added, so the SNO compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed Only NetworkPolicy manifests were added; no replicas, affinity, nodeSelectors, tolerations, or PDBs were introduced, so topology-aware scheduling isn’t affected.
Ote Binary Stdout Contract ✅ Passed Diff adds only manifest YAMLs; no process-level code or stdout-producing binaries were changed.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed PR only adds NetworkPolicy manifests; no Ginkgo/e2e tests were added, so IPv4/disconnected compatibility check is not applicable.
No-Weak-Crypto ✅ Passed Changed files are only NetworkPolicy YAML; scans found no crypto APIs/algorithms or secret comparisons, just benign 'description' substrings.
Container-Privileges ✅ Passed The PR only adds NetworkPolicy manifests; no privileged, hostPID/Network/IPC, SYS_ADMIN, root, or allowPrivilegeEscalation settings are present.
No-Sensitive-Data-In-Logs ✅ Passed The PR only adds NetworkPolicy manifests; no log statements or sensitive-data fields appear in the changed files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml`:
- Around line 19-22: Constrain the egress rule under the API-server allowlist to
Kubernetes API-server destinations by adding the appropriate supported IP/CIDR
or peer selector in its `to` clause. If supported OpenShift/HyperShift
topologies require destination-less TCP 6443 access, document that rationale in
the manifest instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 98b602f6-83ad-40f1-82af-4e661da20dbb

📥 Commits

Reviewing files that changed from the base of the PR and between 6cda706 and 4cfbb1d.

📒 Files selected for processing (4)
  • manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml
  • manifests/03-networkpolicy-operator-allow-dns-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/console (manual)
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{yaml,yml,json}

📄 CodeRabbit inference engine (Custom checks)

**/*.{yaml,yml,json}: Flag privileged: true, hostPID, hostNetwork, hostIPC, SYS_ADMIN capability, running as root without justification, and allowPrivilegeEscalation: true in container/Kubernetes manifests
When deployment manifests, operator code, or controllers are added/modified, ensure they do not introduce scheduling constraints assuming standard HA topology (3+ control-plane nodes, dedicated workers). Flag: required pod anti-affinity with maxUnavailable: 0 (deadlocks on SNO/TNF/TNA), pod topology spread with DoNotSchedule and hostname key (breaks on SNO), replica counts derived from node count without topology awareness, nodeSelector/node affinity targeting control-plane nodes (fails on HyperShift), scheduling to all control-plane nodes equally without excluding arbiter nodes (TNA), assuming dedicated worker nodes exist (SNO/TNF), or PodDisruptionBudgets designed for 3+ nodes (TNF/TNA). Do not flag if change checks ControlPlaneTopology, node counts, or topology labels before applying constraints.

Files:

  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
  • manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml
  • manifests/03-networkpolicy-operator-allow-dns-egress.yaml
{manifests,bindata/assets,quickstarts,examples,profile-patches}/**/*.{yaml,yml}

📄 CodeRabbit inference engine (.claude/skills/manifest-review.md)

{manifests,bindata/assets,quickstarts,examples,profile-patches}/**/*.{yaml,yml}: Kubernetes manifests under manifests/, bindata/assets/, quickstarts/, examples/, and profile-patches/ must include the appropriate cluster profile annotations when they are CVO-deployed resources (for example include.release.openshift.io/hypershift, include.release.openshift.io/ibm-cloud-managed, include.release.openshift.io/self-managed-high-availability, and include.release.openshift.io/single-node-developer).
Console resources in the manifest trees must include the capability annotation capability.openshift.io/name: Console.
RBAC manifests must follow least-privilege design: grant only the permissions needed, avoid wildcards unless truly justified, use verbs that match the actual operation set, and set correct apiGroups ("" for core APIs and specific groups for CRDs).
Resources must use the correct namespace for their role: openshift-console for console workload resources and openshift-console-operator for operator resources; any cross-namespace reference must be explicit and intentional.
YAML manifests should use 2-space indentation, keep fields in a consistent order, and include --- separators between multiple resources in the same file.
When binding roles to service accounts, use console-operator in the openshift-console-operator namespace for operator cross-namespace access, and use console in the openshift-console namespace for console workload-scoped access.

Files:

  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
  • manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml
  • manifests/03-networkpolicy-operator-allow-dns-egress.yaml
**/*.yaml

⚙️ CodeRabbit configuration file

**/*.yaml: Review YAML manifests based on content and kind.

Refer to /manifest-review when YAML contains:

  • kind: Role or kind: ClusterRole (RBAC review)
  • kind: RoleBinding or kind: ClusterRoleBinding
  • annotations: section (check for cluster profiles)
  • verbs: ["*"] or wildcard permissions
  • apiGroups: ["*"] or overly broad permissions
  • ServiceAccount references in subjects

Check for required annotations in manifests/:

  • include.release.openshift.io/hypershift
  • include.release.openshift.io/ibm-cloud-managed
  • include.release.openshift.io/self-managed-high-availability
  • include.release.openshift.io/single-node-developer
  • capability.openshift.io/name: Console

For quickstarts/, additionally check:

  • QuickStart spec structure
  • Task descriptions and prerequisites
  • See quickstarts/README.md for guidelines

Files:

  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
  • manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml
  • manifests/03-networkpolicy-operator-allow-dns-egress.yaml
**/*.{yaml,yml}

⚙️ CodeRabbit configuration file

**/*.{yaml,yml}: If this is a Kubernetes/OpenShift manifest or Helm template:

  • securityContext: runAsNonRoot, readOnlyRootFilesystem,
    allowPrivilegeEscalation: false
  • Drop ALL capabilities, add only what is required
  • Resource limits (cpu, memory) on every container
  • No hostPID, hostNetwork, hostIPC, privileged: true
  • NetworkPolicy defined for the namespace
  • OpenShift: SCC must be restricted or custom-scoped
  • Liveness + readiness probes defined
  • automountServiceAccountToken: false unless needed
  • RBAC: least privilege; no cluster-admin for workloads
  • Helm: no .Values interpolation in shell commands

Files:

  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
  • manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml
  • manifests/03-networkpolicy-operator-allow-dns-egress.yaml
🔇 Additional comments (4)
manifests/03-networkpolicy-operator-default-deny.yaml (1)

1-21: LGTM!

manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml (1)

1-18: LGTM!

Also applies to: 23-24

manifests/03-networkpolicy-operator-allow-dns-egress.yaml (1)

1-34: LGTM!

manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml (1)

1-28: LGTM!

Comment thread manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml Outdated
@redhat-chai-bot
redhat-chai-bot force-pushed the CONSOLE-5432-networkpolicy-operator branch from 4cfbb1d to 460ee58 Compare July 24, 2026 17:24
# The API server runs on the host network, not the pod network,
# so it cannot be targeted via namespaceSelector/podSelector.
# A static ipBlock CIDR is also not feasible because API server
# IPs vary per cluster and this is a CVO-managed static manifest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of including context like this in a YAML comment only visible to folks with Git access, can you shift it into the kubernetes.io/description annotation? That way, the context is also available to curious cluster-admins in-cluster.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call — shifting the rationale into kubernetes.io/description now so it's visible in-cluster. Removing the YAML comments.

@wking wking Jul 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Addressed in 18cb6b1. This thread can be marked resolved, but I don't have access to do that myself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved — thanks for confirming!

@redhat-chai-bot
redhat-chai-bot force-pushed the CONSOLE-5432-networkpolicy-operator branch 2 times, most recently from 63898f1 to 18cb6b1 Compare July 24, 2026 17:37
DNS resolution needs. In the future, cluster-scoped
AdminNetworkPolicy may allow tighter restrictions.
spec:
podSelector: {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checking a 5.0 nightly CI run's gather-extra artifacts:

$ curl -s https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/logs/periodic-ci-openshift-release-main-ci-5.0-e2e-aws-ovn/2080425132433608704/artifacts/e2e-aws-ovn/gather-extra/artifacts/pods.json | jq -c '.items[].metadata | select(.namespace == "openshift-console-operator").labels'
{"name":"console-operator","pod-template-hash":"c58f98658","topology.kubernetes.io/region":"us-west-1","topology.kubernetes.io/zone":"us-west-1c"}

so the operator is the only thing running, and that name=console-operator label is the pod-selector the Deployment uses. Can you use that podSelector here, to avoid granting broad egress access to any Pods besides the console operator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — podSelector: {} is needlessly broad when we know the only pod is the operator with name: console-operator. Updating both the egress and metrics-ingress policies to use podSelector: matchLabels: name: console-operator. The default-deny will keep podSelector: {} since that baseline should cover all pods in the namespace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ae86d33 adds a podSelector here. This thread can be marked resolved; although I am not authorized to do that myself.

openshift-monitoring namespace. This enables Prometheus
to scrape operator metrics.
spec:
podSelector: {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as egress, it's not secure to use an empty pod-selector when granting access. Can you scope this down to just the console operator too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — scoping down to name: console-operator on the metrics-ingress too. Pushing shortly.

Default deny all ingress and egress traffic in the
openshift-console-operator namespace. The policy improves
network isolation by ensuring that the operator controller pod
only communicates through explicitly allowed policies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no podSelector on this one, so should be `The policy improves network isolation by ensuring that pods only communicate through explicitly allowed policies.".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — updating the description to use generic "pods" language since this policy covers all pods via podSelector: {}. Pushing now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest force-push (fbce1df07) — the default-deny annotation now reads:

"Default deny all ingress and egress traffic in the openshift-console-operator namespace. The policy improves network isolation by ensuring that pods only communicate through explicitly allowed policies."

Generic "pods" language since podSelector: {} covers all pods in the namespace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

18cb6b1 seems to have lost this reword. Can you try again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looking at the file at ae86d330f, the default-deny annotation currently reads:

"Default deny all ingress and egress traffic in the openshift-console-operator namespace. The policy improves network isolation by ensuring that pods only communicate through explicitly allowed policies."

This already uses generic "pods" language (not "the console operator pod"). Could you double-check against the latest commit? The squash should have preserved the fbce1df07 fix. If it still looks wrong on your end I'll re-push.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I was looking at an old commit. ae86d33 has the rewording. This thread can be marked resolved; although I am not authorized to do that myself.

needs Kubernetes API server access to watch and reconcile
console-related resources. Because the API server address and
port vary per cluster and the server runs on the host network,
they cannot be statically restricted in a CVO-managed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

New administrators may not be familiar with the "CVO" acronym. Can you unpack it "...in a NetworkPolicy managed by the cluster-version operator."?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do — expanding "CVO" to "cluster-version operator" in the annotation now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ae86d33 still contains the "CVO-managed" sentence. Can you try again to unpack to "...in a NetworkPolicy managed by the cluster-version operator."?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right — I see it's still there. Fixing now, will amend and force-push.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

5fde96a has the rewording. This thread can be marked resolved, although I'm not authorized to do that myself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5fde96af7 — now reads "a NetworkPolicy managed by the cluster-version operator" instead of "CVO-managed".

they cannot be statically restricted in a CVO-managed
NetworkPolicy. Opening all egress also covers DNS resolution
needs. In the future, cluster-scoped AdminNetworkPolicy may
allow tighter restrictions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't have a feature-tracker linked for this. And unless we do have somewhere folks can subscribe fore updates, I'd avoid "In the future..." statements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — removing the "In the future…" sentence. The annotation will just explain why open egress is needed without speculating about future improvements.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ae86d33 still contains the "In the future..." sentence. Can you try again to remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still there — sorry about that. Removing it now and force-pushing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

5fde96a has the rewording. This thread can be marked resolved, although I'm not authorized to do that myself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5fde96af7 — the "In the future..." sentence has been removed. The annotation now ends at "DNS resolution needs."

@redhat-chai-bot
redhat-chai-bot force-pushed the CONSOLE-5432-networkpolicy-operator branch from 492e9f0 to fbce1df Compare July 24, 2026 18:11
@@ -0,0 +1,29 @@
apiVersion: networking.k8s.io/v1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated to this line, I see no need for two commits here. Can you squash 18cb6b1 and fbce1df07e6806c1efd4fe264cb74010c731c74da together, with a commit message that explains the consolidated change? You shouldn't need to go into much detail in the commit message, because the kubernetes.io/description annotations should bring most of the context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will squash into a single commit with a concise message. Pushing shortly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ae86d33 squashed to one commit. This thread can be marked resolved, but I don't have authorization to do that myself.

@redhat-chai-bot
redhat-chai-bot force-pushed the CONSOLE-5432-networkpolicy-operator branch 2 times, most recently from ae86d33 to 5fde96a Compare July 24, 2026 18:49

@wking wking left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 24, 2026
@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: redhat-chai-bot, wking
Once this PR has been reviewed and has the lgtm label, please assign jhadvig for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@openshift-ci

openshift-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@redhat-chai-bot: 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/e2e-gcp-ovn 5fde96a link true /test e2e-gcp-ovn
ci/prow/e2e-aws-operator 5fde96a link true /test e2e-aws-operator

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.

- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: openshift-monitoring

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This limitation might be breaking e2e-aws-operator:

metrics_test.go:97: http error: Get "https://metrics-openshift-console-operator.apps.ci-op-f6j7t0d9-7ab6c.xxxxxxxxxxxxxxxxxxxxxx/metrics": EOF
    metrics_test.go:116: metrics request failed after several attempts: Get "https://metrics-openshift-console-operator.apps.ci-op-f6j7t0d9-7ab6c.xxxxxxxxxxxxxxxxxxxxxx/metrics": EOF
    metrics_test.go:46: waiting for cleanup to reach settled state...
--- FAIL: TestMetricsEndpoint (27.14s)

Not sure what to do about that. There's no status on NetworkPolicy to be able to tell if it's alive or having trouble or what. So a local test case could add an additional NetworkPolicy, then try to scrape metrics, and then remove its NetworkPolicy in post-test-case teardown. But there wouldn't be a way to gracefully wait for the NetworkPolicy to go live, you'd just be hammering away at the metrics endpoint until you got through.

Or we could drop the test, and assume TargetDown or other signs out of the monitoring side of things would catch us if we broke metrics serving.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — the TestMetricsEndpoint failure is caused by this policy. The test accesses metrics through a Route, so traffic arrives from openshift-ingress router pods — which the metrics-ingress policy blocks (only openshift-monitoring is whitelisted).

Options as I see them:

  1. Add openshift-ingress to the metrics-ingress from list — simplest fix, but widens the ingress surface beyond what's needed for production (the Route exists only for testing; Prometheus scrapes directly via pod IP).

  2. Have the test create a temporary NetworkPolicy allowing ingress from openshift-ingress, then clean up in teardown. As you noted, there's no status on NetworkPolicy so you'd need to poll/retry the metrics endpoint.

  3. Change the test to access metrics directly (e.g. kubectl port-forward or exec into a pod in the namespace) instead of going through a Route. This avoids needing any NetworkPolicy change.

  4. Drop the test and rely on TargetDown / monitoring alerts as you suggested.

Deferring to @soltysh on which approach fits best for the console operator's test philosophy. The GCP failure is unrelated infra (cluster bootstrap failure).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, actually, Developing Network Policies; Ingress to Metrics Endpoint currently says:

We allow anything to reach our metrics endpoint.

apiVersion: networking.k8s.io/v1	
kind: NetworkPolicy
metadata:
 name: allow-ingress-to-metrics
spec:
 podSelector:
   matchLabels:                      # You need to define this based on what pods support metrics, or remove for all
 ingress:
 - ports:
   - protocol: TCP
     port: 12345                 # Use the port number of your metrics endpoint
 policyTypes:
 - Ingress

so we can probably recover this test-case just by dropping the from here entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Perfect — much simpler. Dropping the from entirely and keeping just the ports restriction matches the guide's pattern and fixes the test in one shot. Pushing now.

…tor namespace

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@redhat-chai-bot
redhat-chai-bot force-pushed the CONSOLE-5432-networkpolicy-operator branch from 5fde96a to d07d8ca Compare July 25, 2026 05:48
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 25, 2026
@openshift-ci

openshift-ci Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@manifests/03-networkpolicy-operator-allow-egress.yaml`:
- Around line 25-26: Replace the unrestricted egress entry in the NetworkPolicy
with a destination-less TCP rule permitting only port 6443 for API-server
access, and add a separately scoped DNS egress rule limited to the required DNS
port and protocol. Keep static unrestricted egress removed and preserve the
policy’s existing scope and selectors.

In `@manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml`:
- Around line 13-16: Update the NetworkPolicy allowing metrics ingress to
restrict sources to the openshift-monitoring namespace, adding the appropriate
namespace/pod selector under from while preserving the named metrics port and
TCP protocol settings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b7ad8f0-d5ce-4407-8358-0da4c557cda3

📥 Commits

Reviewing files that changed from the base of the PR and between 4cfbb1d and d07d8ca.

📒 Files selected for processing (3)
  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
  • manifests/03-networkpolicy-operator-default-deny.yaml
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • openshift/console (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • manifests/03-networkpolicy-operator-default-deny.yaml
📜 Review details
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{yaml,yml,json}

📄 CodeRabbit inference engine (Custom checks)

**/*.{yaml,yml,json}: Flag privileged: true, hostPID, hostNetwork, hostIPC, SYS_ADMIN capability, running as root without justification, and allowPrivilegeEscalation: true in container/Kubernetes manifests
When deployment manifests, operator code, or controllers are added/modified, ensure they do not introduce scheduling constraints assuming standard HA topology (3+ control-plane nodes, dedicated workers). Flag: required pod anti-affinity with maxUnavailable: 0 (deadlocks on SNO/TNF/TNA), pod topology spread with DoNotSchedule and hostname key (breaks on SNO), replica counts derived from node count without topology awareness, nodeSelector/node affinity targeting control-plane nodes (fails on HyperShift), scheduling to all control-plane nodes equally without excluding arbiter nodes (TNA), assuming dedicated worker nodes exist (SNO/TNF), or PodDisruptionBudgets designed for 3+ nodes (TNF/TNA). Do not flag if change checks ControlPlaneTopology, node counts, or topology labels before applying constraints.

Files:

  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
{manifests,bindata/assets,quickstarts,examples,profile-patches}/**/*.{yaml,yml}

📄 CodeRabbit inference engine (.claude/skills/manifest-review.md)

{manifests,bindata/assets,quickstarts,examples,profile-patches}/**/*.{yaml,yml}: Kubernetes manifests under manifests/, bindata/assets/, quickstarts/, examples/, and profile-patches/ must include the appropriate cluster profile annotations when they are CVO-deployed resources (for example include.release.openshift.io/hypershift, include.release.openshift.io/ibm-cloud-managed, include.release.openshift.io/self-managed-high-availability, and include.release.openshift.io/single-node-developer).
Console resources in the manifest trees must include the capability annotation capability.openshift.io/name: Console.
RBAC manifests must follow least-privilege design: grant only the permissions needed, avoid wildcards unless truly justified, use verbs that match the actual operation set, and set correct apiGroups ("" for core APIs and specific groups for CRDs).
Resources must use the correct namespace for their role: openshift-console for console workload resources and openshift-console-operator for operator resources; any cross-namespace reference must be explicit and intentional.
YAML manifests should use 2-space indentation, keep fields in a consistent order, and include --- separators between multiple resources in the same file.
When binding roles to service accounts, use console-operator in the openshift-console-operator namespace for operator cross-namespace access, and use console in the openshift-console namespace for console workload-scoped access.

Files:

  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
**/*.yaml

⚙️ CodeRabbit configuration file

**/*.yaml: Review YAML manifests based on content and kind.

Refer to /manifest-review when YAML contains:

  • kind: Role or kind: ClusterRole (RBAC review)
  • kind: RoleBinding or kind: ClusterRoleBinding
  • annotations: section (check for cluster profiles)
  • verbs: ["*"] or wildcard permissions
  • apiGroups: ["*"] or overly broad permissions
  • ServiceAccount references in subjects

Check for required annotations in manifests/:

  • include.release.openshift.io/hypershift
  • include.release.openshift.io/ibm-cloud-managed
  • include.release.openshift.io/self-managed-high-availability
  • include.release.openshift.io/single-node-developer
  • capability.openshift.io/name: Console

For quickstarts/, additionally check:

  • QuickStart spec structure
  • Task descriptions and prerequisites
  • See quickstarts/README.md for guidelines

Files:

  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
**/*.{yaml,yml}

⚙️ CodeRabbit configuration file

**/*.{yaml,yml}: If this is a Kubernetes/OpenShift manifest or Helm template:

  • securityContext: runAsNonRoot, readOnlyRootFilesystem,
    allowPrivilegeEscalation: false
  • Drop ALL capabilities, add only what is required
  • Resource limits (cpu, memory) on every container
  • No hostPID, hostNetwork, hostIPC, privileged: true
  • NetworkPolicy defined for the namespace
  • OpenShift: SCC must be restricted or custom-scoped
  • Liveness + readiness probes defined
  • automountServiceAccountToken: false unless needed
  • RBAC: least privilege; no cluster-admin for workloads
  • Helm: no .Values interpolation in shell commands

Files:

  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
🧠 Learnings (1)
📚 Learning: 2026-07-24T17:22:48.776Z
Learnt from: redhat-chai-bot
Repo: openshift/console-operator PR: 1198
File: manifests/03-networkpolicy-operator-allow-apiserver-egress.yaml:19-22
Timestamp: 2026-07-24T17:22:48.776Z
Learning: For CVO-managed OpenShift operator NetworkPolicy manifests that must allow egress to the Kubernetes API server (TCP 6443), do not rely on podSelector/namespaceSelector targeting for the API server, because the API server may be host-networked and therefore not reliably matchable. Also avoid static ipBlock rules since API server addresses vary by cluster and topology. Instead, use a destination-less egress rule for TCP port 6443 only when the manifest explicitly documents the rationale explaining why selectors/ipBlock cannot be used.

Applied to files:

  • manifests/03-networkpolicy-operator-allow-egress.yaml
  • manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml
🔇 Additional comments (2)
manifests/03-networkpolicy-operator-allow-egress.yaml (1)

1-11: LGTM!

Also applies to: 21-24

manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml (1)

1-11: LGTM!

Also applies to: 17-20

Comment on lines +25 to +26
egress:
- {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not allow unrestricted egress.

egress: - {} permits the console operator to reach every destination and port, including services unrelated to reconciliation. Narrow this policy to the required API-server port (TCP 6443) and provide a separately scoped DNS allowance; the PR objective explicitly calls for API-server and DNS policies rather than open egress.

Based on learnings, API-server access should use a destination-less TCP 6443 rule because host-networked API servers cannot be reliably selected, while static unrestricted egress should be avoided.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@manifests/03-networkpolicy-operator-allow-egress.yaml` around lines 25 - 26,
Replace the unrestricted egress entry in the NetworkPolicy with a
destination-less TCP rule permitting only port 6443 for API-server access, and
add a separately scoped DNS egress rule limited to the required DNS port and
protocol. Keep static unrestricted egress removed and preserve the policy’s
existing scope and selectors.

Source: Learnings

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intentional — egress: - {} is the pattern prescribed by the Developing Network Policies guide and matches the kube-apiserver-operator's own policy. The API server address and port vary per cluster (host-networked), so a static port-6443 restriction is also insufficient. This was reviewed and approved by @wking in the earlier discussion thread.

Comment on lines +13 to +16
Allow ingress to the metrics port on the console operator pod.
This is a NetworkPolicy managed by the cluster-version operator
that allows any source to reach the metrics port, enabling
Prometheus scraping and metrics-based testing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target file =="
sed -n '1,160p' manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml

echo
echo "== related networkpolicy manifests =="
rg -n --glob '*.yaml' '03-networkpolicy-operator|from:|to:|ports:' manifests/bindata manifests 2>/dev/null | head -200

echo
echo "== console operator pod/deployment manifests and ports =="
rg -n --glob '*.yaml' 'console-operator|name: metrics|containerPort|port: 60000|60000' manifests/bindata manifests 2>/dev/null | head -300

echo
echo "== current diff summary/stat =="
git diff --stat || true
git diff -- manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml | sed -n '1,220p' || true

Repository: openshift/console-operator

Length of output: 1329


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== all NetworkPolitics =="
rg -n --glob '*.yaml' 'kind: NetworkPolicy|name: allow-metrics-ingress|from:|policyTypes:' manifests/bindata manifests 2>/dev/null || true

echo
echo "== console operator deployment manifests =="
for f in manifests/05-service.yaml manifests/07-operator.yaml manifests/07-operator-ibm-cloud-managed.yaml; do
  if [ -f "$f" ]; then
    echo "--- $f"
    sed -n '1,140p' "$f"
  else
    echo "--- MISSING $f"
  fi
done

echo
echo "== metrics port references =="
rg -n --glob '*.yaml|*.go|*.md' 'metrics|60000|containerPort:|name: metrics' . 2>/dev/null | head -300 || true

Repository: openshift/console-operator

Length of output: 8942


Restrict metrics ingress to the monitoring namespace.

With no from clause, every namespace and reachable source can access the operator’s metrics endpoint. Add a selector for openshift-monitoring pods/namespaces; the named metrics port is already TCP 60000 in the console-operator container.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@manifests/03-networkpolicy-operator-allow-metrics-ingress.yaml` around lines
13 - 16, Update the NetworkPolicy allowing metrics ingress to restrict sources
to the openshift-monitoring namespace, adding the appropriate namespace/pod
selector under from while preserving the named metrics port and TCP protocol
settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intentional — the Developing Network Policies guide says "We allow anything to reach our metrics endpoint" with no from clause. @wking requested this change specifically to fix the TestMetricsEndpoint e2e failure (the previous from: openshift-monitoring blocked the ingress router pods used by the test).

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

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants