Skip to content

Commit e19a891

Browse files
authored
Harden bridge-marker SCC: restrict privileges, enforce non-root, allow projected volumes (#2336)
* bridge-marker, scc: Drop unnecessary host volume privileges in SCC - Disallow hostDir volume plugins. - Restrict volume types to configMap and emptyDir. - Restrict volumes access to basic folders. Projected volume is required for ServiceAccount token mounts. Signed-off-by: Ram Lavi <[email protected]> * bridge-marker: mount writable /tmp to support runtime dependencies As a preliminary step to the next commit where runtime dependencies are hardened, mounting /tmp. This is required for compatibility with Go libraries and client-go when using readOnlyRootFilesystem. This commit mounts an emptyDir at /tmp to provide writable scratch space for the container. This change should also occur on the repo itself, but until it does, and in order to allow for smooth bump when it occurs - it should stay. Signed-off-by: Ram Lavi <[email protected]> * bridge-marker, scc: Enforce stricter runtime restrictions - Enable readOnlyRootFilesystem for better container isolation. - Require containers to run as non-root users. - Set SELinux context type to MustRunAs for confinement. Signed-off-by: Ram Lavi <[email protected]> * ds/bridge-marker: Add securityContext to enforce non-root UID and read-only rootfs - Configure container to run as non-root user explicitly (UID 1001). - Enable read-only root filesystem at container level. - Ensure consistent non-root enforcement across architectures. This change should also occur on the repo itself, but until it does, and in order to allow for smooth bump when it occurs - it should stay. Signed-off-by: Ram Lavi <[email protected]> --------- Signed-off-by: Ram Lavi <[email protected]>
1 parent e8b06bb commit e19a891

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

data/linux-bridge/003-bridge-marker.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ spec:
4747
fieldRef:
4848
fieldPath: spec.nodeName
4949
terminationMessagePolicy: FallbackToLogsOnError
50+
volumeMounts:
51+
- name: tmp
52+
mountPath: /tmp
5053
affinity: {{ toYaml .Placement.Affinity | nindent 8 }}
54+
volumes:
55+
- name: tmp
56+
emptyDir: {}
57+
securityContext:
58+
runAsNonRoot: true
59+
runAsUser: 1001
60+
readOnlyRootFilesystem: true
5161
---
5262
kind: ClusterRole
5363
apiVersion: rbac.authorization.k8s.io/v1
@@ -89,19 +99,21 @@ kind: SecurityContextConstraints
8999
metadata:
90100
name: bridge-marker
91101
allowHostNetwork: true
92-
allowHostDirVolumePlugin: true
102+
allowHostDirVolumePlugin: false
93103
allowPrivilegedContainer: false
94-
readOnlyRootFilesystem: false
104+
readOnlyRootFilesystem: true
95105
allowHostIPC: false
96106
allowHostPID: false
97107
allowHostPorts: false
98108
runAsUser:
99-
type: RunAsAny
109+
type: MustRunAsNonRoot
100110
seLinuxContext:
101-
type: RunAsAny
111+
type: MustRunAs
102112
users:
103113
- system:serviceaccount:{{ .Namespace }}:bridge-marker
104114
volumes:
105-
- "*"
115+
- configMap
116+
- emptyDir
117+
- projected
106118
{{ end }}
107119
---

hack/components/bump-bridge-marker.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ function __parametize_by_object() {
2626
yaml-utils::set_param ${f} spec.template.spec.affinity '{{ toYaml .Placement.Affinity | nindent 8 }}'
2727
yaml-utils::set_param ${f} 'spec.template.metadata.annotations."openshift.io/required-scc"' '"bridge-marker"'
2828
yaml-utils::update_param ${f} spec.template.spec.tolerations '{{ toYaml .Placement.Tolerations | nindent 8 }}'
29+
yaml-utils::set_param ${f} spec.template.spec.volumes[0].name 'tmp'
30+
yaml-utils::set_param ${f} spec.template.spec.volumes[0].emptyDir '{}'
31+
yaml-utils::set_param ${f} spec.template.spec.containers[0].volumeMounts[0].name 'tmp'
32+
yaml-utils::set_param ${f} spec.template.spec.containers[0].volumeMounts[0].mountPath '/tmp'
33+
yaml-utils::set_param ${f} spec.template.spec.securityContext.runAsNonRoot 'true'
34+
yaml-utils::set_param ${f} spec.template.spec.securityContext.runAsUser '1001'
35+
yaml-utils::set_param ${f} spec.template.spec.securityContext.readOnlyRootFilesystem 'true'
2936
yaml-utils::remove_single_quotes_from_yaml ${f}
3037
;;
3138
esac
@@ -68,20 +75,22 @@ kind: SecurityContextConstraints
6875
metadata:
6976
name: bridge-marker
7077
allowHostNetwork: true
71-
allowHostDirVolumePlugin: true
78+
allowHostDirVolumePlugin: false
7279
allowPrivilegedContainer: false
73-
readOnlyRootFilesystem: false
80+
readOnlyRootFilesystem: true
7481
allowHostIPC: false
7582
allowHostPID: false
7683
allowHostPorts: false
7784
runAsUser:
78-
type: RunAsAny
85+
type: MustRunAsNonRoot
7986
seLinuxContext:
80-
type: RunAsAny
87+
type: MustRunAs
8188
users:
8289
- system:serviceaccount:{{ .Namespace }}:bridge-marker
8390
volumes:
84-
- "*"
91+
- configMap
92+
- emptyDir
93+
- projected
8594
{{ end }}
8695
---
8796
EOF

0 commit comments

Comments
 (0)