Skip to content

Commit 6fc5251

Browse files
committed
fix(tenant): skip Cilium policies on isp-hosted without Cilium
The isp-hosted variants install no CNI of their own, so on a host without Cilium the cilium.io/v2 kinds do not exist and the tenant install fails, taking the root tenant and everything that depends on cozystack-basics down with it. The policies now render on isp-hosted only when the host serves both Cilium policy kinds. On every other variant Cozystack installs Cilium itself, so they keep rendering unconditionally: a CRD that is missing at render time there fails the install loudly instead of leaving the tenant without network isolation, because helm-controller does not re-render a release when only API discovery changes. On isp-hosted without Cilium the tenant gets no network isolation from Cozystack; isolating tenants is then up to the host's CNI. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent bc400df commit 6fc5251

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎packages/apps/tenant/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ tenant-u1
7070
└── postgres-db1
7171
```
7272

73+
### Network isolation
74+
75+
Tenant network isolation is enforced with Cilium network policies. On the `isp-hosted` and `isp-hosted-slim` platform variants the CNI belongs to the host, so these policies are created only if the host serves the Cilium policy API when the tenant is installed or updated. On a host without Cilium, tenants get no network isolation from Cozystack, and isolating them is up to the host. If Cilium appears on the host later, the policies are created on the tenant's next chart or values change, not automatically.
76+
7377
## Parameters
7478

7579
### Common parameters

‎packages/apps/tenant/templates/_helpers.tpl‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,16 @@ false
9292
{{- if .Values.gateway -}}true{{- else -}}false{{- end -}}
9393
{{- end -}}
9494
{{- end -}}
95+
96+
{{- /* Every variant but the isp-hosted ones installs Cilium itself, so the
97+
policies render unconditionally there: a CRD missing at render time
98+
must fail the install, not leave the tenant unisolated for good, since
99+
helm-controller does not re-render a release when discovery changes.
100+
isp-hosted runs on the host's CNI, which may or may not be Cilium. */ -}}
101+
{{- define "tenant.ciliumPolicies" -}}
102+
{{- if not (has (include "cozy-lib.bundle-name" .) (list "isp-hosted" "isp-hosted-slim")) -}}
103+
true
104+
{{- else if and (.Capabilities.APIVersions.Has "cilium.io/v2/CiliumNetworkPolicy") (.Capabilities.APIVersions.Has "cilium.io/v2/CiliumClusterwideNetworkPolicy") -}}
105+
true
106+
{{- end -}}
107+
{{- end -}}

‎packages/apps/tenant/templates/networkpolicy.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if include "tenant.ciliumPolicies" . }}
12
---
23
apiVersion: cilium.io/v2
34
kind: CiliumNetworkPolicy
@@ -274,3 +275,4 @@ spec:
274275
- toEndpoints:
275276
- matchLabels:
276277
cozystack.io/service: ingress
278+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
suite: tenant Cilium policies follow the platform variant's CNI
2+
templates:
3+
- templates/networkpolicy.yaml
4+
release:
5+
name: tenant-ktj
6+
namespace: tenant-root
7+
tests:
8+
- it: renders no Cilium objects on isp-hosted without the cilium.io API
9+
set:
10+
_cluster:
11+
bundle-name: isp-hosted
12+
asserts:
13+
- hasDocuments:
14+
count: 0
15+
16+
- it: renders no Cilium objects on isp-hosted-slim without the cilium.io API
17+
set:
18+
_cluster:
19+
bundle-name: isp-hosted-slim
20+
asserts:
21+
- hasDocuments:
22+
count: 0
23+
24+
- it: renders no Cilium objects on isp-hosted when only one Cilium kind is served
25+
set:
26+
_cluster:
27+
bundle-name: isp-hosted
28+
capabilities:
29+
apiVersions:
30+
- cilium.io/v2/CiliumNetworkPolicy
31+
asserts:
32+
- hasDocuments:
33+
count: 0
34+
35+
- it: renders the Cilium policies on isp-hosted when the host runs Cilium
36+
set:
37+
_cluster:
38+
bundle-name: isp-hosted
39+
capabilities:
40+
apiVersions:
41+
- cilium.io/v2/CiliumNetworkPolicy
42+
- cilium.io/v2/CiliumClusterwideNetworkPolicy
43+
asserts: &policiesRendered
44+
- documentSelector:
45+
path: metadata.name
46+
value: allow-internal-communication
47+
isKind:
48+
of: CiliumNetworkPolicy
49+
- documentSelector:
50+
path: metadata.name
51+
value: tenant-ktj-ingress
52+
isKind:
53+
of: CiliumClusterwideNetworkPolicy
54+
55+
- it: renders the Cilium policies on a Cilium variant even when the API is not discoverable
56+
set:
57+
_cluster:
58+
bundle-name: isp-full
59+
asserts: *policiesRendered
60+
61+
- it: renders the Cilium policies when the platform injected no _cluster
62+
asserts: *policiesRendered

0 commit comments

Comments
 (0)