Skip to content

Commit c7677ae

Browse files
authored
chart: add pod and container security contexts (#422)
Signed-off-by: explsd <[email protected]>
1 parent 0d0ec47 commit c7677ae

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

charts/trow/templates/statefulset.yaml

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ spec:
6262
resources:
6363
{{- toYaml . | nindent 10 }}
6464
{{- end }}
65+
{{- with .Values.containerSecurityContext }}
66+
securityContext:
67+
{{- toYaml . | nindent 10 }}
68+
{{- end }}
69+
{{- with .Values.podSecurityContext }}
6570
securityContext:
66-
runAsUser: 333333
67-
runAsGroup: 333333
68-
fsGroup: 333333
71+
{{- toYaml . | nindent 8 }}
72+
{{- end }}
6973
volumes:
7074
{{- if and (.Values.trow.user) (.Values.trow.password) }}
7175
- name: trow-pass

charts/trow/templates/webhooks/deployment.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ spec:
3030
- |
3131
cp /etc/trow/webhook-cert-ecc/tls.crt /etc/trow/webhook-cert/cert && \
3232
openssl pkcs8 -topk8 -nocrypt -in /etc/trow/webhook-cert-ecc/tls.key -out /etc/trow/webhook-cert/key
33+
{{- with .Values.containerSecurityContext }}
34+
securityContext:
35+
{{- toYaml . | nindent 10 }}
36+
{{- end }}
3337
volumeMounts:
3438
- name: webhook-cert-translated
3539
mountPath: /etc/trow/webhook-cert
@@ -53,6 +57,10 @@ spec:
5357
ports:
5458
- name: webhook
5559
containerPort: 8443
60+
{{- with .Values.containerSecurityContext }}
61+
securityContext:
62+
{{- toYaml . | nindent 10 }}
63+
{{- end }}
5664
volumeMounts:
5765
- name: webhook-cert-translated
5866
mountPath: /etc/trow/webhook-cert
@@ -63,6 +71,10 @@ spec:
6371
subPath: config.yaml
6472
readOnly: true
6573
{{- end}}
74+
{{- with .Values.podSecurityContext }}
75+
securityContext:
76+
{{- toYaml . | nindent 8 }}
77+
{{- end }}
6678
volumes:
6779
- name: webhook-cert-ecc
6880
secret:

charts/trow/templates/webhooks/tls-patch.yaml

+15-9
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,16 @@ spec:
135135
valueFrom:
136136
fieldRef:
137137
fieldPath: metadata.namespace
138+
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
138139
securityContext:
139-
allowPrivilegeEscalation: false
140+
{{- toYaml . | nindent 12 }}
141+
{{- end }}
140142
restartPolicy: OnFailure
141143
serviceAccountName: {{ include "trow.fullname" . }}-webhooks-tls
144+
{{- with .Values.webhooks.tls.patch.podSecurityContext }}
142145
securityContext:
143-
runAsNonRoot: true
144-
runAsUser: 2000
145-
fsGroup: 2000
146+
{{- toYaml . | nindent 8 }}
147+
{{- end }}
146148
---
147149
apiVersion: batch/v1
148150
kind: Job
@@ -184,8 +186,10 @@ spec:
184186
valueFrom:
185187
fieldRef:
186188
fieldPath: metadata.namespace
189+
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
187190
securityContext:
188-
allowPrivilegeEscalation: false
191+
{{- toYaml . | nindent 12 }}
192+
{{- end }}
189193
{{- end }}
190194
{{- if .Values.trow.proxyRegistries.webhook.enabled }}
191195
- name: patch-mutation
@@ -203,13 +207,15 @@ spec:
203207
valueFrom:
204208
fieldRef:
205209
fieldPath: metadata.namespace
210+
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
206211
securityContext:
207-
allowPrivilegeEscalation: false
212+
{{- toYaml . | nindent 12 }}
213+
{{- end }}
208214
{{- end }}
209215
restartPolicy: OnFailure
210216
serviceAccountName: {{ include "trow.fullname" . }}-webhooks-tls
217+
{{- with .Values.webhooks.tls.patch.podSecurityContext }}
211218
securityContext:
212-
runAsNonRoot: true
213-
runAsUser: 2000
214-
fsGroup: 2000
219+
{{- toYaml . | nindent 8 }}
220+
{{- end }}
215221
{{- end -}}

charts/trow/values.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ image:
99
tag:
1010
pullPolicy: IfNotPresent
1111

12+
## Applies to the Trow Statefulset and the webhooks Deployment
13+
podSecurityContext:
14+
runAsUser: 333333
15+
runAsGroup: 333333
16+
fsGroup: 333333
17+
18+
containerSecurityContext: {}
19+
1220
trow:
1321
## if using NodePort, this can be set to 127.0.0.1:XXXX
1422
## Where "XXXX" is the value of service.nodePort
@@ -76,6 +84,12 @@ webhooks:
7684
image:
7785
image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.4@sha256:a9f03b34a3cbfbb26d103a14046ab2c5130a80c3d69d526ff8063d2b37b9fd3f
7886
pullPolicy: IfNotPresent
87+
podSecurityContext:
88+
runAsNonRoot: true
89+
runAsUser: 2000
90+
fsGroup: 2000
91+
containerSecurityContext:
92+
allowPrivilegeEscalation: false
7993
## Use an existing secret that contains tls.crt and tls.key
8094
existingSecretRef: ~
8195

0 commit comments

Comments
 (0)