Skip to content

Commit 5788c1f

Browse files
fix: controller and sidecar containers run as non-root (#225)
Closes #177 Signed-off-by: Jonathan Battiato <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
1 parent a7ef56b commit 5788c1f

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

internal/cnpgi/operator/lifecycle.go

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

303315
// merge the main container envs if they aren't already set
304316
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:

manifest.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,25 @@ spec:
871871
tcpSocket:
872872
port: 9090
873873
resources: {}
874+
securityContext:
875+
allowPrivilegeEscalation: false
876+
capabilities:
877+
drop:
878+
- ALL
879+
readOnlyRootFilesystem: true
880+
runAsGroup: 10001
881+
runAsUser: 10001
882+
seccompProfile:
883+
type: RuntimeDefault
874884
volumeMounts:
875885
- mountPath: /server
876886
name: server
877887
- mountPath: /client
878888
name: client
889+
securityContext:
890+
runAsNonRoot: true
891+
seccompProfile:
892+
type: RuntimeDefault
879893
serviceAccountName: plugin-barman-cloud
880894
volumes:
881895
- name: server

0 commit comments

Comments
 (0)