Skip to content

fix: variable namespaces for networkpolicies#3342

Merged
google-oss-prow[bot] merged 40 commits into
kubeflow:masterfrom
danish9039:fix/networkpolicies-variable-namespaces
Feb 26, 2026
Merged

fix: variable namespaces for networkpolicies#3342
google-oss-prow[bot] merged 40 commits into
kubeflow:masterfrom
danish9039:fix/networkpolicies-variable-namespaces

Conversation

@danish9039

Copy link
Copy Markdown
Member

✏️ Summary of Changes

This PR fixes an issue #3319 where NetworkPolicies for various core components were incorrectly being applied to the kubeflow namespace. This was caused by a hardcoded namespace: kubeflow in the base kustomization.yaml.

Additionally, this PR updates the tests/multi_tenancy_install.sh script to proactively create the required target namespaces before applying the policies, ensuring the installation succeeds even if components are installed in a pick-and-choose manner.

The Problem

flowchart TB
    subgraph "Before Fix (Broken)"
        K[kustomization.yaml<br>namespace: kubeflow] --> |Forces ALL resources| KF[kubeflow namespace]
        
        P1[cert-manager-webhook.yaml<br>namespace: cert-manager] --> K
        P2[default-allow-auth.yaml<br>namespace: auth] --> K
        P3[istio-policy.yaml<br>namespace: istio-system] --> K
        
        K --> |All end up in| KF
        
        KF --> |Contains policies for| WRONG[❌ Wrong namespaces!]
    end
Loading

The Solution

flowchart TB
    subgraph "After Fix (Correct)"
        K2[kustomization.yaml<br>NO namespace override] --> |Respects each file|SPLIT
        
        SPLIT{Each policy goes<br>to its own namespace}
        
        SPLIT --> CM[cert-manager namespace]
        SPLIT --> AU[auth namespace]
        SPLIT --> IS[istio-system namespace]
        SPLIT --> KS[knative-serving namespace]
        SPLIT --> KF2[kubeflow namespace]
        SPLIT --> KFS[kubeflow-system namespace]
        
        CM --> |✅ Protects| CMP[cert-manager pods]
        AU --> |✅ Protects| AUP[auth pods]
        IS --> |✅ Protects| ISP[istio pods]
    end
Loading

Verification

  • Checked that kustomize build common/networkpolicies/base generates policies with correct namespaces.
  • Ran shellcheck tests/multi_tenancy_install.sh on the modified script to ensure robustness.

Continuing work by @juhyeon-cha with addition of namespace creation in test scripts.

📦 Dependencies

None.

🐛 Related Issues

Supersedes #3319

✅ Contributor Checklist

  • I have tested these changes with kustomize. See Installation Prerequisites.
  • All commits are signed-off to satisfy the DCO check.
  • I have considered adding my company to the adopters page to support Kubeflow and help the community, since I expect help from the community for my issue (see 1. and 2.).

@github-actions

github-actions Bot commented Feb 9, 2026

Copy link
Copy Markdown

Welcome to the Kubeflow Manifests Repository

Thanks for opening your first PR. Your contribution means a lot to the Kubeflow community.

Before making more PRs:
Please ensure your PR follows our Contributing Guide.
Please also be aware that many components are synchronizes from upstream via the scripts in /scripts.
So in some cases you have to fix the problem in the upstream repositories first, but you can use a PR against kubeflow/manifests to test the platform integration.

Community Resources:

Thanks again for helping to improve Kubeflow.

@danish9039 danish9039 force-pushed the fix/networkpolicies-variable-namespaces branch from ec1e9f0 to 6c7b0c9 Compare February 9, 2026 12:03
@danish9039

Copy link
Copy Markdown
Member Author

@juliusvonkohout

@juliusvonkohout

juliusvonkohout commented Feb 10, 2026

Copy link
Copy Markdown
Member

Thank you for the PR. Please check out all the comments such as #3319 (comment) "everything outside of the kubeflow namespaces so cert-manager, knative-serving etc. We should directly move in this PR to the respective folders/overlays in /common" lets aim for a long-term solution that is better than just creating empty namespaces. I will also do a dummy istio change to trigger more tests. For example we can rename common/cert-manager/kubeflow-issuer/base to common/cert-manager/overlay/kubeflow and add the cert-manager networkpolicy in that folder

