Skip to content

Commit b63db5e

Browse files
vishwaktclaude
andcommitted
feat(chart): expose podSecurityContext and securityContext values
Add `podSecurityContext` (pod-level) and `securityContext` (container-level) values and wire them into both the Deployment and DaemonSet templates. Secure defaults are provided so the controller no longer runs as root with a writable root filesystem out of the box, satisfying the Pod Security "restricted" profile and lint gates such as kube-linter's `run-as-non-root` and `no-read-only-root-fs`: - podSecurityContext: runAsNonRoot, runAsUser 65532, RuntimeDefault seccomp - securityContext: readOnlyRootFilesystem, no privilege escalation, drop ALL The runtime does not write to its root filesystem, so readOnlyRootFilesystem is safe. Both blocks are `with`-guarded so operators can relax them by overriding the values. Closes #1253 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7ed3ba7 commit b63db5e

7 files changed

Lines changed: 93 additions & 0 deletions

File tree

chart/.snapshots/default.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ kind: ServiceAccount
55
metadata:
66
name: hcloud-cloud-controller-manager
77
namespace: kube-system
8+
89
---
910
# Source: hcloud-cloud-controller-manager/templates/clusterrole.yml
1011
apiVersion: rbac.authorization.k8s.io/v1
@@ -70,6 +71,7 @@ rules:
7071
- list
7172
- watch
7273
- update
74+
7375
---
7476
# Source: hcloud-cloud-controller-manager/templates/clusterrolebinding.yaml
7577
kind: ClusterRoleBinding
@@ -86,6 +88,7 @@ subjects:
8688
- kind: ServiceAccount
8789
name: hcloud-cloud-controller-manager
8890
namespace: kube-system
91+
8992
---
9093
# Source: hcloud-cloud-controller-manager/templates/deployment.yaml
9194
apiVersion: apps/v1
@@ -107,6 +110,11 @@ spec:
107110
app.kubernetes.io/name: 'hcloud-cloud-controller-manager'
108111
spec:
109112
serviceAccountName: hcloud-cloud-controller-manager
113+
securityContext:
114+
runAsNonRoot: true
115+
runAsUser: 65532
116+
seccompProfile:
117+
type: RuntimeDefault
110118
dnsPolicy: Default
111119
tolerations:
112120
# Allow HCCM itself to schedule on nodes that have not yet been initialized by HCCM.
@@ -128,6 +136,12 @@ spec:
128136
effect: "NoExecute"
129137
containers:
130138
- name: hcloud-cloud-controller-manager
139+
securityContext:
140+
allowPrivilegeEscalation: false
141+
capabilities:
142+
drop:
143+
- ALL
144+
readOnlyRootFilesystem: true
131145
args:
132146
- "--allow-untagged-cloud"
133147
- "--cloud-provider=hcloud"

chart/.snapshots/full.daemonset.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ kind: ServiceAccount
55
metadata:
66
name: hcloud-cloud-controller-manager
77
namespace: kube-system
8+
89
---
910
# Source: hcloud-cloud-controller-manager/templates/clusterrole.yml
1011
apiVersion: rbac.authorization.k8s.io/v1
@@ -70,6 +71,7 @@ rules:
7071
- list
7172
- watch
7273
- update
74+
7375
---
7476
# Source: hcloud-cloud-controller-manager/templates/clusterrolebinding.yaml
7577
kind: ClusterRoleBinding
@@ -86,6 +88,7 @@ subjects:
8688
- kind: ServiceAccount
8789
name: hcloud-cloud-controller-manager
8890
namespace: kube-system
91+
8992
---
9093
# Source: hcloud-cloud-controller-manager/templates/daemonset.yaml
9194
apiVersion: apps/v1
@@ -109,6 +112,11 @@ spec:
109112
pod-annotation: pod-annotation
110113
spec:
111114
serviceAccountName: hcloud-cloud-controller-manager
115+
securityContext:
116+
runAsNonRoot: true
117+
runAsUser: 65532
118+
seccompProfile:
119+
type: RuntimeDefault
112120
dnsPolicy: Default
113121
tolerations:
114122
# Allow HCCM itself to schedule on nodes that have not yet been initialized by HCCM.
@@ -137,6 +145,12 @@ spec:
137145
foo: bar
138146
containers:
139147
- name: hcloud-cloud-controller-manager
148+
securityContext:
149+
allowPrivilegeEscalation: false
150+
capabilities:
151+
drop:
152+
- ALL
153+
readOnlyRootFilesystem: true
140154
command:
141155
- "/bin/hcloud-cloud-controller-manager"
142156
- "--allow-untagged-cloud"

chart/templates/daemonset.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ spec:
2626
{{- toYaml . | nindent 8 }}
2727
{{- end }}
2828
serviceAccountName: {{ include "hcloud-cloud-controller-manager.name" . }}
29+
{{- with .Values.podSecurityContext }}
30+
securityContext:
31+
{{- toYaml . | nindent 8 }}
32+
{{- end }}
2933
dnsPolicy: Default
3034
tolerations:
3135
# Allow HCCM itself to schedule on nodes that have not yet been initialized by HCCM.
@@ -60,6 +64,10 @@ spec:
6064
{{- end }}
6165
containers:
6266
- name: hcloud-cloud-controller-manager
67+
{{- with .Values.securityContext }}
68+
securityContext:
69+
{{- toYaml . | nindent 12 }}
70+
{{- end }}
6371
command:
6472
- "/bin/hcloud-cloud-controller-manager"
6573
{{- range $key, $value := $.Values.args }}

chart/templates/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ spec:
3131
{{- toYaml . | nindent 8 }}
3232
{{- end }}
3333
serviceAccountName: {{ include "hcloud-cloud-controller-manager.name" . }}
34+
{{- with .Values.podSecurityContext }}
35+
securityContext:
36+
{{- toYaml . | nindent 8 }}
37+
{{- end }}
3438
dnsPolicy: {{ .Values.dnsPolicy }}
3539
{{- with .Values.dnsConfig }}
3640
dnsConfig:
@@ -74,6 +78,10 @@ spec:
7478
{{- end }}
7579
containers:
7680
- name: hcloud-cloud-controller-manager
81+
{{- with .Values.securityContext }}
82+
securityContext:
83+
{{- toYaml . | nindent 12 }}
84+
{{- end }}
7785
args:
7886
{{- range $key, $value := $.Values.args }}
7987
{{- if not (eq $value nil) }}

chart/values.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ resources:
120120
cpu: 100m
121121
memory: 50Mi
122122

123+
# Pod-level security context for the hccm Pod.
124+
# The defaults run the controller as a non-root user with a RuntimeDefault
125+
# seccomp profile, satisfying the Pod Security "restricted" profile.
126+
# Set to {} (or override individual fields) to relax these constraints.
127+
podSecurityContext:
128+
runAsNonRoot: true
129+
runAsUser: 65532
130+
seccompProfile:
131+
type: RuntimeDefault
132+
133+
# Container-level security context for the hccm container.
134+
# The controller does not write to its root filesystem at runtime, so a
135+
# read-only root filesystem with all capabilities dropped is safe by default.
136+
# Set to {} (or override individual fields) to relax these constraints.
137+
securityContext:
138+
readOnlyRootFilesystem: true
139+
allowPrivilegeEscalation: false
140+
capabilities:
141+
drop:
142+
- ALL
143+
123144
selectorLabels:
124145
app.kubernetes.io/name: '{{ include "hcloud-cloud-controller-manager.name" $ }}'
125146
app.kubernetes.io/instance: "{{ $.Release.Name }}"

deploy/ccm-networks.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ kind: ServiceAccount
55
metadata:
66
name: hcloud-cloud-controller-manager
77
namespace: kube-system
8+
89
---
910
# Source: hcloud-cloud-controller-manager/templates/clusterrole.yml
1011
apiVersion: rbac.authorization.k8s.io/v1
@@ -70,6 +71,7 @@ rules:
7071
- list
7172
- watch
7273
- update
74+
7375
---
7476
# Source: hcloud-cloud-controller-manager/templates/clusterrolebinding.yaml
7577
kind: ClusterRoleBinding
@@ -86,6 +88,7 @@ subjects:
8688
- kind: ServiceAccount
8789
name: hcloud-cloud-controller-manager
8890
namespace: kube-system
91+
8992
---
9093
# Source: hcloud-cloud-controller-manager/templates/deployment.yaml
9194
apiVersion: apps/v1
@@ -105,6 +108,11 @@ spec:
105108
app: hcloud-cloud-controller-manager
106109
spec:
107110
serviceAccountName: hcloud-cloud-controller-manager
111+
securityContext:
112+
runAsNonRoot: true
113+
runAsUser: 65532
114+
seccompProfile:
115+
type: RuntimeDefault
108116
dnsPolicy: Default
109117
tolerations:
110118
# Allow HCCM itself to schedule on nodes that have not yet been initialized by HCCM.
@@ -127,6 +135,12 @@ spec:
127135
hostNetwork: true
128136
containers:
129137
- name: hcloud-cloud-controller-manager
138+
securityContext:
139+
allowPrivilegeEscalation: false
140+
capabilities:
141+
drop:
142+
- ALL
143+
readOnlyRootFilesystem: true
130144
args:
131145
- "--allow-untagged-cloud"
132146
- "--cloud-provider=hcloud"

deploy/ccm.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ kind: ServiceAccount
55
metadata:
66
name: hcloud-cloud-controller-manager
77
namespace: kube-system
8+
89
---
910
# Source: hcloud-cloud-controller-manager/templates/clusterrole.yml
1011
apiVersion: rbac.authorization.k8s.io/v1
@@ -70,6 +71,7 @@ rules:
7071
- list
7172
- watch
7273
- update
74+
7375
---
7476
# Source: hcloud-cloud-controller-manager/templates/clusterrolebinding.yaml
7577
kind: ClusterRoleBinding
@@ -86,6 +88,7 @@ subjects:
8688
- kind: ServiceAccount
8789
name: hcloud-cloud-controller-manager
8890
namespace: kube-system
91+
8992
---
9093
# Source: hcloud-cloud-controller-manager/templates/deployment.yaml
9194
apiVersion: apps/v1
@@ -105,6 +108,11 @@ spec:
105108
app: hcloud-cloud-controller-manager
106109
spec:
107110
serviceAccountName: hcloud-cloud-controller-manager
111+
securityContext:
112+
runAsNonRoot: true
113+
runAsUser: 65532
114+
seccompProfile:
115+
type: RuntimeDefault
108116
dnsPolicy: Default
109117
tolerations:
110118
# Allow HCCM itself to schedule on nodes that have not yet been initialized by HCCM.
@@ -126,6 +134,12 @@ spec:
126134
effect: "NoExecute"
127135
containers:
128136
- name: hcloud-cloud-controller-manager
137+
securityContext:
138+
allowPrivilegeEscalation: false
139+
capabilities:
140+
drop:
141+
- ALL
142+
readOnlyRootFilesystem: true
129143
args:
130144
- "--allow-untagged-cloud"
131145
- "--cloud-provider=hcloud"

0 commit comments

Comments
 (0)