← Back to Pull requests

feat: verify chart RBAC does not drift from config/rbac #372

Open
unknown opened this pull request with 549 lines diff across 6 files
View on GitHub
unknown unknown commented on Aug 07, 2026 19:32 UTC
Author

Description

Follows up on @ajaysundark's question in #351 about whether hack/verify-chart-drift.sh could cover more than CRDs. This extends it to RBAC.

The script previously diffed only the bundled CRD, so nothing caught the chart granting different permissions than the controller declares. #350 was exactly that, and it went unnoticed precisely because nothing compares the two.

RBAC is the case most likely to drift. config/rbac/role.yaml is generated by controller-gen from the kubebuilder markers, so it updates itself whenever the controller's permissions change. The chart's ClusterRole is hand written, so it only updates when someone remembers. Every future permission change is another chance for the chart to fall behind, and the failure is silent apart from whatever the missing grant covered.

A plain diff does not work here. The generated roles carry short names and kustomize labels, the chart templates the name from the release name and adds Helm labels, so the files never match textually even when the permissions are identical. The check therefore renders the chart, matches each Role and ClusterRole by name ignoring the release prefix, and compares only the rules.

Rules are normalised before comparison, sorting the entries within each rule and then the rules themselves, because the order of apiGroups, resources and verbs means nothing to the API server and should not be reported as drift. Without that the check would be noisy enough that people would learn to ignore it.

Output points at the offending permission rather than dumping both role definitions:

RBAC drift between config/rbac and the Helm chart:

ClusterRole "manager-role" has different rules
  only in config: apiGroups=["",events.k8s.io] resources=[events] verbs=[create,patch]
  only in chart:  apiGroups=[""] resources=[events] verbs=[create,patch]

The chart grants different permissions than the controller declares.
Update charts/nrr-controller/templates/rbac.yaml to match config/rbac.

A role the chart renders that has no counterpart in config is reported as a note rather than a failure, since the chart may legitimately ship something kustomize does not.

Merge order. This depends on #351. Run against main as it stands today the check fails, because it correctly finds the missing events.k8s.io grant that #351 fixes. That failure is the proof it works, but it does mean this should land after #351, or CI on main will flag a bug that already has a fix in flight.

Scope. Roles and ClusterRoles only, not bindings, subjects, the Deployment, Services or webhook configuration. I checked all of those by hand while reviewing #351 and they currently agree, so RBAC seemed the right place to start given it is the one that has already bitten us. Easy to extend later if that is wanted.

Related Issue

Fixes #371

Type of Change

/kind feature

Testing

Verified both directions against a real drift rather than a synthetic one.

Against main, where the chart is still missing the events grant, the check fails with the output shown above and exits 1. With #351's template change applied, it passes:

RBAC in the Helm chart matches config/rbac (7 roles compared)

All seven roles are compared: manager-role, leader-election-role, metrics-auth-role, metrics-reader, and the nodereadinessrule admin, editor and viewer roles.

golangci-lint v2.12.1 reports 0 issues across the repo including the new tool, gofmt is clean, and the boilerplate header matches hack/boilerplate/boilerplate.go.txt exactly. bash -n passes on the modified script.

One note on local verification: I could not run the script end to end on Windows, because make manifests fails there with no Go files in E:\... from controller-gen's path handling. That reproduces identically on a clean checkout of main, so it is pre-existing and unrelated to this change. I ran the RBAC section verbatim instead, and CI runs on ubuntu-latest where the CRD step works.

The Helm workflow already sets up Helm, Go and Python before invoking this script, so no workflow change is needed. If helm is missing locally the script now fails with a message pointing at make ensure-helm-install rather than skipping silently.

Checklist


  • make test passes

  • make lint passes
  • Does this PR introduce a user-facing change?

    ``release-note
    NONE
    ``

    Diff: 549 lines (+411 / -138) across 6 files Reviewer: ajaysundark Review duration: 85269m
    All Vouch review confidence checks passed
    Residual risk 0.43 = Change Risk (0.78) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.78 · 549 lines diff across 6 files
    0.78
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.078
    Real PR Conversation Timeline
    1 comments
    "Review active on #372"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 44.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 78.2% (HIGH) · Higher = larger blast radius
    78.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 43.3% · Moderate risk
    43.3%