Skip to content

Commit c2eda87

Browse files
jk464cognifloyd
andcommitted
Run containers as non-root w/o escalation privs
Co-authored-by: Jacob Floyd <[email protected]>
1 parent 80f80b4 commit c2eda87

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

templates/deployments.yaml

+8-4
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ spec:
439439
securityContext: {{- toYaml . | nindent 10 }}
440440
{{- end }}
441441
ports:
442-
- containerPort: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 443 80 }}
442+
- containerPort: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 8443 8080 }}
443443
# Probe to check if app is running. Failure will lead to a pod restart.
444444
livenessProbe:
445445
httpGet:
446446
scheme: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary "HTTPS" "HTTP" }}
447447
path: /
448-
port: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 443 80 }}
448+
port: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 8443 8080 }}
449449
initialDelaySeconds: 1
450450
# Probe to check if app is ready to serve traffic. Failure will lead to temp stop serving traffic.
451451
# TODO: Failing to add readinessProbe, since st2 requires authorization (401) and we don't have `/healthz` endpoints yet (https://github.com/StackStorm/st2/issues/4020)
@@ -1644,13 +1644,17 @@ spec:
16441644
{{- end }}
16451645
volumeMounts:
16461646
- name: st2client-config-vol
1647+
{{- if .Values.st2.system_user.user == 'root' }}
16471648
mountPath: /root/.st2/
1649+
{{- else }}
1650+
mountPath: /home/{{ .Values.st2.system_user.user }}/.st2/
1651+
{{- end }}
16481652
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
16491653
command:
16501654
- 'sh'
16511655
- '-ec'
16521656
- |
1653-
cat <<EOT > /root/.st2/config
1657+
cat <<EOT > /home/stanley/.st2/config
16541658
{{- tpl .Values.st2client.st2clientConfig . | nindent 12 }}
16551659
EOT
16561660
containers:
@@ -1683,7 +1687,7 @@ spec:
16831687
{{- end }}
16841688
{{- include "stackstorm-ha.overrides-config-mounts" . | nindent 8 }}
16851689
- name: st2client-config-vol
1686-
mountPath: /root/.st2/
1690+
mountPath: /home/stanley/.st2/
16871691
- name: st2-ssh-key-vol
16881692
mountPath: {{ tpl .Values.st2.system_user.ssh_key_file . | dir | dir }}/.ssh-key-vol/
16891693
{{- if ne "disable" (default "" .Values.st2.datastore_crypto_key) }}

templates/jobs.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ spec:
164164
{{- end }}
165165
volumeMounts:
166166
- name: st2client-config-vol
167-
mountPath: /root/.st2/
167+
mountPath: /home/stanley/.st2/
168168
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
169169
command:
170170
- 'sh'
171171
- '-ec'
172172
- |
173-
cat <<EOT > /root/.st2/config
173+
cat <<EOT > /home/stanley/.st2/config
174174
{{- tpl .Values.jobs.st2clientConfig . | nindent 12 }}
175175
EOT
176176
containers:
@@ -197,7 +197,7 @@ spec:
197197
{{- end }}
198198
volumeMounts:
199199
- name: st2client-config-vol
200-
mountPath: /root/.st2/
200+
mountPath: /home/stanley/.st2/
201201
- name: st2-apikeys-vol
202202
mountPath: /etc/st2/apikeys.yaml
203203
subPath: apikeys.yaml
@@ -290,13 +290,13 @@ spec:
290290
{{- end }}
291291
volumeMounts:
292292
- name: st2client-config-vol
293-
mountPath: /root/.st2/
293+
mountPath: /home/stanley/.st2/
294294
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
295295
command:
296296
- 'sh'
297297
- '-ec'
298298
- |
299-
cat <<EOT > /root/.st2/config
299+
cat <<EOT > /home/stanley/.st2/config
300300
{{- tpl .Values.jobs.st2clientConfig . | nindent 12 }}
301301
EOT
302302
containers:
@@ -325,7 +325,7 @@ spec:
325325
volumeMounts:
326326
{{- include "stackstorm-ha.st2-config-volume-mounts" . | nindent 8 }}
327327
- name: st2client-config-vol
328-
mountPath: /root/.st2/
328+
mountPath: /home/stanley/.st2/
329329
- name: st2-kv-vol
330330
mountPath: /etc/st2/st2kv.yaml
331331
subPath: st2kv.yaml
@@ -660,13 +660,13 @@ spec:
660660
{{- end }}
661661
volumeMounts:
662662
- name: st2client-config-vol
663-
mountPath: /root/.st2/
663+
mountPath: /home/stanley/.st2/
664664
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
665665
command:
666666
- 'sh'
667667
- '-ec'
668668
- |
669-
cat <<EOT > /root/.st2/config
669+
cat <<EOT > /home/stanley/.st2/config
670670
{{- tpl $.Values.jobs.st2clientConfig $ | nindent 12 }}
671671
EOT
672672
containers:
@@ -692,7 +692,7 @@ spec:
692692
{{- end }}
693693
volumeMounts:
694694
- name: st2client-config-vol
695-
mountPath: /root/.st2/
695+
mountPath: /home/stanley/.st2/
696696
{{- include "stackstorm-ha.overrides-config-mounts" $ | nindent 8 }}
697697
{{- include "stackstorm-ha.st2-config-volume-mounts" $ | nindent 8 }}
698698
{{- include "stackstorm-ha.packs-volume-mounts-for-register-job" $ | nindent 8 }}

