Skip to content

Commit 3b5af9d

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 360f03b commit 3b5af9d

8 files changed

Lines changed: 125 additions & 2 deletions

File tree

‎docs/security/self-assessment.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Actors are decomposed by **trust boundary**: two components are distinct actors
9393
- **Upstream-only vulnerabilities** not introduced or worsened by Cozystack packaging or defaults.
9494
- **Ingress-side isolation of tenant pods.** Tenant-pod ingress is open to `world` and `cluster`, so a tenant pod is reachable by any in-cluster peer whose own egress permits it (platform components) or by a workload not governed by Cozystack's tenant egress policies. Cross-tenant isolation is enforced on the *egress* side, not tenant-pod ingress.
9595
- **Blocking cross-tenant reachability through externally-exposed services.** If a tenant publishes a LoadBalancer external IP, another tenant can reach it via `world` egress.
96+
- **Network isolation between tenants on a hosted cluster without Cilium.** On the `isp-hosted` and `isp-hosted-slim` variants the CNI belongs to the host, and tenant Cilium policies are created only if the host serves the Cilium policy API. Without it, tenants get no network isolation from Cozystack, and isolating them is up to the host.
9697
- **Noisy-neighbour / side-channel** guarantees for co-located tenant pods beyond namespace scoping (and, for tenant Kubernetes/VMs, virtualization).
9798
- Acting as an **egress firewall**: tenant workloads may egress to `world` by default.
9899
- Supporting **pre-release builds and end-of-life versions**.

‎docs/security/threat-model.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ The following are explicitly out of scope for the platform's security guarantees
8383
- **Upstream-only vulnerabilities** that Cozystack packaging and defaults do not introduce or worsen.
8484
- **Ingress-side isolation of tenant pods.** Tenant-pod ingress is open to the `world` and `cluster` entities, so a tenant pod is reachable by any in-cluster peer whose own egress permits it (platform components) and by a workload not governed by Cozystack's tenant egress policies (e.g. a privileged or system pod). Cross-tenant isolation is enforced on the *egress* side, not on tenant-pod ingress.
8585
- **Blocking cross-tenant reachability through externally-exposed services.** If a tenant publishes a LoadBalancer with an external IP, another tenant can reach it via `world` egress.
86+
- **Network isolation between tenants on a hosted cluster without Cilium.** On the `isp-hosted` and `isp-hosted-slim` variants the CNI belongs to the host, and the tenant chart creates its Cilium policies only if the host serves the Cilium policy API (`packages/apps/tenant/templates/_helpers.tpl`, helper `tenant.ciliumPolicies`). Without it, tenants get no network isolation from Cozystack, and isolating them is up to the host.
8687
- **Noisy-neighbour and side-channel guarantees** for co-located tenant pods beyond namespace scoping (and, for tenant Kubernetes/VMs, virtualization). Co-located pods are not claimed to be side-channel isolated.
8788
- **Acting as an egress firewall.** Tenant workloads are allowed egress to `world` by default (`packages/apps/tenant/templates/networkpolicy.yaml`).
8889
- **Supporting pre-release builds and end-of-life versions** (`SECURITY.md`).

‎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
@@ -100,3 +100,16 @@ false
100100
{{- define "tenant.tracingCentralEgress" -}}
101101
{{- if and (ne (include "tenant.name" .) "tenant-root") .Values.tracingCentral .Values.monitoring -}}true{{- end -}}
102102
{{- end -}}
103+
104+
{{- /* Every variant but the isp-hosted ones installs Cilium itself, so the
105+
policies render unconditionally there: a CRD missing at render time
106+
must fail the install, not leave the tenant unisolated for good, since
107+
helm-controller does not re-render a release when discovery changes.
108+
isp-hosted runs on the host's CNI, which may or may not be Cilium. */ -}}
109+
{{- define "tenant.ciliumPolicies" -}}
110+
{{- if not (has (include "cozy-lib.bundle-name" .) (list "isp-hosted" "isp-hosted-slim")) -}}
111+
true
112+
{{- else if and (.Capabilities.APIVersions.Has "cilium.io/v2/CiliumNetworkPolicy") (.Capabilities.APIVersions.Has "cilium.io/v2/CiliumClusterwideNetworkPolicy") -}}
113+
true
114+
{{- end -}}
115+
{{- end -}}

