Skip to content

Commit 1cd6043

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

File tree

7 files changed

+760
-6548
lines changed

7 files changed

+760
-6548
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
-24.3 KB
Binary file not shown.
-24.3 KB
Binary file not shown.

charts/redpanda/statefulset.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,10 @@ func statefulSetInitContainerTuning(dot *helmette.Dot) *corev1.Container {
395395
Capabilities: &corev1.Capabilities{
396396
Add: []corev1.Capability{`SYS_RESOURCE`},
397397
},
398-
Privileged: ptr.To(true),
399-
RunAsUser: ptr.To(int64(0)),
400-
RunAsGroup: ptr.To(int64(0)),
398+
Privileged: ptr.To(true),
399+
RunAsNonRoot: ptr.To(false),
400+
RunAsUser: ptr.To(int64(0)),
401+
RunAsGroup: ptr.To(int64(0)),
401402
},
402403
VolumeMounts: append(append(CommonMounts(dot),
403404
templateToVolumeMounts(dot, values.Statefulset.InitContainers.Tuning.ExtraVolumeMounts)...),

charts/redpanda/templates/_statefulset.go.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
{{- break -}}
222222
{{- end -}}
223223
{{- $_is_returning = true -}}
224-
{{- (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) (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot)))) "r")) (default (list) (get (fromJson (include "redpanda.templateToVolumeMounts" (dict "a" (list $dot $values.statefulset.initContainers.tuning.extraVolumeMounts)))) "r")))) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "base-config" "mountPath" "/etc/redpanda")))) "resources" $values.statefulset.initContainers.tuning.resources))) | toJson -}}
224+
{{- (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) (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot)))) "r")) (default (list) (get (fromJson (include "redpanda.templateToVolumeMounts" (dict "a" (list $dot $values.statefulset.initContainers.tuning.extraVolumeMounts)))) "r")))) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "base-config" "mountPath" "/etc/redpanda")))) "resources" $values.statefulset.initContainers.tuning.resources))) | toJson -}}
225225
{{- break -}}
226226
{{- end -}}
227227
{{- end -}}
@@ -236,9 +236,9 @@
236236
{{- (dict "r" (coalesce nil)) | toJson -}}
237237
{{- break -}}
238238
{{- end -}}
239-
{{- $_426_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-datadir-ownership")))) "r") -}}
240-
{{- $uid := ((index $_426_uid_gid 0) | int64) -}}
241-
{{- $gid := ((index $_426_uid_gid 1) | int64) -}}
239+
{{- $_427_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-datadir-ownership")))) "r") -}}
240+
{{- $uid := ((index $_427_uid_gid 0) | int64) -}}
241+
{{- $gid := ((index $_427_uid_gid 1) | int64) -}}
242242
{{- $_is_returning = true -}}
243243
{{- (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)) "volumeMounts" (concat (default (list) (concat (default (list) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot)))) "r")) (default (list) (get (fromJson (include "redpanda.templateToVolumeMounts" (dict "a" (list $dot $values.statefulset.initContainers.setDataDirOwnership.extraVolumeMounts)))) "r")))) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" `datadir` "mountPath" `/var/lib/redpanda/data`)))) "resources" $values.statefulset.initContainers.setDataDirOwnership.resources))) | toJson -}}
244244
{{- break -}}
@@ -297,9 +297,9 @@
297297
{{- (dict "r" (coalesce nil)) | toJson -}}
298298
{{- break -}}
299299
{{- end -}}
300-
{{- $_508_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-tiered-storage-cache-dir-ownership")))) "r") -}}
301-
{{- $uid := ((index $_508_uid_gid 0) | int64) -}}
302-
{{- $gid := ((index $_508_uid_gid 1) | int64) -}}
300+
{{- $_509_uid_gid := (get (fromJson (include "redpanda.securityContextUidGid" (dict "a" (list $dot "set-tiered-storage-cache-dir-ownership")))) "r") -}}
301+
{{- $uid := ((index $_509_uid_gid 0) | int64) -}}
302+
{{- $gid := ((index $_509_uid_gid 1) | int64) -}}
303303
{{- $cacheDir := (get (fromJson (include "redpanda.Storage.TieredCacheDirectory" (dict "a" (list $values.storage $dot)))) "r") -}}
304304
{{- $mounts := (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot)))) "r") -}}
305305
{{- $mounts = (concat (default (list) $mounts) (list (mustMergeOverwrite (dict "name" "" "mountPath" "") (dict "name" "datadir" "mountPath" "/var/lib/redpanda/data")))) -}}

0 commit comments

Comments
 (0)