@danish9039 danish9039 force-pushed the fix/networkpolicies-variable-namespaces branch from a820ebf to e60201f Compare February 11, 2026 15:13
@google-oss-prow google-oss-prow Bot added size/L and removed size/XS labels Feb 11, 2026
@danish9039

Copy link
Copy Markdown
Member Author

Thank you for the PR. Please check out all the comments such as #3319 (comment) "everything outside of the kubeflow namespaces so cert-manager, knative-serving etc. We should directly move in this PR to the respective folders/overlays in /common" lets aim for a long-term solution that is better than just creating empty namespaces. I will also do a dummy istio change to trigger more tests. For example we can rename common/cert-manager/kubeflow-issuer/base to common/cert-manager/overlay/kubeflow and add the cert-manager networkpolicy in that folder

@juliusvonkohout updated the PR to address the feedback

  • Refactored Overlays : moved the NetworkPolicies for cert-manager, dex, istio, knative, and oauth2-proxy into their respective overlays/kubeflow directories within common/
  • Kustomize Refactor: Updated thekustomization.yaml files to reference these new paths and verified that the base common/networkpolicies/base configuration correctly targets the kubeflow namespace.
  • Verification: validated these changes locally using kustomize build and performed server-side validation against a Kind cluster with upstream CRDs installed (for Istio and Knative). confirmed that all manifests are generated correctly and accepted by the API server.

Comment thread common/dex/overlays/kubeflow/kustomization.yaml Outdated
Comment thread common/networkpolicies/base/kustomization.yaml Outdated
Comment thread tests/multi_tenancy_install.sh Outdated

@juliusvonkohout juliusvonkohout 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.

Thank you, I added comments.

Comment thread common/cert-manager/overlays/kubeflow/kustomization.yaml
Comment thread common/cert-manager/overlays/kubeflow/cluster-issuer.yaml
@juliusvonkohout

Copy link
Copy Markdown
Member

/ok-to-test

Comment thread common/cert-manager/kubeflow-issuer/base/cluster-issuer.yaml Outdated
@danish9039

Copy link
Copy Markdown
Member Author

Thank you, I added comments.

@juliusvonkohout I have addressed the feedback , renamed all network policy files as requested and updated their references throughout the codebase. looking at your suggestion #3342 additionally i refactored the namespace creation into a proper Kustomize base (common/namespaces) to provide a declarative, long-term solution instead of relying on the imperative bash loop, ensuring all target namespaces exist before policies are applied.

Comment thread common/cert-manager/overlays/kubeflow/kustomization.yaml Outdated
Comment thread common/namespaces/base/auth.yaml Outdated
Comment thread common/namespaces/base/cert-manager.yaml Outdated
Comment thread common/namespaces/base/istio-system.yaml Outdated
Comment thread common/namespaces/base/knative-serving.yaml Outdated
Comment thread common/namespaces/base/kubeflow-system.yaml Outdated
Comment thread common/namespaces/base/kubeflow.yaml Outdated
Comment thread common/namespaces/base/kustomization.yaml Outdated
Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
@danish9039 danish9039 force-pushed the fix/networkpolicies-variable-namespaces branch from 2db6d1a to b7a6a0c Compare February 25, 2026 11:12
@danish9039

danish9039 commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

Please rebase to master now since I merged c589121

@juliusvonkohout done

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
@danish9039

Copy link
Copy Markdown
Member Author

@juliusvonkohout Added allow-knative-to-istio-gateways in istio-system , this allows knative-serving traffic to reach Istio gateways and removes the cross-namespace timeout after enabling same-namespace default allow netpol . and allow-istio-gateways-to-activator in knative-serving this allows Istio gateway pods to reach Knative activator on the serving path,

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
@danish9039

Copy link
Copy Markdown
Member Author

@juliusvonkohout moved the remaining networkpolicies in common/networkpolicies/base/ to common/kubeflow-namespace/base/kubeflow/ and removed separate netpol reference from example/kustomization.yaml and the explicit netpol apply step from tests/multi_tenancy_install.sh

Comment thread common/istio/istio-namespace/base/allow-istiod-control-plane.yaml Outdated
Comment thread common/istio/istio-namespace/base/kustomization.yaml Outdated
Comment thread common/knative/knative-serving/base/kustomization.yaml Outdated
Comment thread common/kubeflow-namespace/base/kubeflow/kustomization.yaml
@juliusvonkohout

