Skip to content

OCPSTRAT-3567: Replace console allow-all NetworkPolicy with scoped policies - #1227

Open
redhat-chai-bot wants to merge 3 commits into
openshift:mainfrom
redhat-chai-bot:OCPSTRAT-3567
Open

OCPSTRAT-3567: Replace console allow-all NetworkPolicy with scoped policies#1227
redhat-chai-bot wants to merge 3 commits into
openshift:mainfrom
redhat-chai-bot:OCPSTRAT-3567

Conversation

@redhat-chai-bot

@redhat-chai-bot redhat-chai-bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the namespace-wide allow-all NetworkPolicy in openshift-console with explicit policies that reduce unintended ingress while preserving required console backend egress.

  • Add namespace default-deny for ingress and egress.
  • Allow router ingress to console UI on pod ports 8443 and 8444.
  • Allow monitoring ingress to console UI metrics on pod port 8443.
  • Allow router ingress to downloads pods on pod port 8080.
  • Retain broad egress only for console UI pods because ConsolePlugin services and external integrations are dynamic.
  • Leave downloads pods with no egress allowance.

Validation

  • make verify
  • make test-unit
  • Reviewed the complete diff and confirmed a clean working tree.

Tracking: OCPSTRAT-3567


AI-generated. Review for accuracy.

@spadgett requested in Slack thread

Summary by CodeRabbit

  • Security Enhancements
    • Added network controls for the console UI, allowing required inbound traffic from platform routing and monitoring services.
    • Added controlled access for the console downloads service from the OpenShift router.
    • Enabled the console UI’s required outbound network traffic.
    • Changed console networking to deny inbound and outbound traffic by default unless explicitly permitted by an approved policy.

… explicit policies

Replace the namespace-wide allow-all NetworkPolicy in the openshift-console
namespace with four explicit, auditable policies:

1. default-deny: Deny all ingress and egress for all pods in the namespace.

2. allow-ingress-console-ui: Allow ingress from the OpenShift router
   (openshift-ingress namespace) on ports 8443 and 8444, and from the
   monitoring stack (openshift-monitoring namespace) on port 8443 for
   Prometheus metrics scraping.

3. allow-ingress-downloads: Allow ingress from the OpenShift router
   (openshift-ingress namespace) on port 8080 for CLI binary downloads.

4. allow-egress-console-ui: Allow all egress from console UI pods only.
   Broad egress is required because the console backend communicates with
   the Kubernetes API server (address varies per cluster), dynamically
   registered ConsolePlugin backend services (arbitrary namespaces/ports),
   external Helm chart repositories, and OAuth/OIDC endpoints. The
   downloads server pods are intentionally excluded and have no egress
   allowance under the default-deny policy.

Namespace selectors use the well-known labels network.openshift.io/
policy-group set by the cluster-ingress-operator and cluster-monitoring-
operator on the openshift-ingress and openshift-monitoring namespaces.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

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

openshift-ci-robot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@redhat-chai-bot: This pull request references OCPSTRAT-3567 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 initiative to target the "5.1.0" version, but no target version was set.

Details

In response to this:

Summary

Replace the namespace-wide allow-all NetworkPolicy in openshift-console with explicit policies that reduce unintended ingress while preserving required console backend egress.

  • Add namespace default-deny for ingress and egress.
  • Allow router ingress to console UI on pod ports 8443 and 8444.
  • Allow monitoring ingress to console UI metrics on pod port 8443.
  • Allow router ingress to downloads pods on pod port 8080.
  • Retain broad egress only for console UI pods because ConsolePlugin services and external integrations are dynamic.
  • Leave downloads pods with no egress allowance.

Validation

  • make verify
  • make test-unit
  • Reviewed the complete diff and confirmed a clean working tree.

Tracking: OCPSTRAT-3567


AI-generated. Review for accuracy.

@spadgett 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 September 3, 2026 20:30
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Team

Run ID: 09ba301d-b11f-4565-8e19-c54f05b6ef8f

📥 Commits

Reviewing files that changed from the base of the PR and between b7336e4 and 25074b4.

📒 Files selected for processing (1)
  • manifests/03-networkpolicy-console-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-console-default-deny.yaml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
🧰 Additional context used
🔀 Multi-repo context openshift/console

Linked repositories findings

openshift/console

  • cmd/downloads/main.go:19 defines the downloads server’s default port as 8080, matching the new downloads ingress policy. [::openshift/console::]
  • pkg/plugins/handlers.go:68-90 constructs proxy handlers from configured plugin service endpoints, supporting the need for console UI egress to dynamic plugin services. [::openshift/console::]

Walkthrough

The console namespace changes from allow-all to default-deny behavior. New policies allow console UI ingress, console UI egress, and downloads ingress from defined namespace groups and ports. Tests validate selectors and ports.

Changes

Console network policy enforcement

Layer / File(s) Summary
Default-deny and workload allow rules
manifests/03-networkpolicy-console-default-deny.yaml, manifests/03-networkpolicy-console-allow-ingress-console-ui.yaml, manifests/03-networkpolicy-console-allow-ingress-downloads.yaml, manifests/03-networkpolicy-console-allow-egress-console-ui.yaml
Renames the policy to default-deny and removes its allow-all rules. Adds explicit console UI ingress and egress policies and downloads ingress rules.
Network policy manifest validation
pkg/console/subresource/deployment/networkpolicy_test.go
Adds tests that compare policy selectors and TCP ports with console deployments and services.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 25074

This change scopes console namespace network access with default-deny policies and explicit workload allowances. No unresolved merge-readiness risk is identified.

