Skip to content

Commit c866988

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

File tree

5 files changed

+111
-16
lines changed

5 files changed

+111
-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/statefulset.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ func statefulSetInitContainerTuning(dot *helmette.Dot) *corev1.Container {
374374
Capabilities: &corev1.Capabilities{
375375
Add: []corev1.Capability{`SYS_RESOURCE`},
376376
},
377-
Privileged: ptr.To(true),
378-
RunAsUser: ptr.To(int64(0)),
379-
RunAsGroup: ptr.To(int64(0)),
377+
Privileged: ptr.To(true),
378+
RunAsNonRoot: ptr.To(false),
379+
RunAsUser: ptr.To(int64(0)),
380+
RunAsGroup: ptr.To(int64(0)),
380381
},
381382
VolumeMounts: append(
382383
CommonMounts(dot),

charts/redpanda/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" $values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $dot)))) "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 $dot)))) "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" $values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $dot)))) "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 $dot)))) "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-
{{- $_404_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-datadir-ownership")))) "r") -}}
219-
{{- $uid := ((index $_404_uid_gid 0) | int64) -}}
220-
{{- $gid := ((index $_404_uid_gid 1) | int64) -}}
218+
{{- $_405_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-datadir-ownership")))) "r") -}}
219+
{{- $uid := ((index $_405_uid_gid 0) | int64) -}}
220+
{{- $gid := ((index $_405_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" $values.statefulset.initContainerImage.repository $values.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 $dot)))) "r")) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" `datadir` "mountPath" `/var/lib/redpanda/data`))))))) | toJson -}}
223223
{{- break -}}
@@ -230,12 +230,12 @@
230230
{{- range $_ := (list 1) -}}
231231
{{- $_is_returning := false -}}
232232
{{- $values := $dot.Values.AsMap -}}
233-
{{- $_432_gid_uid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $values.podTemplate "redpanda")))) "r") -}}
234-
{{- $gid := (index $_432_gid_uid 0) -}}
235-
{{- $uid := (index $_432_gid_uid 1) -}}
236-
{{- $_433_sgid_suid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $values.statefulset.podTemplate "redpanda")))) "r") -}}
237-
{{- $sgid := (index $_433_sgid_suid 0) -}}
238-
{{- $suid := (index $_433_sgid_suid 1) -}}
233+
{{- $_433_gid_uid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $values.podTemplate "redpanda")))) "r") -}}
234+
{{- $gid := (index $_433_gid_uid 0) -}}
235+
{{- $uid := (index $_433_gid_uid 1) -}}
236+
{{- $_434_sgid_suid := (get (fromJson (include "redpanda.giduidFromPodTemplate" (dict "a" (list $values.statefulset.podTemplate "redpanda")))) "r") -}}
237+
{{- $sgid := (index $_434_sgid_suid 0) -}}
238+
{{- $suid := (index $_434_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-
{{- $_516_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-tiered-storage-cache-dir-ownership")))) "r") -}}
316-
{{- $uid := ((index $_516_uid_gid 0) | int64) -}}
317-
{{- $gid := ((index $_516_uid_gid 1) | int64) -}}
315+
{{- $_517_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-tiered-storage-cache-dir-ownership")))) "r") -}}
316+
{{- $uid := ((index $_517_uid_gid 0) | int64) -}}
317+
{{- $gid := ((index $_517_uid_gid 1) | int64) -}}
318318
{{- $cacheDir := (get (fromJson (include "redpanda.Storage.TieredCacheDirectory" (dict "a" (list $values.storage $dot)))) "r") -}}
319319
{{- $mounts := (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot)))) "r") -}}
320320
{{- $mounts = (concat (default (list) $mounts) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "datadir" "mountPath" "/var/lib/redpanda/data")))) -}}

0 commit comments

Comments
 (0)