Skip to content

CNTRLPLANE-2698: add network policies for apiserver operator and operands#2029

Open
dusk125 wants to merge 1 commit intoopenshift:mainfrom
dusk125:network-policy
Open

CNTRLPLANE-2698: add network policies for apiserver operator and operands#2029
dusk125 wants to merge 1 commit intoopenshift:mainfrom
dusk125:network-policy

Conversation

@dusk125
Copy link
Contributor

@dusk125 dusk125 commented Feb 5, 2026

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

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

openshift-ci-robot commented Feb 5, 2026

@dusk125: This pull request references API-1631 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 epic to target the "4.22.0" version, but no target version was set.

Details

In response to this:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

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.

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1f8ea64-d3e7-4935-832e-5fce343b366f

📥 Commits

Reviewing files that changed from the base of the PR and between 71a564b and bf51996.

📒 Files selected for processing (5)
  • bindata/assets/kube-apiserver/networkpolicy-operand-allow.yaml
  • bindata/assets/kube-apiserver/networkpolicy-operand-default-deny.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-default-deny.yaml
  • pkg/operator/starter.go
✅ Files skipped from review due to trivial changes (4)
  • bindata/assets/kube-apiserver/networkpolicy-operand-allow.yaml
  • bindata/assets/kube-apiserver/networkpolicy-operand-default-deny.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-default-deny.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/operator/starter.go

Walkthrough

Adds four new Kubernetes NetworkPolicy manifests (two under bindata and two under manifests) to enforce default-deny posture and specific allow rules (egress and metrics ingress), and updates the operator starter to include the two operand networkpolicy assets in its static resources list.

Changes

Cohort / File(s) Summary
NetworkPolicy manifests
bindata/assets/kube-apiserver/networkpolicy-operand-allow.yaml, bindata/assets/kube-apiserver/networkpolicy-operand-default-deny.yaml, manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml, manifests/0000_20_kube-apiserver-operator_networkpolicy-default-deny.yaml
Adds four NetworkPolicy resources: operand allow (egress: allow all for pods labeled app in {guard,installer,pruner}) and operand default-deny in openshift-kube-apiserver; operator allow (egress: allow all; ingress: TCP port 8443) and operator default-deny in openshift-kube-apiserver-operator. Manifests include explanatory comments and release annotations.
Operator initialization
pkg/operator/starter.go
Appends two kube-apiserver operand networkpolicy asset paths to the static resource list used by RunOperator; notes that default-deny should be applied last.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. 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 clearly and specifically describes the main change: adding network policies for both the apiserver operator and operands, which aligns with all four files added.
Stable And Deterministic Test Names ✅ Passed This PR is not applicable to the Stable and Deterministic Test Names check because it does not add, modify, or include any Ginkgo tests.
Test Structure And Quality ✅ Passed The PR does not include any Ginkgo test code, only manifest YAML files and starter.go modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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 Feb 5, 2026
@dusk125
Copy link
Contributor Author

dusk125 commented Feb 5, 2026

/retitle WIP: CNTRLPLANE-2698: add network policies for apiserver operator and operands

@openshift-ci openshift-ci bot requested review from benluddy and sanchezl February 5, 2026 18:32
@openshift-ci openshift-ci bot changed the title WIP: API-1631: add network policies for apiserver operator and operands WIP: CNTRLPLANE-2698: add network policies for apiserver operator and operands Feb 5, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 5, 2026

@dusk125: This pull request references CNTRLPLANE-2698 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:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

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
Copy link
Contributor

openshift-ci bot commented Feb 5, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dusk125
Once this PR has been reviewed and has the lgtm label, please assign sanchezl 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-robot
Copy link

openshift-ci-robot commented Mar 4, 2026

@dusk125: This pull request references CNTRLPLANE-2698 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:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

Summary by CodeRabbit

  • Chores
  • Added network policies for the kube-apiserver operand and operator, including default-deny rules and allow-list policies for DNS, metrics collection, and inter-component communication channels.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@manifests/0000_20_kube-apiserver-operator_11_networkpolicies.yaml`:
- Around line 52-56: The NetworkPolicy named allow-to-apiserver currently uses
podSelector: {} and egress: - {} which permits all pods unrestricted outbound
traffic; change it to target only operator pods by replacing the empty
podSelector with the selector used elsewhere (matchLabels: {app:
kube-apiserver-operator}) so only pods labeled app: kube-apiserver-operator get
the broad egress; keep the egress rules as-is but ensure the policyTypes and
name (allow-to-apiserver) remain unchanged to preserve intent and ordering with
default-deny semantics.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: f064883c-cbdc-4ddb-a70c-03bd760315e5

📥 Commits

Reviewing files that changed from the base of the PR and between ce72eb4 and 8e7295e.

📒 Files selected for processing (2)
  • manifests/0000_12_kube-apiserver-operand_networkpolicies.yaml
  • manifests/0000_20_kube-apiserver-operator_11_networkpolicies.yaml

Comment on lines +52 to +56
podSelector: {}
egress:
- {}
policyTypes:
- Egress
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the file
file=$(fd '0000_20_kube-apiserver-operator_11_networkpolicies.yaml' | head -n1)
echo "Found file: $file"
echo "=== File structure and lines 52-56 ==="
sed -n '45,60p' "$file" | cat -n

echo ""
echo "=== Full context for allow-to-apiserver policy ==="
rg -n -B5 -A10 'name:\s*allow-to-apiserver' "$file"

echo ""
echo "=== Check for app labels in kube-apiserver-operator deployments ==="
fd '.*kube-apiserver-operator.*\.yaml' | head -5 | while read f; do
  if rg -q 'app.*kube-apiserver-operator' "$f"; then
    echo "Found label in: $f"
    rg -B2 -A2 'app.*kube-apiserver-operator' "$f" | head -10
  fi
done

Repository: openshift/cluster-kube-apiserver-operator

Length of output: 1470


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="manifests/0000_20_kube-apiserver-operator_11_networkpolicies.yaml"

echo "=== FULL FILE CONTENT ==="
cat -n "$file"

echo ""
echo "=== Check for default-deny policy ==="
rg -n 'name:.*default-deny|name:.*deny' "$file"

echo ""
echo "=== Check deployments for app label ==="
fd 'deployment.*\.yaml' | xargs rg -l 'kube-apiserver-operator' | head -3 | while read f; do
  echo "File: $f"
  rg -C3 'app.*kube-apiserver-operator|labels:' "$f" | head -20
done

Repository: openshift/cluster-kube-apiserver-operator

Length of output: 6621


allow-to-apiserver allows all egress for all pods in the namespace, including those that don't need it.

The policy uses podSelector: {} with egress: - {}, which selects every pod and permits unrestricted outbound traffic. While the intent stated in the file (lines 41–42) is to handle variable API server endpoints, this blanket allowance applies to every workload in the namespace, not just the operator. The default-deny policy cannot override it due to NetworkPolicy additive semantics—once any policy permits traffic, it is allowed.

The namespace contains an app: kube-apiserver-operator label (confirmed in the deployment) that is already used in allow-to-kube-apiserver and allow-to-metrics policies in the same file. Scoping allow-to-apiserver to only operator pods aligns with least-privilege and the pattern established by the other policies.

Proposed tightening
 spec:
-  podSelector: {}
+  podSelector:
+    matchLabels:
+      app: kube-apiserver-operator
   egress:
   - {}
   policyTypes:
   - Egress
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
podSelector: {}
egress:
- {}
policyTypes:
- Egress
podSelector:
matchLabels:
app: kube-apiserver-operator
egress:
- {}
policyTypes:
- Egress
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@manifests/0000_20_kube-apiserver-operator_11_networkpolicies.yaml` around
lines 52 - 56, The NetworkPolicy named allow-to-apiserver currently uses
podSelector: {} and egress: - {} which permits all pods unrestricted outbound
traffic; change it to target only operator pods by replacing the empty
podSelector with the selector used elsewhere (matchLabels: {app:
kube-apiserver-operator}) so only pods labeled app: kube-apiserver-operator get
the broad egress; keep the egress rules as-is but ensure the policyTypes and
name (allow-to-apiserver) remain unchanged to preserve intent and ordering with
default-deny semantics.

@dusk125 dusk125 changed the title WIP: CNTRLPLANE-2698: add network policies for apiserver operator and operands CNTRLPLANE-2698: add network policies for apiserver operator and operands Mar 4, 2026
@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 Mar 4, 2026
@dusk125
Copy link
Contributor Author

dusk125 commented Mar 5, 2026

/retest-required

1 similar comment
@dusk125
Copy link
Contributor Author

dusk125 commented Mar 5, 2026

/retest-required

@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 9, 2026

@dusk125: This pull request references CNTRLPLANE-2698 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:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

Summary by CodeRabbit

  • New Features
  • Added network policies to kube-apiserver and kube-apiserver-operator components enforcing default-deny posture with specific allow rules for operational traffic (DNS resolution, health checks, API server communication).
  • Configured metrics ingress access on port 8443.

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.

