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 securityContext and podSecurityContext values #271

Merged
merged 3 commits into from
Dec 30, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## In Development
* Advanced Feature: Make securityContext (on Deployments/Jobs) and podSecurityContext (on Pods) configurable. This allows dropping all capabilities, for example. You can override the securityContext for `st2actionrunner`, `st2sensorcontainer`, and `st2client` if your actions or sensors need, for example, additional capabilites that the rest of StackStorm does not need. (#271) (by @cognifloyd)

## v0.80.0
* Switch st2 to `v3.6` as a new default stable version (#274)
Expand Down
15 changes: 15 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Create the name of the stackstorm-ha service account to use
echo 'Waiting for MongoDB Connection...'
sleep 2;
done
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end -}}

Expand All @@ -117,6 +120,9 @@ Create the name of the stackstorm-ha service account to use
echo 'Waiting for RabbitMQ Connection...'
sleep 2;
done
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end -}}

Expand Down Expand Up @@ -203,6 +209,9 @@ Create the name of the stackstorm-ha service account to use
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
{{- if or $.Values.st2.packs.images $.Values.st2.packs.volumes.enabled }}
Expand All @@ -221,6 +230,9 @@ Create the name of the stackstorm-ha service account to use
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- if and $.Values.st2.packs.configs $.Values.st2.packs.volumes.enabled }}
# Pack configs defined in helm values
Expand All @@ -237,6 +249,9 @@ Create the name of the stackstorm-ha service account to use
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/configs/. /opt/stackstorm/configs-shared
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end -}}

Expand Down
96 changes: 96 additions & 0 deletions templates/deployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ spec:
- name: generate-htpasswd
image: '{{ template "imageRepository" . }}/st2auth:{{ tpl (.Values.st2auth.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- secretRef:
name: {{ .Release.Name }}-st2-auth
Expand All @@ -75,6 +78,9 @@ spec:
- name: st2auth
image: '{{ template "imageRepository" . }}/st2auth:{{ tpl (.Values.st2auth.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 9100
# TODO: Add liveness/readiness probes (#3)
Expand Down Expand Up @@ -122,6 +128,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2auth.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -191,6 +200,9 @@ spec:
- name: st2api
image: '{{ template "imageRepository" . }}/st2api:{{ tpl (.Values.st2api.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 9101
# TODO: Add liveness/readiness probes (#3)
Expand Down Expand Up @@ -252,6 +264,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2api.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -314,6 +329,9 @@ spec:
- name: st2stream
image: '{{ template "imageRepository" . }}/st2stream:{{ tpl (.Values.st2stream.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 9102
# TODO: Add liveness/readiness probes (#3)
Expand Down Expand Up @@ -354,6 +372,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2stream.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -411,6 +432,9 @@ spec:
- name: st2web
image: '{{ template "imageRepository" . }}/st2web:{{ tpl (.Values.st2web.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with default .Values.securityContext .Values.st2web.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: {{ eq (get .Values.st2web.env "ST2WEB_HTTPS" | toString) "1" | ternary 443 80 }}
# Probe to check if app is running. Failure will lead to a pod restart.
Expand Down Expand Up @@ -491,6 +515,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with default .Values.podSecurityContext .Values.st2client.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2web.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -554,6 +581,9 @@ spec:
- name: st2rulesengine
image: '{{ template "imageRepository" . }}/st2rulesengine:{{ tpl (.Values.st2rulesengine.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -605,6 +635,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2rulesengine.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -668,6 +701,9 @@ spec:
- name: st2timersengine
image: '{{ template "imageRepository" . }}/st2timersengine:{{ tpl (.Values.st2timersengine.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -706,6 +742,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2timersengine.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -769,6 +808,9 @@ spec:
- name: st2workflowengine
image: '{{ template "imageRepository" . }}/st2workflowengine:{{ tpl (.Values.st2workflowengine.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -828,6 +870,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2workflowengine.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -890,6 +935,9 @@ spec:
- name: st2scheduler
image: '{{ template "imageRepository" . }}/st2scheduler:{{ tpl (.Values.st2scheduler.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -941,6 +989,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2scheduler.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1003,6 +1054,9 @@ spec:
- name: st2notifier
image: '{{ template "imageRepository" . }}/st2notifier:{{ tpl (.Values.st2notifier.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -1041,6 +1095,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2notifier.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1130,6 +1187,9 @@ spec:
- name: {{ $name }}
image: '{{ template "imageRepository" $ }}/st2sensorcontainer:{{ tpl ($sensor.image.tag | default $.Values.image.tag) $ }}'
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- with default $.Values.securityContext $sensor.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
{{- with $sensor.readinessProbe }}
# Probe to check if app is running. Failure will lead to a pod restart.
readinessProbe:
Expand Down Expand Up @@ -1210,6 +1270,9 @@ spec:
{{- with $.Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with default $.Values.podSecurityContext $sensor.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with $sensor.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1286,6 +1349,9 @@ spec:
- name: st2actionrunner
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with default .Values.securityContext .Values.st2actionrunner.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -1363,6 +1429,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with default .Values.podSecurityContext .Values.st2actionrunner.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2actionrunner.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1425,6 +1494,9 @@ spec:
- name: st2garbagecollector
image: '{{ template "imageRepository" . }}/st2garbagecollector:{{ tpl (.Values.st2garbagecollector.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
# TODO: Add liveness/readiness probes (#3)
#livenessProbe:
#readinessProbe:
Expand Down Expand Up @@ -1463,6 +1535,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2garbagecollector.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1532,6 +1607,9 @@ spec:
- name: generate-st2client-config
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2client.image.tag | default (.Values.st2actionrunner.image.tag | default .Values.image.tag)) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
Expand All @@ -1556,6 +1634,9 @@ spec:
- name: st2client
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2client.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with default .Values.securityContext .Values.st2actionrunner.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
env:
- name: ST2CLIENT
value: "1"
Expand Down Expand Up @@ -1648,6 +1729,15 @@ spec:
- name: st2-post-start-script-vol
configMap:
name: {{ .Release.Name }}-st2client-post-start-script
{{- if .Values.dnsPolicy }}
dnsPolicy: {{ .Values.dnsPolicy }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with default .Values.podSecurityContext .Values.st2client.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2client.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -1707,6 +1797,9 @@ spec:
- name: st2chatops
image: '{{ .Values.st2chatops.image.repository | default "stackstorm" }}/{{ .Values.st2chatops.image.name | default "st2chatops" }}:{{ tpl (.Values.st2chatops.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.st2chatops.image.pullPolicy | default .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 10 }}
{{- end }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-st2-urls
Expand Down Expand Up @@ -1765,6 +1858,9 @@ spec:
{{- with .Values.dnsConfig }}
dnsConfig: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext: {{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.st2chatops.nodeSelector }}
nodeSelector: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
Loading