Skip to content

Commit 358eb88

Browse files
committed
Set podSecurityContext to reflect distroless nonroot uids
1 parent 7b69a84 commit 358eb88

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99
### Added
10+
* Add `orchestrator.persistence.fsGroupWorkaroundEnabled` for persistent volume
11+
provisioners wich don't support fsGroup in security context (fixes #615)
1012
### Changed
13+
* Allow setting pod security context when deploying with Helm
1114
* Use [distroless](https://github.com/GoogleContainerTools/distroless) as base image for orchestrator container
1215
### Removed
1316
### Fixed

deploy/charts/mysql-operator/templates/statefulset.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ spec:
3333
- name: operator
3434
image: "{{ .Values.image }}"
3535
imagePullPolicy: {{ .Values.imagePullPolicy }}
36-
securityContext:
37-
runAsUser: 888
3836
env:
3937
- name: ORC_TOPOLOGY_USER
4038
valueFrom:
@@ -93,8 +91,10 @@ spec:
9391
secretRef:
9492
name: {{ template "mysql-operator.orc-secret-name" . }}
9593
volumeMounts:
94+
- name: data
95+
mountPath: /var/lib/orchestrator
9696
- name: config
97-
mountPath: /usr/local/share/orchestrator/templates/
97+
mountPath: /usr/local/share/orchestrator/templates
9898
livenessProbe:
9999
timeoutSeconds: 10
100100
initialDelaySeconds: 200
@@ -118,17 +118,24 @@ spec:
118118
- name: data
119119
emptyDir: {}
120120
{{- end }}
121+
122+
{{- if .Values.orchestrator.persistence.fsGroupWorkaroundEnabled }}
121123
initContainers:
122124
- name: init-mount
125+
securityContext:
126+
runAsUser: 0
123127
image: busybox:1.34.0
124-
command: ['sh', '-c', "chown -R 777:777 /var/lib/orchestrator"]
128+
command: ['sh', '-c', "chown -R {{ .Values.securityContext.fsGroup | default "0" }}:{{ .Values.securityContext.fsGroup | default "0" }} /var/lib/orchestrator"]
125129
volumeMounts:
126130
- name: data
127-
mountPath: /var/lib/orchestrator/
131+
mountPath: /var/lib/orchestrator
132+
{{- end }}
128133

129134
# security context to mount corectly the volume for orc
135+
{{- with .Values.securityContext }}
130136
securityContext:
131-
fsGroup: 777
137+
{{- toYaml . | nindent 8 }}
138+
{{- end }}
132139

133140
{{- with .Values.nodeSelector }}
134141
nodeSelector:

deploy/charts/mysql-operator/values.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ resources: {}
4949
# cpu: 100m
5050
# memory: 128Mi
5151

52+
securityContext:
53+
runAsNonRoot: true
54+
# 65532 is the UID for nonroot user from distroless image
55+
runAsUser: 65532
56+
runAsGroup: 65532
57+
fsGroup: 65532
58+
5259
## nodeAffinity settings
5360
# nodeAffinity:
5461
# requiredDuringSchedulingIgnoredDuringExecution:
@@ -130,6 +137,10 @@ orchestrator:
130137
# storageClass: "-"
131138
accessMode: "ReadWriteOnce"
132139
size: 1Gi
140+
# inject an init container which properly sets the ownership for the orchestrator's data volume
141+
# this is needed when the PV provisioner does not properly sets permissions for fsGroup
142+
# when enabling this, you MUST change the securityContext.runAsNonRoot to false
143+
fsGroupWorkaroundEnabled: false
133144

134145
# key value map of orchestrator conf directives.
135146
# see: https://github.com/github/orchestrator/blob/master/conf/orchestrator-sample.conf.json
@@ -179,7 +190,7 @@ orchestrator:
179190
# for more information about template: https://github.com/github/orchestrator/blob/master/go/logic/topology_recovery.go#L256
180191
ProcessesShellCommand: "sh"
181192

182-
OnFailureDetectionProcesses:
193+
OnFailureDetectionProcesses:
183194
- "/usr/local/bin/orc-helper event -w '{failureClusterAlias}' 'OrcFailureDetection' 'Failure: {failureType}, failed host: {failedHost}, lost replcas: {lostReplicas}' || true"
184195
- "/usr/local/bin/orc-helper failover-in-progress '{failureClusterAlias}' '{failureDescription}' || true"
185196

0 commit comments

Comments
 (0)