Skip to content

fix(kubernetes): CKV_K8S_40 should pass when hostUsers is false#7580

Open
UTKARSH698 wants to merge 1 commit into
bridgecrewio:mainfrom
UTKARSH698:fix-ckv-k8s-40-hostusers
Open

fix(kubernetes): CKV_K8S_40 should pass when hostUsers is false#7580
UTKARSH698 wants to merge 1 commit into
bridgecrewio:mainfrom
UTKARSH698:fix-ckv-k8s-40-hostusers

Conversation

@UTKARSH698

Copy link
Copy Markdown

Description

CKV_K8S_40 ("Containers should run as a high UID to avoid host conflict") enforces runAsUser >= 10000 so that, if a container process runs as root, its UID will not collide with a privileged UID on the host.

When a pod sets spec.hostUsers: false it runs in a private user namespace (enabled by default since Kubernetes 1.33). Container UIDs are then remapped to unprivileged, non-overlapping host UIDs, so the host-collision risk this check guards against can no longer occur. In that case the high-UID requirement is moot and the check should PASS.

This PR makes RootContainersHighUID.scan_spec_conf return PASSED early when spec.hostUsers is False.

Fixes #7527

Behaviour

  • hostUsers: false -> PASSED (private user namespace; UID collision impossible)
  • hostUsers: true or unset -> unchanged (high-UID check still applies)

The guard uses an explicit is False check, so only the namespaced case is exempted; an unset or true value keeps the original behaviour.

Tests

Extended tests/kubernetes/checks/test_RootContainersHighUID.py example manifests:

  • added a hostUsers: false pod with no runAsUser -> expected PASSED (proves the fix)
  • added an explicit hostUsers: true pod with no runAsUser -> expected FAILED (guards against over-broadening the exemption)

Expected summary counts updated to passed=4, failed=7. Test passes locally.

A pod with spec.hostUsers: false runs in a private user namespace, so
container UIDs are remapped to unprivileged host UIDs and the high-UID
host-collision risk this check guards against no longer applies.
RootContainersHighUID now returns PASSED early in that case.

Adds example manifests covering hostUsers: false (PASSED) and an explicit
hostUsers: true (still FAILED) to guard the exemption, and updates the
expected summary counts.

Closes bridgecrewio#7527
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CKV_K8S_40 (and others) should not trigger if .spec.hostUsers is false

1 participant