ADR-009: Shared NetworkPolicy for istio-injected namespaces¶
Status¶
Accepted (status aligned with the ADR index on 2026-06-07; implementation complete — see Addendum)
Date¶
2026-05-03
Context¶
ADR-004 established the "default-deny + explicit allow" NetworkPolicy pattern for each target namespace. As secrets-management infrastructure (Vault / ESO / VCO) was rolled out in PR #225, NetworkPolicy was authored independently per namespace, which surfaced two problems:
-
PR #225 had a port omission: the
allow-istio-gateway-egresspolicy in vault namespace only allowed ports 80/443 to istio-system. Port 15012 (istiod xDS over gRPC mTLS) was missing, so the istio-proxy sidecar couldn't pull xDS config from istiod and the Pod hung in Init forever (startup probe failed continuously). ESO and VCO didn't have any istio-system egress policy at all and hit the same wall. -
Existing namespaces (
platform-auth-prodKeycloak,kensan-prod,backstage, etc.) all use the sameallow-istiopolicy: a single NetworkPolicy that allows all-port bidirectional traffic to/from istio-system namespace. This pattern is already established as best practice in the cluster but wasn't reused in PR #225.
In short, an established pattern existed but was reinvented (poorly) in a new PR. As we add more istio-injected namespaces, the same problem will recur.
Decision¶
Short term (this PR)¶
Replace the per-namespace hand-written istio policies with the established allow-istio pattern:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-istio
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: istio-system
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: istio-system
No port restriction. Bidirectional. The istio-system namespaceSelector is the access boundary. This is the same shape as the existing allow-istio policies in kubernetes/network/network-policy/keycloak-prod.yaml, kubernetes/environments/kensan-{prod,dev}/network-policy.yaml, etc.
Apply to: vault, external-secrets, vault-config-operator.
Medium term (separate PR, chore)¶
Migrate to a single CiliumClusterwideNetworkPolicy (CCNP) that applies to any namespace labeled istio-injection: enabled:
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
name: allow-istio-for-mesh-ns
spec:
description: "All namespaces with istio-injection=enabled may freely talk to istio-system"
endpointSelector:
matchLabels:
k8s:io.cilium.k8s.namespace.labels.istio-injection: enabled
ingress:
- fromEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: istio-system
egress:
- toEndpoints:
- matchLabels:
k8s:io.kubernetes.pod.namespace: istio-system
Place at kubernetes/network/istio/resources/clusterwide-allow-istio.yaml. Once verified, remove the per-namespace allow-istio from each component's resources/network-policy.yaml.
The CCNP supplements the per-namespace default-deny-all (Kubernetes NetworkPolicy semantics are additive: any policy that explicitly allows a destination unblocks it). So the chain becomes:
- per-ns
default-deny-all→ blocks everything by default - CCNP
allow-istio-for-mesh-ns→ adds an istio-system hole to allistio-injection=enablednamespaces
Why CCNP over alternatives¶
| Alternative | Pros | Cons |
|---|---|---|
| CCNP (chosen) | One file. Namespace label is single source of truth. New ns auto-covered just by adding the label. | Cilium-specific (we're locked to Cilium anyway). Slight learning curve for the namespaceSelector syntax. |
Kustomize component (_shared/istio-injected-ns/) |
Stays portable across CNIs. | Each component still has to opt in via kustomization.yaml, easy to forget. Bigger blast radius if shared component changes. |
Kyverno generate policy |
Auto-generates NP when ns label appears. | New controller dependency. Generated resources are not in Git → ArgoCD IgnoreExtraneous workaround needed. Breaks pure GitOps. |
Shared Helm chart (platform-namespace) |
GitOps-clean, parameterizable per component. | Extra chart authoring overhead. Each component's Application CR becomes more complex. |
CCNP wins on simplicity (one file, one source of truth) and aligns with how Cilium policies already integrate cleanly with our standard K8s NetworkPolicies.
Consequences¶
Positive¶
- One pattern: any new istio-injected namespace just needs
istio-injection: enabledlabel. NP coverage is automatic via CCNP. - Smaller surface for mistakes: PR #225's port-omission bug class becomes structurally impossible.
- Reduced duplication: 6+ namespaces currently carry the same hand-written
allow-istioblock; CCNP collapses them.
Negative¶
- Cilium lock-in deepens: switching CNI requires re-implementing the rule. Acceptable since kensan-lab is committed to Cilium (kube-proxy replacement, L2 announcements).
- Coarse granularity: CCNP allows full ns→ns access, not specific ports. For production-grade segmentation, future per-ns policies may need to add more restrictive rules on top. Acceptable for Phase 1; revisit when istio-csr or stricter mTLS enforcement is introduced.
Migration plan (medium term)¶
- Land CCNP
allow-istio-for-mesh-ns(separate PR). - Verify Vault / ESO / VCO / Keycloak / kensan-* / backstage all stay healthy.
- Remove per-namespace
allow-istiofrom each component'sresources/network-policy.yaml(one PR per component or batch). - Update ADR-004 with a note pointing to ADR-009.
Addendum (2026-06-07)¶
The medium-term migration plan above is fully implemented: the clusterwide policies
(clusterwide-{default-deny,allow-dns,allow-istio,allow-prometheus-scrape}-for-mesh-ns.yaml) live under
kubernetes/network/network-policy/ with Prune=false per resource, and all per-namespace allow-istio
policies have been removed. Step 4 was completed late, via the supersede note added to ADR-004 in the
2026-06-07 ADR housekeeping.
Related¶
- ADR-004: NetworkPolicy Design
- ADR-005: Istio Native OAuth2 (Phase 1 sidecar inject decision)