Repository navigation
fix(rbac): scope _role_is_privileged() resource checks to api_groups (#144) - #145
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
…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]>
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
secretsand thepods/exec/pods/attach/pods/portforwardsubresources by name only, without looking atapi_groups. So a CRD that reuses one of those names in an unrelated group makes the role look privileged. Since this feedsprivileged_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_groupsbehaviour from #131 on purpose: an absent or emptyapi_groupsis treated as unspecified and still matches, so hand-built graphs fromPOST /rbac/combo-scanand unrendered--manifeststemplates don't quietly stop firing.Tests (in
control-plane/tests/test_effective_access.py):secretsgrant sitting in an unrelated API group →privileged_pod_creationno longer firesapi_groupskey → still fires (the regression guard)27 passed locally — the 25 that were already there plus these 2.
Closes #144.