Skip to content

Commit 840023a

Browse files
authored
fix: keep global security defaults scoped (#32)
## Summary - resolve global security context defaults into a temporary map instead of emitting raw YAML - merge pod/container contexts with set-based helper to avoid leaking other global values into securityContext blocks - update Besu and bootstrapper manifests to consume the shared helper without fromYaml conversions ## Testing - helm template test charts/network --namespace test - bun run check - bun run typecheck - bun run test ## Summary by Sourcery Refactor Helm chart security context helpers to isolate global defaults in a scoped map and update chart templates to use the new helper signature, eliminating raw YAML emission and parsing. Bug Fixes: - Prevent leaking unrelated global securityContext values into pod and container contexts Enhancements: - Refactor securityContexts helper to accept a destination map and merge global pod/container defaults with chart overrides in-place - Update network-bootstrapper and network-nodes templates to initialize a dest dict and invoke the refactored helper without relying on raw YAML or fromYaml parsing
1 parent 2c946b1 commit 840023a

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

charts/network/charts/network-bootstrapper/templates/_helpers.tpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ Accepts either a YAML string or a list of init container maps and indents output
8282
Resolve pod and container security contexts by layering chart values over global defaults.
8383
*/}}
8484
{{- define "network-bootstrapper.securityContexts" -}}
85-
{{- $root := . -}}
86-
{{- $globalValues := ($root.Values.global | default (dict)) -}}
87-
{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) -}}
88-
{{- $pod := mergeOverwrite (deepCopy (dig "pod" $globalSecurityContexts (dict))) (default (dict) $root.Values.podSecurityContext) -}}
89-
{{- $container := mergeOverwrite (deepCopy (dig "container" $globalSecurityContexts (dict))) (default (dict) $root.Values.securityContext) -}}
90-
{{- dict "pod" $pod "container" $container | toYaml -}}
85+
{{- $ctx := index . "ctx" -}}
86+
{{- $dest := index . "dest" -}}
87+
{{- $globalValues := ($ctx.Values.global | default (dict)) -}}
88+
{{- $globalSecurityContexts := default (dict) (get $globalValues "securityContexts") -}}
89+
{{- $podDefaults := default (dict) (get $globalSecurityContexts "pod") -}}
90+
{{- $containerDefaults := default (dict) (get $globalSecurityContexts "container") -}}
91+
{{- $_ := set $dest "pod" (mergeOverwrite (deepCopy $podDefaults) (default (dict) $ctx.Values.podSecurityContext)) -}}
92+
{{- $_ := set $dest "container" (mergeOverwrite (deepCopy $containerDefaults) (default (dict) $ctx.Values.securityContext)) -}}
9193
{{- end -}}

charts/network/charts/network-bootstrapper/templates/job.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ spec:
2727
{{- toYaml . | nindent 8 }}
2828
{{- end }}
2929
serviceAccountName: {{ include "network-bootstrapper.serviceAccountName" . }}
30-
{{- $securityContexts := include "network-bootstrapper.securityContexts" . | fromYaml }}
30+
{{- $securityContexts := dict -}}
31+
{{- include "network-bootstrapper.securityContexts" (dict "ctx" . "dest" $securityContexts) -}}
3132
{{- $podSecurityContext := index $securityContexts "pod" }}
3233
{{- $containerSecurityContext := index $securityContexts "container" }}
3334
{{- if $podSecurityContext }}

charts/network/charts/network-nodes/templates/_helpers.tpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ Accepts either a YAML string or a list of init container maps and indents output
131131
Resolve pod and container security contexts using global defaults plus chart overrides.
132132
*/}}
133133
{{- define "nodes.securityContexts" -}}
134-
{{- $root := . -}}
135-
{{- $globalValues := ($root.Values.global | default (dict)) -}}
136-
{{- $globalSecurityContexts := dig "securityContexts" $globalValues (dict) -}}
137-
{{- $pod := mergeOverwrite (deepCopy (dig "pod" $globalSecurityContexts (dict))) (default (dict) $root.Values.podSecurityContext) -}}
138-
{{- $container := mergeOverwrite (deepCopy (dig "container" $globalSecurityContexts (dict))) (default (dict) $root.Values.securityContext) -}}
139-
{{- dict "pod" $pod "container" $container | toYaml -}}
134+
{{- $ctx := index . "ctx" -}}
135+
{{- $dest := index . "dest" -}}
136+
{{- $globalValues := ($ctx.Values.global | default (dict)) -}}
137+
{{- $globalSecurityContexts := default (dict) (get $globalValues "securityContexts") -}}
138+
{{- $podDefaults := default (dict) (get $globalSecurityContexts "pod") -}}
139+
{{- $containerDefaults := default (dict) (get $globalSecurityContexts "container") -}}
140+
{{- $_ := set $dest "pod" (mergeOverwrite (deepCopy $podDefaults) (default (dict) $ctx.Values.podSecurityContext)) -}}
141+
{{- $_ := set $dest "container" (mergeOverwrite (deepCopy $containerDefaults) (default (dict) $ctx.Values.securityContext)) -}}
140142
{{- end -}}

charts/network/charts/network-nodes/templates/statefulset-rpc.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ spec:
3636
{{- $initContainers := .Values.initContainers | default (dict) }}
3737
{{- $sharedInitContainers := get $initContainers "shared" }}
3838
{{- $rpcInitContainers := get $initContainers "rpc" }}
39-
{{- $securityContexts := include "nodes.securityContexts" . | fromYaml }}
39+
{{- $securityContexts := dict -}}
40+
{{- include "nodes.securityContexts" (dict "ctx" . "dest" $securityContexts) -}}
4041
{{- $podSecurityContext := index $securityContexts "pod" }}
4142
{{- $containerSecurityContext := index $securityContexts "container" }}
4243
podManagementPolicy: Parallel

charts/network/charts/network-nodes/templates/statefulset-validator.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ spec:
3737
{{- $initContainers := .Values.initContainers | default (dict) }}
3838
{{- $sharedInitContainers := get $initContainers "shared" }}
3939
{{- $validatorInitContainers := get $initContainers "validator" }}
40-
{{- $securityContexts := include "nodes.securityContexts" . | fromYaml }}
40+
{{- $securityContexts := dict -}}
41+
{{- include "nodes.securityContexts" (dict "ctx" . "dest" $securityContexts) -}}
4142
{{- $podSecurityContext := index $securityContexts "pod" }}
4243
{{- $containerSecurityContext := index $securityContexts "container" }}
4344
podManagementPolicy: Parallel

0 commit comments

Comments
 (0)