-
Notifications
You must be signed in to change notification settings - Fork 22
Adding network policies to kmm including to kmm bundle #1652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||||||||||||||||||||||||||||
| kind: NetworkPolicy | ||||||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||||||
| name: build-and-sign | ||||||||||||||||||||||||||||||||||||
| namespace: system | ||||||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||||||
| podSelector: | ||||||||||||||||||||||||||||||||||||
| matchExpressions: | ||||||||||||||||||||||||||||||||||||
| - key: openshift.io/build.name | ||||||||||||||||||||||||||||||||||||
| operator: Exists | ||||||||||||||||||||||||||||||||||||
| policyTypes: | ||||||||||||||||||||||||||||||||||||
| - Egress | ||||||||||||||||||||||||||||||||||||
| egress: | ||||||||||||||||||||||||||||||||||||
| - {} | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix YAML lint issues (indentation, trailing newline) and keep minimal style. YAMLLint flagged indentation under policyTypes and missing newline at EOF. Also normalize list indentation under matchExpressions. spec:
- podSelector:
- matchExpressions:
- - key: openshift.io/build.name
- operator: Exists
- policyTypes:
- - Egress
- egress:
- - {}
+ podSelector:
+ matchExpressions:
+ - key: openshift.io/build.name
+ operator: Exists
+ policyTypes:
+ - Egress
+ egress:
+ - {}
+📝 Committable suggestion
Suggested change
🧰 Tools🪛 YAMLlint (1.37.1)[warning] 12-12: wrong indentation: expected 2 but found 4 (indentation) [error] 14-14: no new line character at the end of file (new-line-at-end-of-file) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: controller | ||
| namespace: system | ||
| spec: | ||
| podSelector: | ||
| matchLabels: | ||
| control-plane: controller | ||
| policyTypes: | ||
| - Egress | ||
| - Ingress | ||
| ingress: | ||
| - ports: | ||
| - protocol: TCP # metrics port | ||
| port: 8443 | ||
| - protocol: TCP | ||
| port: 8081 # Healthz | ||
| egress: | ||
| - to: | ||
| - namespaceSelector: # DNS | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: openshift-dns | ||
| podSelector: | ||
| matchLabels: | ||
| dns.operator.openshift.io/daemonset-dns: default | ||
| ports: | ||
| - protocol: UDP # DNS | ||
| port: 53 | ||
| - protocol: TCP # DNS | ||
| port: 53 | ||
| - ports: # kube api server | ||
| - protocol: TCP | ||
| port: 6443 | ||
| - protocol: TCP | ||
| port: 443 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: default-deny | ||
| namespace: system | ||
| spec: | ||
| podSelector: {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||||||||||||||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||||||||||||||||||||||||
| kind: NetworkPolicy | ||||||||||||||||||||||||||||||||
| metadata: | ||||||||||||||||||||||||||||||||
| name: webhook | ||||||||||||||||||||||||||||||||
| namespace: system | ||||||||||||||||||||||||||||||||
| spec: | ||||||||||||||||||||||||||||||||
| podSelector: | ||||||||||||||||||||||||||||||||
| matchLabels: | ||||||||||||||||||||||||||||||||
| control-plane: webhook-server | ||||||||||||||||||||||||||||||||
| policyTypes: | ||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Selector likely mismatched with current webhook pod labels NetworkPolicy selects pods via control-plane: webhook-server, while config/webhook-server/kustomization.yaml applies app.kubernetes.io/component: webhook-server. Unless the Deployment also sets control-plane: webhook-server on the Pod template, this policy won’t select the webhook pods and will be a no-op. Apply one of the following to align: Option A — make the policy match the kustomize-applied label: spec:
podSelector:
matchLabels:
- control-plane: webhook-server
+ app.kubernetes.io/component: webhook-serverOption B — keep the policy as-is but add the missing pod label via kustomize (see my comment on config/webhook-server/kustomization.yaml). 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
| - Egress | ||||||||||||||||||||||||||||||||
| - Ingress | ||||||||||||||||||||||||||||||||
| ingress: | ||||||||||||||||||||||||||||||||
| - ports: | ||||||||||||||||||||||||||||||||
| - protocol: TCP | ||||||||||||||||||||||||||||||||
| port: 9443 | ||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ingress currently allows from anywhere; restrict to API server With an ingress rule that only lists ports and no from peers, traffic on 9443 is allowed from any source. For admission webhooks we should scope ingress to the API server namespaces to reduce blast radius. Example tightening (covers both vanilla and OpenShift): ingress:
- - ports:
- - protocol: TCP
- port: 9443
+ - from:
+ - namespaceSelector:
+ matchLabels:
+ kubernetes.io/metadata.name: kube-system
+ - namespaceSelector:
+ matchLabels:
+ kubernetes.io/metadata.name: openshift-kube-apiserver
+ ports:
+ - protocol: TCP
+ port: 9443If you prefer stricter scoping, we can further constrain with podSelector labels on the apiserver pods in those namespaces. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| egress: | ||||||||||||||||||||||||||||||||
| - ports: # kube api server port | ||||||||||||||||||||||||||||||||
| - protocol: TCP | ||||||||||||||||||||||||||||||||
| port: 6443 | ||||||||||||||||||||||||||||||||
| - protocol: TCP | ||||||||||||||||||||||||||||||||
| port: 443 | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: build-and-sign | ||
| namespace: system | ||
| spec: | ||
| podSelector: | ||
| matchExpressions: | ||
| - key: openshift.io/build.name | ||
| operator: Exists | ||
| policyTypes: | ||
| - Egress | ||
| egress: | ||
| - {} | ||
|
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix YAML indentation and ensure newline at EOF to satisfy linters/CI. Yamllint flagged indentation and missing newline. Apply: spec:
podSelector:
matchExpressions:
- - key: openshift.io/build.name
- operator: Exists
- policyTypes:
- - Egress
- egress:
- - {}
+ - key: openshift.io/build.name
+ operator: Exists
+ policyTypes:
+ - Egress
+ egress:
+ - {}
+
🧰 Tools🪛 YAMLlint (1.37.1)[warning] 12-12: wrong indentation: expected 2 but found 4 (indentation) [error] 14-14: no new line character at the end of file (new-line-at-end-of-file) 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||||
| apiVersion: networking.k8s.io/v1 | ||||||||||||||||
| kind: NetworkPolicy | ||||||||||||||||
| metadata: | ||||||||||||||||
| name: controller | ||||||||||||||||
| namespace: system | ||||||||||||||||
| spec: | ||||||||||||||||
|
Comment on lines
+3
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainBundle manifest should not hardcode OLM typically applies bundle objects into the operator’s install namespace. Shipping a hardcoded namespace can cause install-time failures or resources landing in the wrong namespace. Recommend dropping the field in the bundled file (or have the bundle generator strip it). metadata:
name: controller
- namespace: system🏁 Script executed: #!/usr/bin/env bash
# Locate the NetworkPolicy manifest and print its metadata section
manifest="bundle/manifests/kmm-operator-controller_networking.k8s.io_v1_networkpolicy.yaml"
if [ -f "$manifest" ]; then
echo "Showing lines 1-20 of $manifest:"
sed -n '1,20p' "$manifest"
else
echo "$manifest not found."
fiLength of output: 871 Remove hardcoded namespace from NetworkPolicy manifest The bundle’s NetworkPolicy manifest explicitly sets Please update the file as follows: • File: Suggested diff: metadata:
name: controller
- namespace: system📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| podSelector: | ||||||||||||||||
| matchLabels: | ||||||||||||||||
| control-plane: controller | ||||||||||||||||
| policyTypes: | ||||||||||||||||
| - Egress | ||||||||||||||||
| - Ingress | ||||||||||||||||
| ingress: | ||||||||||||||||
| - ports: | ||||||||||||||||
| - protocol: TCP # metrics port | ||||||||||||||||
| port: 8443 | ||||||||||||||||
| - protocol: TCP | ||||||||||||||||
| port: 8081 # Healthz | ||||||||||||||||
| egress: | ||||||||||||||||
| - to: | ||||||||||||||||
| - namespaceSelector: # DNS | ||||||||||||||||
| matchLabels: | ||||||||||||||||
| kubernetes.io/metadata.name: openshift-dns | ||||||||||||||||
| podSelector: | ||||||||||||||||
| matchLabels: | ||||||||||||||||
| dns.operator.openshift.io/daemonset-dns: default | ||||||||||||||||
| ports: | ||||||||||||||||
| - protocol: UDP # DNS | ||||||||||||||||
| port: 53 | ||||||||||||||||
| - protocol: TCP # DNS | ||||||||||||||||
| port: 53 | ||||||||||||||||
| - ports: # kube api server | ||||||||||||||||
| - protocol: TCP | ||||||||||||||||
| port: 6443 | ||||||||||||||||
| - protocol: TCP | ||||||||||||||||
| port: 443 | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| apiVersion: networking.k8s.io/v1 | ||
| kind: NetworkPolicy | ||
| metadata: | ||
| name: default-deny | ||
| namespace: system | ||
| spec: | ||
| podSelector: {} | ||
| policyTypes: | ||
| - Ingress | ||
| - Egress |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||
| apiVersion: networking.k8s.io/v1 | ||||
| kind: NetworkPolicy | ||||
| metadata: | ||||
| name: webhook | ||||
| namespace: system | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Hard-coded namespace "system" in a bundle may not match install namespace. OLM typically installs namespaced resources into the operator’s target namespace. A hard-coded "system" can cause install failures or drift if the operator is installed into openshift-kmm (as your default overlay suggests). Two safe options:
Proposed change (if you choose to drop explicit namespace in source before bundling): - namespace: systemIf you’d rather rewrite at bundle time, adjust hack/generate-bundle to strip or replace the namespace on copied NetworkPolicy YAMLs. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| spec: | ||||
| podSelector: | ||||
| matchLabels: | ||||
| control-plane: webhook-server | ||||
| policyTypes: | ||||
| - Egress | ||||
| - Ingress | ||||
| ingress: | ||||
| - ports: | ||||
| - protocol: TCP | ||||
| port: 9443 | ||||
| egress: | ||||
| - ports: # kube api server port | ||||
| - protocol: TCP | ||||
| port: 6443 | ||||
| - protocol: TCP | ||||
| port: 443 | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Kubebuilder layout bumped to v4 — confirm toolchain compatibility.
Layout v4 with config version "3" is fine, but ensure your pinned operator-sdk/kubebuilder versions in CI and dev images understand v4 layouts.
We can follow up with specific pin recommendations if needed.
🏁 Script executed:
Length of output: 2306
Action Required: Upgrade Operator-SDK and Kubebuilder CLI for go.kubebuilder.io/v4 support
The Makefile currently pins Operator-SDK to v1.32.0, which predates support for Kubebuilder v4 layouts (added in Operator-SDK v1.38.0) (newreleases.io, github.com). Without upgrading, commands like
operator-sdk generatewon’t recognize yourlayout: go.kubebuilder.io/v4scaffold.• Makefile (around line 278): change
(or bump to the latest v1.38.0+ tag)
• Dev/CI images or Dockerfiles: if you install the Kubebuilder CLI directly, pin it to a compatible v4.x release (e.g., v4.6.0) so that
kubebuildercommands understand the v4 layout (github.com).• Verify your
ENVTEST_K8S_VERSION = 1.23remains appropriate for your target Kubernetes version; no change is needed here unless you also bump test-env to match newer K8s minor versions.🤖 Prompt for AI Agents