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

Conversation

RamLavi
Copy link
Collaborator

@RamLavi RamLavi commented Jun 3, 2025

What this PR does / why we need it:
This pull request improves the security posture of the linux-bridge SecurityContextConstraints (SCC) by introducing two changes:

  1. Restrict SELinux context to MustRunAs with spc_t type.
  2. Restrict allowed volume types to only hostPath, configMap, and secret.

Special notes for your reviewer:
To anticipate reviewers request, commented on the PR why I did NOT remove other SCCs.

Release note:

reduce linux bridge SCC

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 <ralavi@redhat.com>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Jun 3, 2025
@kubevirt-bot kubevirt-bot requested review from oshoval and phoracek June 3, 2025 18:07
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign oshoval for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@RamLavi
Copy link
Collaborator Author

RamLavi commented Jun 3, 2025

/hold
I want to check this on kcli locally to make sure it works

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 3, 2025
@RamLavi
Copy link
Collaborator Author

RamLavi commented Jun 5, 2025

🔒 SCC Non-Default Capabilities Review

Capability Set To Default Reason
allowPrivilegedContainer true false Needed to access and write to root-owned hostPath directories (/opt/cni/bin, /var/lib/cni/bin). Without this, the container would get permission denied errors.
allowHostDirVolumePlugin true false Needed to mount hostPath volumes for CNI plugin installation on the host filesystem.
readOnlyRootFilesystem true false Similarly to restricted-v2, harden the container by preventing write access to the root filesystem. Mitigates potential runtime filesystem tampering.
runAsUser RunAsAny MustRunAsRange Container must run as UID 0 (root) to perform cp and ln operations into hostPath volumes, which are owned by root.
seLinuxContext MustRunAs with spc_t MustRunAs Privileged containers must use spc_t SELinux type in OpenShift to access the host securely while maintaining SELinux enforcement.
volumes hostPath, configMap, secret Only safe types (no hostPath) Allow only necessary volume types. Avoids wildcard (*) volume allowance to reduce attack surface.

📚 Sources:

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 <ralavi@redhat.com>
@RamLavi RamLavi force-pushed the linux_brige_reduce_scc branch from f6cc02e to 43b48a6 Compare June 5, 2025 09:14
…mptyDir

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 <ralavi@redhat.com>
@RamLavi RamLavi force-pushed the linux_brige_reduce_scc branch from 43b48a6 to 26d5db9 Compare June 5, 2025 10:38
Copy link

sonarqubecloud bot commented Jun 5, 2025

Copy link
Contributor

@maiqueb maiqueb left a comment

Choose a reason for hiding this comment

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

just a question.

tks for adding the table describing the changes.

Comment on lines +76 to +77
- name: tmp
mountPath: /tmp
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..

@RamLavi
Copy link
Collaborator Author

RamLavi commented Jun 5, 2025

checked on kcli that linux bridge is properly deployed (used U/S CNAO and external provider to deploy with the change). compared binaries checksum before and after the SCC change in order to verify they are indeed the same.

/hold cancel

@kubevirt-bot kubevirt-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2025
@oshoval
Copy link
Collaborator

oshoval commented Jun 5, 2025

Once we return the DaemonSet of passt this way or another, we will need to do more or less the same there right ?

https://github.com/kubevirt/ipam-extensions/pull/50/files#diff-ad4bb703999139ceb1971eca665b98b606f15db349ef5372346405b65a18b458

as it also does more or less what linux-bridge container does

@RamLavi
Copy link
Collaborator Author

RamLavi commented Jun 5, 2025

Once we return the DaemonSet of passt this way or another, we will need to do more or less the same there right ?

https://github.com/kubevirt/ipam-extensions/pull/50/files#diff-ad4bb703999139ceb1971eca665b98b606f15db349ef5372346405b65a18b458

as it also does more or less what linux-bridge container does

pretty much, yes. All containers should adhere to scc best practices, and it will probably have similar considerations..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants