Skip to content

Linux bridge: Harden SCC by restricting SELinux context and allowed volume types #2331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions data/linux-bridge/001-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
readOnlyRootFilesystem: false
readOnlyRootFilesystem: true
runAsUser:
type: RunAsAny
seLinuxContext:
type: RunAsAny
type: MustRunAs
seLinuxOptions:
type: spc_t
users:
- system:serviceaccount:{{ .Namespace }}:linux-bridge
volumes:
- "*"
- hostPath
- configMap
- secret
- emptyDir
{{ end }}
5 changes: 5 additions & 0 deletions data/linux-bridge/002-linux-bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ spec:
memory: "15Mi"
securityContext:
privileged: true
readOnlyRootFilesystem: true
volumeMounts:
- name: cnibin
mountPath: /opt/cni/bin
- name: tmp
mountPath: /tmp
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need access to /tmp ? Seems we didn't need it before. Why add it now ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the commit message:

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOW, if the files are too big they sometimes write to tmp. To be safe - mount an empty tmp folder, so that it won't explode should some cp decides to use that folder..

terminationMessagePolicy: FallbackToLogsOnError
volumes:
- name: cnibin
hostPath:
path: {{ .CNIBinDir }}
- name: tmp
emptyDir: { }