Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to set pod and container security contexts #422

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions charts/trow/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ spec:
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext:
runAsUser: 333333
runAsGroup: 333333
fsGroup: 333333
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- if and (.Values.trow.user) (.Values.trow.password) }}
- name: trow-pass
Expand Down
12 changes: 12 additions & 0 deletions charts/trow/templates/webhooks/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ spec:
- |
cp /etc/trow/webhook-cert-ecc/tls.crt /etc/trow/webhook-cert/cert && \
openssl pkcs8 -topk8 -nocrypt -in /etc/trow/webhook-cert-ecc/tls.key -out /etc/trow/webhook-cert/key
{{- with .Values.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 10 }}
{{- end }}
volumeMounts:
- name: webhook-cert-translated
mountPath: /etc/trow/webhook-cert
Expand All @@ -53,6 +57,10 @@ spec:
ports:
- name: webhook
containerPort: 8443
{{- with .Values.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 10 }}
{{- end }}
volumeMounts:
- name: webhook-cert-translated
mountPath: /etc/trow/webhook-cert
Expand All @@ -63,6 +71,10 @@ spec:
subPath: config.yaml
readOnly: true
{{- end}}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: webhook-cert-ecc
secret:
Expand Down
24 changes: 15 additions & 9 deletions charts/trow/templates/webhooks/tls-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
securityContext:
allowPrivilegeEscalation: false
{{- toYaml . | nindent 12 }}
{{- end }}
restartPolicy: OnFailure
serviceAccountName: {{ include "trow.fullname" . }}-webhooks-tls
{{- with .Values.webhooks.tls.patch.podSecurityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 2000
fsGroup: 2000
{{- toYaml . | nindent 8 }}
{{- end }}
---
apiVersion: batch/v1
kind: Job
Expand Down Expand Up @@ -184,8 +186,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
securityContext:
allowPrivilegeEscalation: false
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.trow.proxyRegistries.webhook.enabled }}
- name: patch-mutation
Expand All @@ -203,13 +207,15 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- with .Values.webhooks.tls.patch.containerSecurityContext }}
securityContext:
allowPrivilegeEscalation: false
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
restartPolicy: OnFailure
serviceAccountName: {{ include "trow.fullname" . }}-webhooks-tls
{{- with .Values.webhooks.tls.patch.podSecurityContext }}
securityContext:
runAsNonRoot: true
runAsUser: 2000
fsGroup: 2000
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}
14 changes: 14 additions & 0 deletions charts/trow/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ image:
tag:
pullPolicy: IfNotPresent

## Applies to the Trow Statefulset and the webhooks Deployment
podSecurityContext:
runAsUser: 333333
runAsGroup: 333333
fsGroup: 333333

containerSecurityContext: {}

trow:
## if using NodePort, this can be set to 127.0.0.1:XXXX
## Where "XXXX" is the value of service.nodePort
Expand Down Expand Up @@ -76,6 +84,12 @@ webhooks:
image:
image: registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.4@sha256:a9f03b34a3cbfbb26d103a14046ab2c5130a80c3d69d526ff8063d2b37b9fd3f
pullPolicy: IfNotPresent
podSecurityContext:
runAsNonRoot: true
runAsUser: 2000
fsGroup: 2000
containerSecurityContext:
allowPrivilegeEscalation: false
## Use an existing secret that contains tls.crt and tls.key
existingSecretRef: ~

Expand Down
Loading