Skip to content

Commit f47e3db

Browse files
fix(helm): make bundled postgres PSA restricted compliant (#1604)
## Summary Closes #1560 The bundled PostgreSQL deployment now ships with Pod Security Admission restricted-compliant defaults and exposes both pod-level and container-level security context values for overrides. - add default `RuntimeDefault` seccomp profiles for the bundled PostgreSQL pod and container - drop all container capabilities by default while keeping `allowPrivilegeEscalation: false` - move the bundled PostgreSQL pod and container security contexts into chart values so users can customize them without patching templates - extend Helm unit coverage for the new defaults and override paths ## Testing - `make helm-version` - `helm unittest helm/kagent` - `helm lint helm/kagent` Signed-off-by: Asish Kumar <officialasishkumar@gmail.com> Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>
1 parent 476a03c commit f47e3db

File tree

3 files changed

+105
-8
lines changed

3 files changed

+105
-8
lines changed

helm/kagent/templates/postgresql.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ spec:
5353
spec:
5454
{{- include "kagent.imagePullSecrets" $ | nindent 6 }}
5555
serviceAccountName: {{ $fullname }}
56+
{{- with $pg.podSecurityContext }}
5657
securityContext:
57-
fsGroup: 999
58-
runAsUser: 999
59-
runAsGroup: 999
60-
runAsNonRoot: true
58+
{{- toYaml . | nindent 8 }}
59+
{{- end }}
6160
containers:
6261
- name: postgresql
6362
image: {{ include "kagent.postgresql.image" . }}
6463
imagePullPolicy: {{ $pg.image.pullPolicy }}
64+
{{- with $pg.securityContext }}
6565
securityContext:
66-
allowPrivilegeEscalation: false
66+
{{- toYaml . | nindent 12 }}
67+
{{- end }}
6768
ports:
6869
- name: postgresql
6970
containerPort: 5432
@@ -137,4 +138,3 @@ spec:
137138
{{- include "kagent.selectorLabels" . | nindent 4 }}
138139
app.kubernetes.io/component: database
139140
{{- end }}
140-

helm/kagent/tests/postgresql_test.yaml

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,95 @@ tests:
217217
template: postgresql.yaml
218218
documentIndex: 2
219219
asserts:
220+
- equal:
221+
path: spec.template.spec.securityContext.fsGroup
222+
value: 999
220223
- equal:
221224
path: spec.template.spec.securityContext.runAsNonRoot
222225
value: true
223226
- equal:
224227
path: spec.template.spec.securityContext.runAsUser
225228
value: 999
229+
- equal:
230+
path: spec.template.spec.securityContext.runAsGroup
231+
value: 999
232+
- equal:
233+
path: spec.template.spec.securityContext.seccompProfile.type
234+
value: RuntimeDefault
235+
- equal:
236+
path: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
237+
value: false
238+
- contains:
239+
path: spec.template.spec.containers[0].securityContext.capabilities.drop
240+
content: ALL
241+
- equal:
242+
path: spec.template.spec.containers[0].securityContext.seccompProfile.type
243+
value: RuntimeDefault
244+
245+
- it: should allow bundled postgres pod security context override
246+
template: postgresql.yaml
247+
documentIndex: 2
248+
set:
249+
database:
250+
postgres:
251+
bundled:
252+
podSecurityContext:
253+
fsGroup: 1001
254+
runAsUser: 1001
255+
runAsGroup: 1001
256+
runAsNonRoot: true
257+
seccompProfile:
258+
type: Localhost
259+
localhostProfile: profiles/postgres.json
260+
asserts:
261+
- equal:
262+
path: spec.template.spec.securityContext.fsGroup
263+
value: 1001
264+
- equal:
265+
path: spec.template.spec.securityContext.runAsUser
266+
value: 1001
267+
- equal:
268+
path: spec.template.spec.securityContext.runAsGroup
269+
value: 1001
270+
- equal:
271+
path: spec.template.spec.securityContext.seccompProfile.type
272+
value: Localhost
273+
- equal:
274+
path: spec.template.spec.securityContext.seccompProfile.localhostProfile
275+
value: profiles/postgres.json
276+
277+
- it: should allow bundled postgres container security context override
278+
template: postgresql.yaml
279+
documentIndex: 2
280+
set:
281+
database:
282+
postgres:
283+
bundled:
284+
securityContext:
285+
allowPrivilegeEscalation: false
286+
readOnlyRootFilesystem: false
287+
capabilities:
288+
drop:
289+
- ALL
290+
seccompProfile:
291+
type: Localhost
292+
localhostProfile: profiles/postgres-container.json
293+
asserts:
294+
- equal:
295+
path: spec.template.spec.containers[0].securityContext.allowPrivilegeEscalation
296+
value: false
297+
- equal:
298+
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
299+
value: false
300+
- contains:
301+
path: spec.template.spec.containers[0].securityContext.capabilities.drop
302+
content: ALL
303+
- equal:
304+
path: spec.template.spec.containers[0].securityContext.seccompProfile.type
305+
value: Localhost
306+
- equal:
307+
path: spec.template.spec.containers[0].securityContext.seccompProfile.localhostProfile
308+
value: profiles/postgres-container.json
226309

227310
- it: should render Service with hardcoded ClusterIP type and port 5432
228311
template: postgresql.yaml
@@ -341,4 +424,3 @@ tests:
341424
value:
342425
- name: secret1
343426
- name: secret2
344-

helm/kagent/values.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ database:
9393
limits:
9494
cpu: 500m
9595
memory: 512Mi
96+
# -- Pod-level security context for the bundled PostgreSQL deployment.
97+
podSecurityContext:
98+
fsGroup: 999
99+
runAsUser: 999
100+
runAsGroup: 999
101+
runAsNonRoot: true
102+
seccompProfile:
103+
type: RuntimeDefault
104+
# -- Container-level security context for the bundled PostgreSQL container.
105+
securityContext:
106+
allowPrivilegeEscalation: false
107+
capabilities:
108+
drop:
109+
- ALL
110+
seccompProfile:
111+
type: RuntimeDefault
96112

97113
# ==============================================================================
98114
# RBAC CONFIGURATION
@@ -490,4 +506,3 @@ otel:
490506
endpoint: ""
491507
timeout: 15
492508
insecure: true
493-

0 commit comments

Comments
 (0)