Skip to content

Commit c138c17

Browse files
committed
fix: controller and sidecar containers run as non-root
Signed-off-by: Jonathan Battiato <[email protected]>
1 parent 0c8b725 commit c138c17

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

internal/cnpgi/operator/lifecycle.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ func reconcilePodSpec(
296296
sidecarConfig.Image = viper.GetString("sidecar-image")
297297
sidecarConfig.ImagePullPolicy = cluster.Spec.ImagePullPolicy
298298
sidecarConfig.StartupProbe = baseProbe.DeepCopy()
299+
sidecarConfig.SecurityContext = &corev1.SecurityContext{
300+
AllowPrivilegeEscalation: ptr.To(false),
301+
RunAsNonRoot: ptr.To(true),
302+
Privileged: ptr.To(false),
303+
ReadOnlyRootFilesystem: ptr.To(true),
304+
SeccompProfile: &corev1.SeccompProfile{
305+
Type: corev1.SeccompProfileTypeRuntimeDefault,
306+
},
307+
Capabilities: &corev1.Capabilities{
308+
Drop: []corev1.Capability{"ALL"},
309+
},
310+
}
299311

300312
// merge the main container envs if they aren't already set
301313
for _, container := range spec.Containers {

kubernetes/deployment.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ spec:
1616
labels:
1717
app: barman-cloud
1818
spec:
19+
securityContext:
20+
runAsNonRoot: true
21+
seccompProfile:
22+
type: RuntimeDefault
1923
serviceAccountName: plugin-barman-cloud
2024
containers:
2125
- image: plugin-barman-cloud:latest
@@ -48,6 +52,16 @@ spec:
4852
- mountPath: /client
4953
name: client
5054
resources: {}
55+
securityContext:
56+
allowPrivilegeEscalation: false
57+
capabilities:
58+
drop:
59+
- ALL
60+
readOnlyRootFilesystem: true
61+
runAsGroup: 10001
62+
runAsUser: 10001
63+
seccompProfile:
64+
type: RuntimeDefault
5165
volumes:
5266
- name: server
5367
secret:

0 commit comments

Comments
 (0)