mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-05 14:42:05 +09:00
fix(tenant): allow etcd and ingress egress to all ancestors at any depth
Walking prefixes of the parent namespace drops tenant-root at depth >= 2. Kamaji control planes of tenant clusters in these tenants time out on etcd.tenant-root.svc:2379. Ingress has the same reachability gap, including hairpin traffic to public URLs hosted by ancestor ingress. The set of allowed destinations only grows: every previously allowed ancestor remains reachable, even when the tenant owns etcd or ingress. namespace.yaml propagates service owners from the parent or assigns ownership to the tenant itself, so inherited owners are always ancestors and need no separate owner logic. tenant-root has no ancestor rules. Validated with helm unittest packages/apps/tenant (113 tests), an offline Helm template render, and regression tests that fail with owner-only rules. Assisted-by: LLM Signed-off-by: tym83 <6355522@gmail.com>
This commit is contained in:
1 parent
054b4ef4bc
commit
b7821e332c
3 files changed
+364
-17
No files matched your search
@@ -14,6 +14,28 @@
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
tenant.ancestorNamespaces encodes the strict ancestor chain as a JSON array
|
||||
for callers using fromJsonArray. Like tenant.ancestorTenantLabels, it takes
|
||||
the tenant's own namespace name: tenant-root is implicit, while the other
|
||||
ancestors are dash-prefixes. The tenant itself is excluded, so tenant-root
|
||||
has no ancestors. Service ownership does not restrict this chain: even a
|
||||
tenant with its own ingress needs ancestor ingress for hairpin traffic.
|
||||
*/}}
|
||||
{{- define "tenant.ancestorNamespaces" -}}
|
||||
{{- $ancestors := list -}}
|
||||
{{- if ne . "tenant-root" -}}
|
||||
{{- $ancestors = append $ancestors "tenant-root" -}}
|
||||
{{- $parts := splitList "-" . -}}
|
||||
{{- range $i, $v := $parts -}}
|
||||
{{- if and (ne $i 0) (lt $i (sub (len $parts) 1)) -}}
|
||||
{{- $ancestors = append $ancestors (join "-" (slice $parts 0 (add $i 1))) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $ancestors | toJson -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/*
|
||||
tenant.gatewayEffective resolves whether THIS tenant should own a
|
||||
dedicated Gateway resource. Returns the literal string "true" or
|
||||
|
||||
@@ -54,30 +54,19 @@ spec:
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if ne (include "tenant.name" .) "tenant-root" }}
|
||||
{{- $ancestors := include "tenant.ancestorNamespaces" (include "tenant.name" .) | fromJsonArray }}
|
||||
{{- with $ancestors }}
|
||||
- toEndpoints:
|
||||
{{- if hasPrefix "tenant-" .Release.Namespace }}
|
||||
{{- $parts := splitList "-" .Release.Namespace }}
|
||||
{{- range $i, $v := $parts }}
|
||||
{{- if ne $i 0 }}
|
||||
{{- range . }}
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": "etcd"
|
||||
"k8s:io.kubernetes.pod.namespace": {{ join "-" (slice $parts 0 (add $i 1)) }}
|
||||
"k8s:io.kubernetes.pod.namespace": {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if ne (include "tenant.name" .) "tenant-root" }}
|
||||
- toEndpoints:
|
||||
{{- if hasPrefix "tenant-" .Release.Namespace }}
|
||||
{{- $parts := splitList "-" .Release.Namespace }}
|
||||
{{- range $i, $v := $parts }}
|
||||
{{- if ne $i 0 }}
|
||||
{{- range . }}
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": {{ join "-" (slice $parts 0 (add $i 1)) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
"k8s:io.kubernetes.pod.namespace": {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
---
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
suite: tenant etcd and ingress egress reaches all ancestors
|
||||
templates:
|
||||
- templates/networkpolicy.yaml
|
||||
set:
|
||||
etcd: false
|
||||
ingress: false
|
||||
tests:
|
||||
- it: allows tenant-root at depth one
|
||||
release:
|
||||
name: tenant-team
|
||||
namespace: tenant-root
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
|
||||
- it: allows root and parent at depth two
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
set:
|
||||
_namespace.etcd: tenant-root
|
||||
_namespace.ingress: tenant-root
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: allows all three ancestors at depth three
|
||||
release:
|
||||
name: tenant-leaf
|
||||
namespace: tenant-team-child
|
||||
set:
|
||||
_namespace.etcd: tenant-team
|
||||
_namespace.ingress: tenant-team-child
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-leaf-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child-leaf": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team-child
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team-child
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team-child
|
||||
|
||||
- it: keeps root reachable with locally owned services at depth one
|
||||
release:
|
||||
name: tenant-team
|
||||
namespace: tenant-root
|
||||
set:
|
||||
etcd: true
|
||||
ingress: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
|
||||
- it: keeps every ancestor reachable with locally owned services
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
set:
|
||||
etcd: true
|
||||
ingress: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: keeps ancestors reachable with local etcd
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
set:
|
||||
etcd: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: keeps ancestors reachable with local ingress
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
set:
|
||||
ingress: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: allows ancestors when owners are missing
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: allows ancestors with a null namespace map
|
||||
release:
|
||||
name: tenant-child
|
||||
namespace: tenant-team
|
||||
set:
|
||||
_namespace: null
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-team-child-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-team-child": ""
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/name": vminsert
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
"k8s:app.kubernetes.io/instance": etcd
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-root
|
||||
- matchLabels:
|
||||
cozystack.io/service: ingress
|
||||
"k8s:io.kubernetes.pod.namespace": tenant-team
|
||||
|
||||
- it: omits ancestor rules for tenant-root
|
||||
release:
|
||||
name: tenant-root
|
||||
namespace: tenant-root
|
||||
set:
|
||||
etcd: true
|
||||
ingress: true
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: tenant-root-egress
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.egress
|
||||
value:
|
||||
- toEndpoints:
|
||||
- matchLabels:
|
||||
"k8s:io.cilium.k8s.namespace.labels.tenant.cozystack.io/tenant-root": ""
|
||||
Reference in new issue
Block a user