Skip to content

Commit eb18445

Browse files
committed
chart/redpanda: Set securityContext.runAsNonRoot to false for tuning container
(cherry picked from commit f187f32)
1 parent 8cbe368 commit eb18445

File tree

6 files changed

+115
-16
lines changed

6 files changed

+115
-16
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project: charts/redpanda
2+
kind: Fixed
3+
body: |
4+
Fix `CreateContainerConfigError: Error: container's runAsUser breaks non-root policy...` error with `statefulset.podTemplate.spec.securityContext.runAsNonRoot: true`
5+
time: 2025-11-03T20:51:45.198677+02:00

charts/redpanda/chart/templates/_statefulset.go.tpl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
{{- break -}}
201201
{{- end -}}
202202
{{- $_is_returning = true -}}
203-
{{- (dict "r" (mustMergeOverwrite (dict "name" "" "resources" (dict)) (dict "name" "tuning" "image" (printf "%s:%s" $state.Values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $state)))) "r")) "command" (list `/bin/bash` `-c` `rpk redpanda tune all`) "securityContext" (mustMergeOverwrite (dict) (dict "capabilities" (mustMergeOverwrite (dict) (dict "add" (list `SYS_RESOURCE`))) "privileged" true "runAsUser" ((0 | int64) | int64) "runAsGroup" ((0 | int64) | int64))) "volumeMounts" (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $state)))) "r")) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "base-config" "mountPath" "/etc/redpanda"))))))) | toJson -}}
203+
{{- (dict "r" (mustMergeOverwrite (dict "name" "" "resources" (dict)) (dict "name" "tuning" "image" (printf "%s:%s" $state.Values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $state)))) "r")) "command" (list `/bin/bash` `-c` `rpk redpanda tune all`) "securityContext" (mustMergeOverwrite (dict) (dict "capabilities" (mustMergeOverwrite (dict) (dict "add" (list `SYS_RESOURCE`))) "privileged" true "runAsNonRoot" false "runAsUser" ((0 | int64) | int64) "runAsGroup" ((0 | int64) | int64))) "volumeMounts" (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $state)))) "r")) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "base-config" "mountPath" "/etc/redpanda"))))))) | toJson -}}
204204
{{- break -}}
205205
{{- end -}}
206206
{{- end -}}
@@ -215,9 +215,9 @@
215215
{{- (dict "r" (coalesce nil)) | toJson -}}
216216
{{- break -}}
217217
{{- end -}}
218-
{{- $_397_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $state $pool "set-datadir-ownership")))) "r") -}}
219-
{{- $uid := ((index $_397_uid_gid 0) | int64) -}}
220-
{{- $gid := ((index $_397_uid_gid 1) | int64) -}}
218+
{{- $_398_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $state $pool "set-datadir-ownership")))) "r") -}}
219+
{{- $uid := ((index $_398_uid_gid 0) | int64) -}}
220+
{{- $gid := ((index $_398_uid_gid 1) | int64) -}}
221221
{{- $_is_returning = true -}}
222222
{{- (dict "r" (mustMergeOverwrite (dict "name" "" "resources" (dict)) (dict "name" "set-datadir-ownership" "image" (printf "%s:%s" $pool.Statefulset.initContainerImage.repository $pool.Statefulset.initContainerImage.tag) "command" (list `/bin/sh` `-c` (printf `chown %d:%d -R /var/lib/redpanda/data` $uid $gid)) "securityContext" (mustMergeOverwrite (dict) (dict "runAsUser" (0 | int64) "runAsGroup" (0 | int64))) "volumeMounts" (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $state)))) "r")) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" `datadir` "mountPath" `/var/lib/redpanda/data`))))))) | toJson -}}
223223
{{- break -}}
@@ -230,12 +230,12 @@
230230
{{- $containerName := (index .a 2) -}}
231231
{{- range $_ := (list 1) -}}
232232
{{- $_is_returning := false -}}
233-
{{- $_423_gid_uid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $state.Values.podTemplate "redpanda")))) "r") -}}
234-
{{- $gid := (index $_423_gid_uid 0) -}}
235-
{{- $uid := (index $_423_gid_uid 1) -}}
236-
{{- $_424_sgid_suid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $pool.Statefulset.podTemplate "redpanda")))) "r") -}}
237-
{{- $sgid := (index $_424_sgid_suid 0) -}}
238-
{{- $suid := (index $_424_sgid_suid 1) -}}
233+
{{- $_424_gid_uid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $state.Values.podTemplate "redpanda")))) "r") -}}
234+
{{- $gid := (index $_424_gid_uid 0) -}}
235+
{{- $uid := (index $_424_gid_uid 1) -}}
236+
{{- $_425_sgid_suid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $pool.Statefulset.podTemplate "redpanda")))) "r") -}}
237+
{{- $sgid := (index $_425_sgid_suid 0) -}}
238+
{{- $suid := (index $_425_sgid_suid 1) -}}
239239
{{- if (ne (toJson $sgid) "null") -}}
240240
{{- $gid = $sgid -}}
241241
{{- end -}}
@@ -312,9 +312,9 @@
312312
{{- (dict "r" (coalesce nil)) | toJson -}}
313313
{{- break -}}
314314
{{- end -}}
315-
{{- $_503_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $state $pool "set-tiered-storage-cache-dir-ownership")))) "r") -}}
316-
{{- $uid := ((index $_503_uid_gid 0) | int64) -}}
317-
{{- $gid := ((index $_503_uid_gid 1) | int64) -}}
315+
{{- $_504_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $state $pool "set-tiered-storage-cache-dir-ownership")))) "r") -}}
316+
{{- $uid := ((index $_504_uid_gid 0) | int64) -}}
317+
{{- $gid := ((index $_504_uid_gid 1) | int64) -}}
318318
{{- $cacheDir := (get (fromJson (include "redpanda.Storage.TieredCacheDirectory" (dict "a" (list $state.Values.storage $state)))) "r") -}}
319319
{{- $mounts := (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $state)))) "r") -}}
320320
{{- $mounts = (concat (default (list) $mounts) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "datadir" "mountPath" "/var/lib/redpanda/data")))) -}}

charts/redpanda/statefulset.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,10 @@ func statefulSetInitContainerTuning(state *RenderState) *corev1.Container {
371371
Capabilities: &corev1.Capabilities{
372372
Add: []corev1.Capability{`SYS_RESOURCE`},
373373
},
374-
Privileged: ptr.To(true),
375-
RunAsUser: ptr.To(int64(0)),
376-
RunAsGroup: ptr.To(int64(0)),
374+
Privileged: ptr.To(true),
375+
RunAsNonRoot: ptr.To(false),
376+
RunAsUser: ptr.To(int64(0)),
377+
RunAsGroup: ptr.To(int64(0)),
377378
},
378379
VolumeMounts: append(
379380
CommonMounts(state),

0 commit comments

Comments
 (0)