Skip to content

fix(rbac): scope _role_is_privileged() resource checks to api_groups (#144) - #145

Merged
rrskris merged 1 commit into
kaaval:mainfrom
shariqueahmad108-ship-it:fix/role-is-privileged-api-groups-144
Aug 5, 2026
Merged

rrskris merged 1 commit into
kaaval:mainfrom
shariqueahmad108-ship-it:fix/role-is-privileged-api-groups-144

Conversation

@shariqueahmad108-ship-it

Copy link
Copy Markdown
Contributor

Follow-up to #131 — this picks up the _role_is_privileged() case that was deliberately left out of scope there.

Same root cause as #125/#131: the function matches secrets and the pods/exec / pods/attach / pods/portforward subresources by name only, without looking at api_groups. So a CRD that reuses one of those names in an unrelated group makes the role look privileged. Since this feeds privileged_pod_creation, the result is a false-positive HIGH on a role that isn't actually dangerous.

The fix routes those two checks through _has_resource() with _CORE_API_GROUP, the same way _can_create_pods() and _can_impersonate() already do after #131. The wildcard and escalation-verb checks don't depend on the group, so I left them alone.

I kept the missing-api_groups behaviour from #131 on purpose: an absent or empty api_groups is treated as unspecified and still matches, so hand-built graphs from POST /rbac/combo-scan and unrendered --manifests templates don't quietly stop firing.

Tests (in control-plane/tests/test_effective_access.py):

  • a secrets grant sitting in an unrelated API group → privileged_pod_creation no longer fires
  • the same grant with no api_groups key → still fires (the regression guard)
cd control-plane
KAAVAL_ADMIN_PASSWORD=test-admin-password python -m pytest tests/test_effective_access.py -v

27 passed locally — the 25 that were already there plus these 2.

Closes #144.

…aaval#144)

_role_is_privileged() inlined its own resource checks and matched
`secrets` and the `pods/*` exec subresources by name alone, ignoring
api_groups. A CRD reusing one of those names in an unrelated group could
make a role look privileged, feeding a false-positive HIGH
privileged_pod_creation finding — the same class of bug kaaval#131 fixed for the
combo predicates.

Route those checks through _has_resource() with _CORE_API_GROUP, exactly as
_can_create_pods() and _can_impersonate() do after kaaval#131. The wildcard and
escalation-verb checks are group-independent and left unchanged. Missing or
empty api_groups stays unspecified and still matches, so hand-built graphs
from POST /rbac/combo-scan and unrendered --manifests templates are not
silently dropped.

Tests: add a privileged-SA fixture whose `secrets` grant sits in an
unrelated API group (must not fire) and the same fixture with api_groups
absent (must still fire — the regression guard).

Closes kaaval#144.

Signed-off-by: shariqueahmad108-ship-it <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>

@rrskris rrskris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving — this is exactly what #144 asked for, and I verified it rather than reading it.

The fix is correct. Both checks now route through _has_resource() with _CORE_API_GROUP, matching the pattern _can_create_pods() and _can_impersonate() took in #131. The wildcard and escalation-verb checks are left alone, which is right — they are genuinely group-independent. Behaviour on resources: ["*"] is unchanged, since the "*" in resources early return fires before either call.

The regression test does its job. I reverted effective_access.py to main and kept your tests:

FAILED test_combo_does_not_fire_when_privileged_secrets_grant_is_in_non_core_group
  AssertionError: secrets in a non-core API group must not mark a role privileged
1 failed, 26 passed

It fails without the fix and passes with it — a real reproduction, not a test written around the new code. Full suite with the fix restored: 131 passed (129 on main + your 2).

The missing-api_groups guard is the part I most wanted to see. That test passes on main too, so it catches nothing today — which is the point. It pins the behaviour that would break silently if someone later "tidied" _has_resource() into defaulting to the core group, and that failure mode drops findings rather than adding them. Encoding the reasoning from the #131 discussion into the docstring, with the issue reference, means the next person doesn't have to reconstruct it from PR archaeology.

One follow-up, not blocking: the pods/exec/attach/portforward branch got the same scoping treatment but has no test of its own — the two new cases both exercise the secrets path. Same shape of blind spot that let #125 and #144 through in the first place. I'll take that one myself rather than send you round again.

Two hours from issue filed to green PR. Merging.

@rrskris
rrskris merged commit 7dfb0b8 into kaaval:main Aug 5, 2026
7 checks passed
rrskris added a commit that referenced this pull request Aug 13, 2026
…output (#157)

The fixture YAML is right, but three of its explanatory comments describe
behaviour the scanner does not produce, which would send the next person
working on #84 chasing a phantom:

- combo-role-writer was documented as producing NO per-role finding; its
  ClusterRoleBinding raises segmentation_violation like every other
  ClusterRoleBinding over a namespaced ServiceAccount.
- combo-escalate-gate was documented as privilege_escalation_verbs MEDIUM;
  the rule scores HIGH whenever the role is cluster-scoped, and MEDIUM only
  for a namespaced Role.
- The verify block said combo_role_escalation arrives once #84 lands.
  evaluate_combo_findings() already reports it today (#105/#131/#145) —
  what #84 adds is surfacing it through the per-role scan path.

Verified by running the scan and evaluate_combo_findings() against the
fixture. Follow-up to #152 (@Maqbool61).

Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>
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.

_role_is_privileged() matches resources by name only, ignoring api_groups

2 participants