Copy link
Copy Markdown
Member

Thank you, that looks quite good already. Please address the last comments and then maybe a final review will do it.

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
@danish9039

Copy link
Copy Markdown
Member Author

Thank you, that looks quite good already. Please address the last comments and then maybe a final review will do it.

@juliusvonkohout addressed all the comments

Signed-off-by: juliusvonkohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: juliusvonkohout <45896133+juliusvonkohout@users.noreply.github.com>
@juliusvonkohout

Copy link
Copy Markdown
Member

Thank you
/lgtm
/approve

@google-oss-prow google-oss-prow Bot added the lgtm label Feb 26, 2026
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: juliusvonkohout

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

The pull request process is described here

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

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

@juliusvonkohout

Copy link
Copy Markdown
Member

If you are interested in a follow up PR: https://github.com/kubeflow/manifests/blob/master/common/cert-manager/README.md update logic should be moved to /scripts as for all other components. and you can also check which scripts in /scripts have to be run since there are newer upstream releases and raise corresponding PRs.

@google-oss-prow google-oss-prow Bot merged commit fcd884f into kubeflow:master Feb 26, 2026
30 checks passed
Raakshass added a commit to Raakshass/manifests that referenced this pull request Mar 27, 2026
* fix: variable namespaces for networkpolicies

Remove namespace override in kustomization.yaml to allow NetworkPolicies
to use their self-defined namespaces.

Also update multi_tenancy_install.sh to create required namespaces
before applying network policies, ensuring the installation succeeds.

Supersedes kubeflow#3319

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* fix: restore netpol namespace & refactor overlays

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* fix: update multi-tenancy script to include new overlays

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* fix

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* refactor

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* fix

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* format yaml disable modification of spec.selector

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* refactor: move networkpolicy files to canonical paths

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* refactor: wire subfolder kustomizations and remove dead overlays

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* test: align cert-manager install and trivy scan paths

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* Update tests/cert_manager_install.sh

Co-authored-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: hippie-danish <133037056+danish9039@users.noreply.github.com>

* Update tests/trivy_scan.py

Co-authored-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: hippie-danish <133037056+danish9039@users.noreply.github.com>

* Update cert-manager installation script to use base

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* test: fix multitenancy wait and lint

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* Update tests/cert_manager_install.sh

Co-authored-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: hippie-danish <133037056+danish9039@users.noreply.github.com>

* Update tests/trainer_install.sh

Co-authored-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: hippie-danish <133037056+danish9039@users.noreply.github.com>

* Apply suggestion from @juliusvonkohout

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Apply suggestion from @juliusvonkohout

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Apply suggestion from @juliusvonkohout

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Update multi_tenancy_install.sh

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Apply suggestion from @juliusvonkohout

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Comment out default-allow-same-namespace.yaml

Comment out default network policy and note future changes.

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>

* test: enable istio-system default-allow-same-namespace only

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* test(netpol): add istiod control-plane allow policy only

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* test(netpol): add istiod webhook apiserver policy only

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* lint

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* test(netpol): add oauth2-proxy ingressgateway allow policy only

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: allow oauth2-proxy and istio to reach dex

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: allow apiserver to reach knative webhook

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: allow apiserver to reach net-istio webhook

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: re-enable same-namespace allow for cert-manager

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: re-enable same-namespace allow for knative-serving

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: allow knative-serving to reach istio gateways

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* netpol: allow istio gateways to reach knative activator

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* move kubeflow network policy files into kubeflow namespace folder

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* rewire kubeflow namespace to apply moved network policies

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* addressed comments

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>

* move readme and owners

Signed-off-by: juliusvonkohout <45896133+juliusvonkohout@users.noreply.github.com>

* cleanup

Signed-off-by: juliusvonkohout <45896133+juliusvonkohout@users.noreply.github.com>

---------

Signed-off-by: danish9039 <danishsiddiqui040@gmail.com>
Signed-off-by: hippie-danish <133037056+danish9039@users.noreply.github.com>
Signed-off-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Signed-off-by: juliusvonkohout <45896133+juliusvonkohout@users.noreply.github.com>
Co-authored-by: Julius von Kohout <45896133+juliusvonkohout@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants