Repository navigation
feat(rbac): segmentation-violation rule — namespaced identity reaching cluster scope (closes #49) - #52
Conversation
|
Fixing those issue. |
0c1a733 to
03f864d
Compare
rrskris
left a comment
There was a problem hiding this comment.
Really strong first contribution, @Maqbool61 — thank you for picking up the segmentation rule from the Zero-Trust design (#49). The rule logic is right (both the cluster-scope and cross-namespace cases), it reuses the pure-function core cleanly, emits the existing finding shape so scoring/remediation/SARIF/PolicyReport all just work, and the test coverage is genuinely thorough — positive, negative, remediation, and the stacking case. That's exactly the pattern.
Four things to fix before I can merge — the first is the important one:
1. Benchmark citations must be real (blocking). This is a hard rule for us because Kaaval is a compliance tool — a wrong or invented citation is worse than none (an auditor may act on it). Two problems in remediation.py:
CIS 5.1.5is a mismatch. CIS Kubernetes 5.1.5 is "ensure default service accounts are not actively used" — it's about default SAs, not segmentation/cross-namespace reach. It doesn't cover this rule.NIST SP 800-207AMS-3is invented. 800-207A doesn't use aMS-ncontrol-numbering scheme — that identifier doesn't exist in the document.
There is no direct CIS 5.1 control for segmentation (same situation as our exec_attach_grant rule, which cites RBAC Good Practices + OWASP K03 with no CIS ID). Please do the same here: drop the CIS 5.1.5 and the MS-3 entries, and cite NIST SP 800-207A by name with id: null (it's the right primary reference — just no fake control number) plus the Kubernetes RBAC Good Practices namespace-isolation guidance (the entry you already have is perfect). Look at how exec_attach_grant is cited in the same file for the shape.
2. Add a fixture. A new rule needs a case in hack/dev/rbac-fixtures.yaml (a namespaced ServiceAccount bound cluster-wide) so the rule fires in the live testbed too, not only in unit tests.
3. Add a docs/rbac-rules.md row. Every rule is documented in the catalog with its trigger, severity, and mapping — please add the row (this is also where point 4 gets addressed).
4. Let's talk about noise (not a hard block, but important). As written, the rule flags every namespaced ServiceAccount bound via ClusterRoleBinding as HIGH. That's a very common, often-legitimate pattern — monitoring agents (Prometheus), ingress controllers, cert-manager, etc. all bind a namespaced SA cluster-wide by design. Firing HIGH on all of them risks the alert-fatigue we explicitly exist to avoid. A couple of options to consider: keep it but document it in rbac-rules.md as "expected on cluster-agent SAs" (like we do for the kind local-path-provisioner cases), or lower the base severity and let the Contextual Risk Score lift the ones that matter, or scope the rule to when the bound ClusterRole is itself broad. I'd love your take — reply here and we'll settle it together; it may be worth a quick note on #49.
Also: your commits need DCO sign-off (git rebase --signoff main then force-push) — CI's DCO check is currently red on that. And two files lost their trailing newline (rbac_service.py, remediation.py) — please restore them.
None of this is a knock — it's a real rule that needed exactly this kind of review. Take your time; ping me here if any of it is unclear. 🙏
| {"benchmark": CIS_BENCHMARK, "id": "5.1.5", | ||
| "title": "Ensure that default service accounts are not bound to active service account roles"}, | ||
| {"benchmark": "NIST SP 800-207A", "id": "MS-3", | ||
| "title": "Enforce namespace isolation — identities should not cross namespace boundaries"}, |
There was a problem hiding this comment.
NIST SP 800-207A has no MS-3 control — this identifier is invented, and CIS 5.1.5 (line 62) is about default service accounts, not segmentation. Please drop both and cite NIST 800-207A with id: null + the Kubernetes RBAC Good Practices entry you already have (mirror how exec_attach_grant is cited above — no CIS ID, primary sources only). A wrong compliance citation in a compliance tool is worse than none.
…eaching cluster scope (closes kaaval#49) Signed-off-by: Maqbool Ahmed <[email protected]>
…aval#52) 1. Fix benchmark citations in remediation.py - Drop CIS 5.1.5 (covers default SA token automount, not segmentation) - Drop NIST SP 800-207A MS-3 (invented control number — 800-207A has no MS-n numbering scheme) - Replace with: NIST SP 800-207A (id: null) + Kubernetes RBAC Good Practices, mirroring the exec_attach_grant pattern 2. Add rbac-fixtures.yaml entry (kaaval#12 cross-ns-reader) A namespaced ServiceAccount (monitoring/prometheus-sa) bound cluster-wide via ClusterRoleBinding so the live testbed can verify the rule fires. 3. Add docs/rbac-rules.md row for segmentation_violation Trigger, base severity (HIGH), and benchmark mapping. Includes a note on the expected cluster-agent SA pattern (Prometheus, ingress-controller, cert-manager) and guidance to use Contextual Risk Score rather than suppression for confirmed-intentional findings. Signed-off-by: Maqbool Ahmed <[email protected]>
03f864d to
faa906f
Compare
All four points addressed in the latest commit:
|
rrskris
left a comment
There was a problem hiding this comment.
Everything's addressed, and verified against the files — the citations are honest now (NIST 800-207A + RBAC Good Practices, no invented IDs), the fixture and docs row are in, DCO's signed, CI's green. Really nice follow-through across two rounds, @Maqbool61. 🎉 Your call to keep HIGH and document the expected cluster-agent pattern (Prometheus/ingress/cert-manager) is consistent with how we already handle local-path-provisioner, so I'm good with it — if real-cluster usage shows it's too noisy we can revisit severity on #49. Merging. Thank you for the careful work!
#119) The token_automount rule added in #108 reads ServiceAccount automount settings and pod specs. Both fetches are wrapped in their own try/except, so a scanner without those permissions logs a warning and silently returns no automount findings — meaning the rule shipped dark for anyone following the documented in-cluster deployment. Adds read-only get/list on core serviceaccounts and pods to both the kaaval-scanner-reader ClusterRole in deploy/cronjob.yaml and the documented kaaval-scanner role in docs/ci-integration.md. Also corrects a stale claim next to that role. The docs asserted Kaaval "would not flag it"; scanning deploy/cronjob.yaml shows it does, and has since the segmentation_violation rule landed in #52 — a namespaced ServiceAccount granted cluster scope via ClusterRoleBinding is exactly what that rule looks for. Verified the two added grants introduce no new findings (3 before, 3 after), so the least-privilege story holds; the parenthetical was simply wrong. Replaced it with the actual result and why it is expected. Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>
What this implements
Adds a new RBAC rule (
segmentation_violation) that flags identities breaking Kubernetes micro-segmentation — a namespaced ServiceAccount granted cluster-wide or cross-namespace reach. Implements the predicate described in issue #49 and satisfies the NIST SP 800-207A micro-segmentation tenet.Problem
The existing 11 RBAC rules catch permission-content risks (wildcards, secrets access, exec grants, etc.) but none of them check whether the identity itself is scoped correctly. A ServiceAccount that lives in
team-abut is bound cluster-wide via aClusterRoleBinding— even to a narrow, low-risk role — violates namespace isolation regardless of what permissions that role grants. The namespace boundary is the fundamental unit of multi-tenancy in Kubernetes; crossing it is a segmentation failure, not just a permission failure.Two patterns were undetected:
ServiceAccountbound at cluster scope viaClusterRoleBinding— the account reaches every namespace in the clusterRoleBindingin namespace A that grants aServiceAccountwhose home namespace is B — lateral cross-namespace reach, a micro-segmentation violation even when the role is narrowHow it works
control-plane/app/rbac_service.pyTwo new helpers and a predicate added:
_subject_namespace(subject)— extracts the namespace from aServiceAccountsubject, returnsNoneforUser/Groupkinds (which are not namespace-scoped)._is_segmentation_violation(binding, role_kind)— checks both patterns in order:ClusterRoleBindingwhose subjects include anyServiceAccountwith a non-None namespace → that account has been lifted from its namespace to cluster scopeRoleBindingin namespace A that grants access to aServiceAccountfrom namespace B (where A ≠ B) and the bound role is aClusterRole→ cross-namespace lateral reachReturns a human-readable description string when a violation is found, or
Nonewhen clean.The check is wired into
evaluate_rbac_findings()right after the existingcluster_admin_bindingcheck. It stacks on top of other risks — a wildcardClusterRolebound to a namespacedServiceAccountproduces bothwildcard_permissionsANDsegmentation_violationfindings, since they represent two distinct problems (bad permissions + bad scoping). Severity isHIGH— cluster-scope reach is serious but notCRITICALunless combined with cluster-admin-equivalent permissions (which the existingcluster_admin_bindingrule already covers separately).control-plane/app/remediation.pyAdded
segmentation_violationto both lookup tables:_CIS_REFS: CIS Kubernetes Benchmark v1.12.0 §5.1.5, NIST SP 800-207A MS-3, and the Kubernetes RBAC Good Practices doc_RBAC_ACTIONS: action template that tells the operator to replace theClusterRoleBindingwith a namespace-scopedRoleBindingand includes the exactkubectl deletecommand for the bindingTests
control-plane/tests/test_rbac_service.py— 6 new tests + 1 updated pre-existing test:test_namespaced_sa_cluster_role_binding_is_segmentation_violationsegmentation_violationfires, severity HIGH, description names the namespacetest_cluster_sa_cluster_role_binding_is_not_segmentation_violationtest_cross_namespace_role_binding_is_segmentation_violationteam-bgranting SA fromteam-a→ fires, both namespace names appear in descriptiontest_same_namespace_role_binding_is_not_segmentation_violationteam-agranting SA fromteam-a→ contained, does not firetest_segmentation_violation_carries_remediationaction,why_it_matters, and populatedbenchmark_refstest_segmentation_violation_stacks_with_other_riskswildcard_permissionsANDsegmentation_violationpresenttest_readonly_narrow_role_produces_no_rbac_risk_findings(updated)_single_rule_graphwhich binds via ClusterRoleBinding with a namespaced SA — now correctly expectssegmentation_violationto fire, and asserts no content-risk findings appear (the original intent)35 tests pass (26 RBAC + 9 remediation), 0 failed.
Acceptance criteria from issue #49
_is_segmentation_violation()inrbac_service.pyrule_type / severity / detail / remediationshape as all other rules_CIS_REFS+_RBAC_ACTIONSentries inremediation.pybenchmark_refsas MS-3