🚥 Pre-merge checks | ✅ 14 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (14 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Jira issue and the main change: replacing the console allow-all NetworkPolicy with scoped policies.
Description check ✅ Passed The description clearly explains the change, the intended network access, validation commands, and tracking issue. It does not use the template headings and omits explicit test setup, browser conforma…
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 The pull request adds one standard Go test and three table-driven subtests. The test title is the static TestNetworkPolicyAllowRulesMatchWorkloadManifests, and the subtest names are the static liter…
Test Structure And Quality ✅ Passed PASS: The added test is a standard Go testing table test, not Ginkgo code. It creates no cluster resources and performs no waits or cluster operations, so cleanup and timeout requirements do not app…
Microshift Test Compatibility ✅ Passed PASS: The PR adds no Ginkgo e2e tests. The only added test is the standard Go test TestNetworkPolicyAllowRulesMatchWorkloadManifests, which uses testing.T and local Kubernetes manifest parsing. Th…
Single Node Openshift (Sno) Test Compatibility ✅ Passed PASS: The pull request adds one Go unit test, TestNetworkPolicyAllowRulesMatchWorkloadManifests, using testing.T and static manifest parsing. It does not add Ginkgo e2e tests or make assumptions a…
Topology-Aware Scheduling Compatibility ✅ Passed PASS: The pull request adds or changes only Kubernetes NetworkPolicy manifests and a validation test. The diff against origin/main contains no Deployment, operator, controller, or pod scheduling chang…
Ote Binary Stdout Contract ✅ Passed PASS — The PR changes only Kubernetes manifests and adds an ordinary Go TestNetworkPolicyAllowRulesMatchWorkloadManifests test with helper functions. The added Go file contains no fmt, log, `klo…
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The pull request adds a standard Go testing.T unit test, not a Ginkgo e2e test. The test reads embedded workload manifests and local NetworkPolicy files, then compares selectors and ports. It does n…
No-Weak-Crypto ✅ Passed PASS: The PR diff contains only Kubernetes NetworkPolicy manifests and a Go test for selectors and ports. The exact diff against origin/main introduces no MD5, SHA1, DES, 3DES, RC4, Blowfish, ECB, cus…
Container-Privileges ✅ Passed PASS. The PR diff adds or updates only NetworkPolicy manifests and a Go test. The changed manifests contain no privileged: true, hostPID, hostNetwork, hostIPC, SYS_ADMIN, `allowPrivilegeEsca…
No-Sensitive-Data-In-Logs ✅ Passed The PR adds no application logging or print statements. The new test uses only standard testing diagnostics for static manifest names, service names, selectors, protocols, and ports. The NetworkPoli…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@spadgett

spadgett commented Sep 4, 2026

Copy link
Copy Markdown
Member

@redhat-chai-bot Can you add some unit tests to check that the ports/selectors are validated against actual deployments?

@spadgett spadgett self-assigned this Sep 4, 2026
@openshift-ci

openshift-ci Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: redhat-chai-bot
Once this PR has been reviewed and has the lgtm label, please ask for approval from spadgett. 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

@spadgett

spadgett commented Sep 4, 2026

Copy link
Copy Markdown
Member

/test e2e-aws-console

Comment on lines +16 to +18
explicitly allowed policies. Companion policies grant ingress
from the OpenShift router and monitoring stack, and egress for
the console UI pods.

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.

Suggested change
explicitly allowed policies. Companion policies grant ingress
from the OpenShift router and monitoring stack, and egress for
the console UI pods.
explicitly allowed policies.

I think we should drop the "Companion policies grant ingress..." sentence from this policy. The previous "...ensuring that pods only communicate through explicitly allowed policies" is a sufficient hint that other NetworkPolicies exist, and cluster-admins can go read the descriptions on those policies to figure out what they do. That way, we don't have to remember to come back and bump this description as other NetworkPolicies are added, removed, or otherwise evolved.

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. I’ll remove the companion-policy inventory from the default-deny description and keep the stable generic isolation description, so it won’t need follow-up edits as policies evolve.


AI-generated. Review for accuracy.

"github.com/openshift/library-go/pkg/operator/resource/resourceread"
)

func TestNetworkPolicyAllowRulesMatchWorkloadManifests(t *testing.T) {

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.

I dunno if this test-coverage is worth it. If we flub one of the matches, won't the blocking e2e presubmits turn up things like "hey, I can't access the Console UI?" or "TargetDown from errors from the console metrics?" etc.?

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.

That’s a fair concern. The e2e presubmits are still the end-to-end guard, but this test is a cheap deterministic check that catches selector/target-port drift before a cluster run. It also covers the custom-route redirect and downloads paths that a normal console UI flow may not exercise. I’ll keep it as a focused manifest-contract test rather than relying on e2e alone.


AI-generated. Review for accuracy.

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.

The e2e presubmits are still the end-to-end guard, but this test is a cheap deterministic check that catches selector/target-port drift before a cluster run.

Selector/target-port drift seems unlikely, and I'm not sure there's any garuntee that unit test success gates the launching of the e2e runs, vs. those happening in parallel.

It also covers the custom-route redirect and downloads paths that a normal console UI flow may not exercise.

Seems like those paths should have some e2e test coverage too then, because "NetworkPolicy metadata matches!" isn't sufficient to confirm they work end to end.

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 — this unit test does not gate or replace the e2e jobs, and it does not prove that the routes work end to end. Its narrower purpose is to validate the intended manifest contract early and cheaply; it is not a runtime-coverage claim. I won’t add e2e coverage or expand the egress design in this PR. Since the original review request asked for this exact ports/selectors check and the test is local/static with the full suite passing, I’m leaving it in place unless maintainers prefer to drop the contract check entirely.


AI-generated. Review for accuracy.

@openshift-ci

openshift-ci Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@redhat-chai-bot: The following test 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-aws-console b7336e4 link true /test e2e-aws-console

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

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.

4 participants