‎packages/apps/tenant/templates/networkpolicy-traces-central-read.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if include "tenant.tracingCentralEgress" . }}
1+
{{- if and (include "tenant.ciliumPolicies" .) (include "tenant.tracingCentralEgress" .) }}
22
# Read hop of shared-central tracing: Grafana reaches the tenant-root vmauth,
33
# never vtselect, which serves any account a client names.
44
apiVersion: cilium.io/v2

‎packages/apps/tenant/templates/networkpolicy-traces-central.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if include "tenant.tracingCentralEgress" . }}
1+
{{- if and (include "tenant.ciliumPolicies" .) (include "tenant.tracingCentralEgress" .) }}
22
# Write hop of shared-central tracing: the collector reaches the tenant-root
33
# vmauth, never vtinsert, which takes the account from the writer's headers.
44
# vmauth sets it from the tenant's VMUser login, so a pod that only carries

‎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: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
suite: tenant Cilium policies follow the platform variant's CNI
2+
templates:
3+
- templates/networkpolicy.yaml
4+
- templates/networkpolicy-traces-central.yaml
5+
- templates/networkpolicy-traces-central-read.yaml
6+
release:
7+
name: tenant-ktj
8+
namespace: tenant-root
9+
tests:
10+
- it: renders no Cilium objects on isp-hosted without the cilium.io API
11+
set:
12+
_cluster:
13+
bundle-name: isp-hosted
14+
asserts:
15+
- hasDocuments:
16+
count: 0
17+
18+
- it: renders no Cilium objects on isp-hosted-slim without the cilium.io API
19+
set:
20+
_cluster:
21+
bundle-name: isp-hosted-slim
22+
asserts:
23+
- hasDocuments:
24+
count: 0
25+
26+
- it: renders no Cilium objects on isp-hosted when only one Cilium kind is served
27+
set:
28+
_cluster:
29+
bundle-name: isp-hosted
30+
capabilities:
31+
apiVersions:
32+
- cilium.io/v2/CiliumNetworkPolicy
33+
asserts:
34+
- hasDocuments:
35+
count: 0
36+
37+
- it: renders the Cilium policies on isp-hosted when the host runs Cilium
38+
set:
39+
_cluster:
40+
bundle-name: isp-hosted
41+
capabilities:
42+
apiVersions:
43+
- cilium.io/v2/CiliumNetworkPolicy
44+
- cilium.io/v2/CiliumClusterwideNetworkPolicy
45+
asserts: &policiesRendered
46+
- template: templates/networkpolicy.yaml
47+
documentSelector:
48+
path: metadata.name
49+
value: allow-internal-communication
50+
isKind:
51+
of: CiliumNetworkPolicy
52+
- template: templates/networkpolicy.yaml
53+
documentSelector:
54+
path: metadata.name
55+
value: tenant-ktj-ingress
56+
isKind:
57+
of: CiliumClusterwideNetworkPolicy
58+
59+
- it: renders the Cilium policies on a Cilium variant even when the API is not discoverable
60+
set:
61+
_cluster:
62+
bundle-name: isp-full
63+
asserts: *policiesRendered
64+
65+
- it: renders the Cilium policies when the platform injected no _cluster
66+
asserts: *policiesRendered
67+
68+
- it: renders no shared-central tracing egress on isp-hosted without the cilium.io API
69+
set:
70+
_cluster:
71+
bundle-name: isp-hosted
72+
tracingCentral: true
73+
monitoring: true
74+
asserts:
75+
- hasDocuments:
76+
count: 0
77+
78+
- it: renders the shared-central tracing egress on isp-hosted when the host runs Cilium
79+
set:
80+
_cluster:
81+
bundle-name: isp-hosted
82+
tracingCentral: true
83+
monitoring: true
84+
capabilities:
85+
apiVersions:
86+
- cilium.io/v2/CiliumNetworkPolicy
87+
- cilium.io/v2/CiliumClusterwideNetworkPolicy
88+
asserts: &tracingRendered
89+
- template: templates/networkpolicy-traces-central.yaml
90+
isKind:
91+
of: CiliumClusterwideNetworkPolicy
92+
- template: templates/networkpolicy-traces-central-read.yaml
93+
isKind:
94+
of: CiliumClusterwideNetworkPolicy
95+
96+
- it: renders the shared-central tracing egress on a Cilium variant
97+
set:
98+
_cluster:
99+
bundle-name: isp-full
100+
tracingCentral: true
101+
monitoring: true
102+
asserts: *tracingRendered

0 commit comments

Comments
 (0)