Skip to content

Commit e8b06bb

Browse files
authored
Linux bridge: Harden SCC by restricting SELinux context and allowed volume types (#2331)
* linux-bridge, scc: Restrict SELinux context to MustRunAs with spc_t type Switch the SecurityContextConstraints (SCC) policy from RunAsAny to MustRunAs for the SELinux context. Additionally, specify the SELinux type as spc_t to better confine the privileged container. This strengthens the SELinux policy, ensuring that even privileged containers are restricted by a specific SELinux type, improving overall security posture. Signed-off-by: Ram Lavi <[email protected]> * linux-bridge, scc: Restrict volumes paths. Limit the allowed volume types in the SCC to only hostPath, configMap, and secret, removing the wildcard "*" that allowed all volume types. This reduces the container's access to only the required volume types and follows the principle of least privilege for better security hardening. Signed-off-by: Ram Lavi <[email protected]> * linux-bridge, scc: Enable readOnlyRootFilesystem with writable /tmp emptyDir Harden the linux-bridge DaemonSet by enabling readOnlyRootFilesystem: true, ensuring that the container's root filesystem is immutable to enhance security. Since some system utilities (e.g., bash, cp, sha256sum) may require a writable /tmp directory, mount an emptyDir at /tmp to provide a writable scratch space, following container security best practices [0]. Also update the associated SCC to enforce readOnlyRootFilesystem: true at the policy level. [0] https://redhat-best-practices-for-k8s.github.io/guide/#k8s-best-practices-storage:-emptydir Signed-off-by: Ram Lavi <[email protected]> --------- Signed-off-by: Ram Lavi <[email protected]>
1 parent cd88e4b commit e8b06bb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

data/linux-bridge/001-rbac.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ allowHostIPC: false
1616
allowHostNetwork: false
1717
allowHostPID: false
1818
allowHostPorts: false
19-
readOnlyRootFilesystem: false
19+
readOnlyRootFilesystem: true
2020
runAsUser:
2121
type: RunAsAny
2222
seLinuxContext:
23-
type: RunAsAny
23+
type: MustRunAs
24+
seLinuxOptions:
25+
type: spc_t
2426
users:
2527
- system:serviceaccount:{{ .Namespace }}:linux-bridge
2628
volumes:
27-
- "*"
29+
- hostPath
30+
- configMap
31+
- secret
32+
- emptyDir
2833
{{ end }}

data/linux-bridge/002-linux-bridge.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ spec:
6969
memory: "15Mi"
7070
securityContext:
7171
privileged: true
72+
readOnlyRootFilesystem: true
7273
volumeMounts:
7374
- name: cnibin
7475
mountPath: /opt/cni/bin
76+
- name: tmp
77+
mountPath: /tmp
7578
terminationMessagePolicy: FallbackToLogsOnError
7679
volumes:
7780
- name: cnibin
7881
hostPath:
7982
path: {{ .CNIBinDir }}
83+
- name: tmp
84+
emptyDir: { }

0 commit comments

Comments
 (0)