Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/parser/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@ func readSecurity(n *yaml.Node) SecurityContext {
}

func applySecFields(ctx *yaml.Node, out *SecurityContext) {
for _, key := range [][2]string{
{"hostNetwork", "HostNetwork"},
{"hostPID", "HostPID"},
{"hostIPC", "HostIPC"},
} {
if v := findChild(ctx, key[0]); v != nil && v.Kind == yaml.ScalarNode {
b := boolValue(v.Value)
switch key[1] {
case "HostNetwork":
if out.HostNetwork == nil {
out.HostNetwork = &b
}
case "HostPID":
if out.HostPID == nil {
out.HostPID = &b
}
case "HostIPC":
if out.HostIPC == nil {
out.HostIPC = &b
}
}
}
}

if v := findChild(ctx, "runAsNonRoot"); v != nil && v.Kind == yaml.ScalarNode {
b := boolValue(v.Value)
out.RunAsNonRoot = &b
Expand Down
54 changes: 54 additions & 0 deletions pkg/parser/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,60 @@ features:
in: "- a\n- b\n",
wantErr: true,
},
{
// hostNetwork/PID/IPC nested under podSecurityContext were silently
// ignored before the applySecFields fix (issue #39).
name: "host-namespace-flags-nested-under-podSecurityContext",
in: `
agent:
resources:
requests:
cpu: "100m"
podSecurityContext:
hostNetwork: true
hostPID: true
hostIPC: true
`,
check: func(t *testing.T, wls []Workload) {
t.Helper()
if len(wls) != 1 {
t.Fatalf("expected 1 workload, got %d", len(wls))
}
sec := wls[0].Security
if sec.HostNetwork == nil || !*sec.HostNetwork {
t.Errorf("HostNetwork = %v, want *true", sec.HostNetwork)
}
if sec.HostPID == nil || !*sec.HostPID {
t.Errorf("HostPID = %v, want *true", sec.HostPID)
}
if sec.HostIPC == nil || !*sec.HostIPC {
t.Errorf("HostIPC = %v, want *true", sec.HostIPC)
}
},
},
{
// Workload-level values must not be overwritten by podSecurityContext.
name: "workload-level-host-flags-take-precedence",
in: `
agent:
resources:
requests:
cpu: "100m"
hostNetwork: false
podSecurityContext:
hostNetwork: true
`,
check: func(t *testing.T, wls []Workload) {
t.Helper()
if len(wls) != 1 {
t.Fatalf("expected 1 workload, got %d", len(wls))
}
sec := wls[0].Security
if sec.HostNetwork == nil || *sec.HostNetwork {
t.Errorf("HostNetwork = %v, want *false (workload level wins)", sec.HostNetwork)
}
},
},
{
name: "deterministic-alpha-order",
in: `
Expand Down