templates/services.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ spec:
100100
{{- end }}
101101
ports:
102102
- protocol: TCP
103-
port: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 443 80 }}
103+
port: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 8443 8080 }}
104104

105105
{{ if .Values.st2chatops.enabled -}}
106106
---

values.yaml

+32-4
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,11 @@ st2:
300300
## Default SecurityContext for pods and containers.
301301
## Overrides available for st2web, st2actionrunner, st2sensorcontainer, st2client pods, and custom packs images.
302302
##
303-
podSecurityContext: {}
304-
securityContext: {}
303+
podSecurityContext:
304+
runAsNonRoot: true
305+
securityContext:
306+
runAsUser: 1000
307+
allowPrivilegeEscalation: false
305308

306309
##
307310
## StackStorm HA Ingress
@@ -377,7 +380,10 @@ st2web:
377380
attach: false
378381
# override the default .podSecurityContext or .securityContext here
379382
podSecurityContext: {}
380-
securityContext: {} # NB: nginx requires some capabilities, drop ALL will cause issues.
383+
securityContext: # NB: nginx requires some capabilities, drop ALL will cause issues.
384+
runAsUser: 101 # run as nginx user
385+
runAsGroup: 101 # run as nginx group
386+
allowPrivilegeEscalation: false
381387
# mount extra volumes on the st2web pod(s) (primarily useful for k8s-provisioned secrets)
382388
## Note that Helm templating is supported in 'mount' and 'volume'
383389
extra_volumes: []
@@ -1050,6 +1056,15 @@ mongodb:
10501056
arbiter:
10511057
enabled: false
10521058
resources: {}
1059+
podSecurityContext:
1060+
enabled: true
1061+
fsGroup: 1001
1062+
sysctls: []
1063+
containerSecurityContext:
1064+
enabled: true
1065+
runAsUser: 1001
1066+
runAsNonRoot: true
1067+
allowPrivilegeEscalation: false
10531068

10541069
##
10551070
## RabbitMQ configuration (3rd party chart dependency)
@@ -1097,7 +1112,12 @@ rabbitmq:
10971112
# As RabbitMQ enabled prometheus operator monitoring by default, disable it for non-prometheus users
10981113
metrics:
10991114
enabled: false
1100-
1115+
podSecurityContext:
1116+
fsGroup: 1001
1117+
runAsUser: 1001
1118+
runAsNonRoot: true
1119+
containerSecurityContext:
1120+
allowPrivilegeEscalation: false
11011121
##
11021122
## Redis HA configuration (3rd party chart dependency)
11031123
##
@@ -1133,6 +1153,14 @@ redis:
11331153
usePassword: false
11341154
metrics:
11351155
enabled: false
1156+
securityContext:
1157+
enabled: true
1158+
fsGroup: 1001
1159+
runAsNonRoot: true
1160+
containerSecurityContext:
1161+
enabled: true
1162+
runAsUser: 1001
1163+
allowPrivilegeEscalation: false
11361164

11371165
##
11381166
## Settings to be applied to all stackstorm-ha pods

0 commit comments

Comments
 (0)