Skip to content

Commit a95c90f

Browse files
committed
feat(helm): add networkPolicy.allowExternalEgress for managed datastores
The default policy allows 443 plus the bundled Postgres and Redis by pod selector, so a managed datastore on another port needs a hand-written CIDR rule — awkward when REDIS_URL arrives via a Secret the chart cannot inspect. Adds an opt-in switch that drops the port restriction while still blocking the cloud metadata endpoints. Defaults to false, keeping this chart stricter than the common chart default of unrestricted egress.
1 parent ee2d004 commit a95c90f

5 files changed

Lines changed: 84 additions & 0 deletions

File tree

apps/docs/content/docs/en/platform/self-hosting/security.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ networkPolicy:
8585
This applies even when `REDIS_URL` reaches the pod through a Secret rather than `values.yaml` — the chart cannot see the host, so it cannot generate the rule. A deployment that accepts the URL but has no matching egress rule will fail to reach Redis with `networkPolicy.enabled: true`.
8686
</Callout>
8787

88+
If maintaining CIDR lists is not worth it, drop the port restriction instead:
89+
90+
```yaml
91+
networkPolicy:
92+
enabled: true
93+
allowExternalEgress: true
94+
```
95+
96+
Cloud metadata endpoints stay blocked either way. This defaults to `false` because Sim's chart is deliberately stricter than the common chart default, which permits unrestricted egress.
97+
8898
### Pod Security Standards
8999

90100
All workloads set `runAsNonRoot`, drop all Linux capabilities, disable privilege escalation, and use `seccompProfile: RuntimeDefault` — the four controls the `restricted` profile requires. Label the namespace to enforce it:

helm/sim/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Before installing in production, confirm each of the following:
235235
- protocol: TCP
236236
port: 5432 # managed Postgres
237237
```
238+
239+
If you would rather not maintain CIDR lists, `networkPolicy.allowExternalEgress: true` drops the port restriction entirely while still blocking the cloud metadata endpoints. It defaults to `false` — this chart is deliberately stricter than the common chart default of unrestricted egress.
238240
* **Network policy ingress** — `networkPolicy.ingressFrom` defaults to `[{}]` (an empty peer selector), which allows ingress traffic from **any pod in the cluster**, not just your ingress controller. This is a deliberate simple default, not a locked-down one. On a shared or multi-tenant cluster, scope it down, e.g. to the ingress-nginx namespace:
239241
```yaml
240242
networkPolicy:

helm/sim/templates/networkpolicy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ spec:
122122
port: 53
123123
- protocol: TCP
124124
port: 53
125+
{{- if .Values.networkPolicy.allowExternalEgress }}
126+
# Unrestricted egress (still excluding cloud metadata endpoints). Opt-in for
127+
# deployments running managed datastores on non-443 ports.
128+
- to:
129+
- ipBlock:
130+
cidr: 0.0.0.0/0
131+
except:
132+
{{- range (default (list "169.254.169.254/32" "169.254.170.2/32") .Values.networkPolicy.egressExceptCidrs) }}
133+
- {{ . | quote }}
134+
{{- end }}
135+
{{- else }}
125136
# Allow HTTPS egress for external APIs (excludes cloud metadata endpoints)
126137
- to:
127138
- ipBlock:
@@ -133,6 +144,7 @@ spec:
133144
ports:
134145
- protocol: TCP
135146
port: 443
147+
{{- end }}
136148
# Allow custom egress rules
137149
{{- with .Values.networkPolicy.egress }}
138150
{{- toYaml . | nindent 2 }}
@@ -214,6 +226,17 @@ spec:
214226
port: 53
215227
- protocol: TCP
216228
port: 53
229+
{{- if .Values.networkPolicy.allowExternalEgress }}
230+
# Unrestricted egress (still excluding cloud metadata endpoints). Opt-in for
231+
# deployments running managed datastores on non-443 ports.
232+
- to:
233+
- ipBlock:
234+
cidr: 0.0.0.0/0
235+
except:
236+
{{- range (default (list "169.254.169.254/32" "169.254.170.2/32") .Values.networkPolicy.egressExceptCidrs) }}
237+
- {{ . | quote }}
238+
{{- end }}
239+
{{- else }}
217240
# Allow HTTPS egress for external APIs (excludes cloud metadata endpoints)
218241
- to:
219242
- ipBlock:
@@ -225,6 +248,7 @@ spec:
225248
ports:
226249
- protocol: TCP
227250
port: 443
251+
{{- end }}
228252
# Allow custom egress rules
229253
{{- with .Values.networkPolicy.egress }}
230254
{{- toYaml . | nindent 2 }}

helm/sim/tests/networkpolicy_test.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,40 @@ tests:
176176
ports:
177177
- protocol: TCP
178178
port: 5432
179+
180+
- it: restricts egress to HTTPS by default
181+
set:
182+
<<: *defaults
183+
documentIndex: 0
184+
asserts:
185+
- contains:
186+
path: spec.egress
187+
content:
188+
to:
189+
- ipBlock:
190+
cidr: 0.0.0.0/0
191+
except:
192+
- "169.254.169.254/32"
193+
- "169.254.170.2/32"
194+
ports:
195+
- protocol: TCP
196+
port: 443
197+
198+
# Opt-in for managed datastores on non-443 ports. Metadata endpoints stay
199+
# blocked either way — that exclusion is not negotiable.
200+
- it: allows unrestricted egress when allowExternalEgress=true
201+
set:
202+
<<: *defaults
203+
networkPolicy.allowExternalEgress: true
204+
documentIndex: 0
205+
asserts:
206+
- contains:
207+
path: spec.egress
208+
content:
209+
to:
210+
- ipBlock:
211+
cidr: 0.0.0.0/0
212+
except:
213+
- "169.254.169.254/32"
214+
- "169.254.170.2/32"
215+

helm/sim/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,17 @@ networkPolicy:
11951195
- "169.254.169.254/32"
11961196
- "169.254.170.2/32"
11971197

1198+
# Allow egress to any destination and port instead of the default
1199+
# HTTPS-only rule set (cloud metadata endpoints stay blocked either way).
1200+
#
1201+
# Off by default: this chart is deliberately stricter than the common chart
1202+
# default, which permits unrestricted egress. Leave it false and enumerate
1203+
# what you need under `egress` below. Turn it on when you run managed
1204+
# datastores on non-443 ports (Redis, Postgres) and would rather not maintain
1205+
# CIDR lists — the bundled Postgres and Redis are already allowed by pod
1206+
# selector and do not need it.
1207+
allowExternalEgress: false
1208+
11981209
# Shared storage for enterprise workflows requiring data sharing between pods
11991210
sharedStorage:
12001211
enabled: false

0 commit comments

Comments
 (0)