🧹 Nitpick comments (1)
manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml (1)

24-27: Consider restricting ingress source for metrics (optional).

The ingress rule allows any pod from any namespace to connect to port 8443. While this is flexible for Prometheus scraping across different cluster configurations, a more restrictive approach could limit sources to the monitoring namespace if known:

ingress:
- from:
  - namespaceSelector:
      matchLabels:
        name: openshift-monitoring
  ports:
  - protocol: TCP
    port: 8443

If the monitoring namespace varies across deployments, the current open approach is acceptable.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml` around
lines 24 - 27, The ingress rule currently allows unrestricted sources to connect
to port 8443; update the ingress block (the ingress entry that contains ports: -
protocol: TCP port: 8443) to restrict sources by adding a from: section with a
namespaceSelector that matches the monitoring namespace (for example,
namespaceSelector: matchLabels: name: openshift-monitoring) so only the
monitoring namespace can scrape metrics; if the monitoring namespace is
variable, make this change conditional or document why the open ingress must
remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml`:
- Around line 24-27: The ingress rule currently allows unrestricted sources to
connect to port 8443; update the ingress block (the ingress entry that contains
ports: - protocol: TCP port: 8443) to restrict sources by adding a from: section
with a namespaceSelector that matches the monitoring namespace (for example,
namespaceSelector: matchLabels: name: openshift-monitoring) so only the
monitoring namespace can scrape metrics; if the monitoring namespace is
variable, make this change conditional or document why the open ingress must
remain.

ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Pro

Run ID: e25cb21d-26c5-4dda-ab44-006991d48a4c

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7295e and a3e97bc.

📒 Files selected for processing (9)
  • bindata/assets/kube-apiserver/networkpolicy-operand-allow.yaml
  • bindata/assets/kube-apiserver/networkpolicy-operand-default-deny.yaml
  • bindata/assets/kube-apiserver/networkpolicy-operator-allow.yaml
  • bindata/assets/kube-apiserver/networkpolicy-operator-default-deny.yaml
  • manifests/0000_12_kube-apiserver-operand_networkpolicy-allow.yaml
  • manifests/0000_12_kube-apiserver-operand_networkpolicy-default-deny.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-allow.yaml
  • manifests/0000_20_kube-apiserver-operator_networkpolicy-default-deny.yaml
  • pkg/operator/starter.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/operator/starter.go

@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 9, 2026

@dusk125: This pull request references CNTRLPLANE-2698 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:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

Summary by CodeRabbit

Release Notes

  • New Features
  • Added network policies to kube-apiserver and kube-apiserver-operator namespaces to enforce default-deny security posture
  • Configured selective allow rules for required traffic including health checks, API server communication, and metrics collection

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.

- key: app
operator: In
values:
- guard
Copy link
Member

Choose a reason for hiding this comment

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

Do guard pods actually need any network access? I've come across it for another component and realized that they don't for that component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought they did requests to the readyz endpoint of their target pod to know when/if it dies

@dusk125
Copy link
Contributor Author

dusk125 commented Mar 10, 2026

/retest-required

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 10, 2026

@dusk125: 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-gcp-operator-serial-ote 71a564b link false /test e2e-gcp-operator-serial-ote

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.

@dusk125
Copy link
Contributor Author

dusk125 commented Mar 11, 2026

/retest-required

@dusk125
Copy link
Contributor Author

dusk125 commented Mar 12, 2026

/label tide/merge-method-squash

@openshift-ci openshift-ci bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 12, 2026
@dusk125
Copy link
Contributor Author

dusk125 commented Mar 17, 2026

/retest-required

@dusk125
Copy link
Contributor Author

dusk125 commented Mar 23, 2026

/label remove tide/merge-method-squash

@openshift-ci-robot
Copy link

@dusk125: This pull request references CNTRLPLANE-2698 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:

Adds NetworkPolicy resources for both operator and operand namespaces:

  • Operator namespace (openshift-kube-apiserver-operator): Default-deny with allow rules for DNS, API server access, kube-apiserver health checks (port 6443), and metrics ingress
  • Operand namespace (openshift-kube-apiserver): Default-deny with allow rules for guard/installer/pruner helper pods (DNS, API server access, kube-apiserver health checks)

Note: kube-apiserver static pods use hostNetwork: true and bypass NetworkPolicy entirely. I'm including a default-deny here anyway as a point of documentation and (big if) that were to ever change in the future, we're still locked down.

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.

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. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants