Repository navigation
Open
Labels
Description
Problem
The operator''s ClusterRole (rendered by operator/documentdb-helm-chart/templates/05_clusterrole.yaml) has been hand-maintained and has drifted significantly from what make manifests would generate from +kubebuilder:rbac markers.
Concretely:
- Only 4 files in
operator/src/internal/carry+kubebuilder:rbacmarkers:certificate_controller.godocumentdb_controller.gopv_controller.go- (partial coverage)
- These files have zero RBAC markers despite making
client.*calls:backup_controller.goscheduledbackup_controller.gophysical_replication.gointernal/utils/util.gointernal/utils/replication_context.gointernal/cnpg/cnpg_sync.go
- As a result,
make manifestsregeneratesoperator/src/config/rbac/role.yamlwith only a small subset of the permissions the operator actually needs (documentdb.io CRDs, cert-manager objects, PVC/PV/StorageClass, plus events). Everything else (postgresql.cnpg.io, snapshot.storage.k8s.io, fleet, services, secrets, configmaps, serviceaccounts, namespaced RBAC, leader-election leases, backup/scheduledbackup CRs) is missing. - The Helm chart''s ClusterRole has therefore been edited by hand to fill the gap. PR chore(helm): trim over-broad ClusterRole permissions #386 cleans up the worst dead grants that hand-editing accumulated, but the underlying drift remains.
Why this matters for GA
- We cannot rely on
make manifestsas a source of truth for RBAC reviews. - New controllers / new client calls require remembering to update the chart''s ClusterRole by hand. Easy to miss; easy to over-grant defensively.
- Reviewers cannot cheaply verify "this PR''s code matches its RBAC delta" they have to grep the codebase by hand (as chore(helm): trim over-broad ClusterRole permissions #386 had to).
Proposed fix
- Add a complete set of
+kubebuilder:rbacmarkers to each controller / utility function that makes Kubernetes API calls. Markers should be co-located with the call site (typically on theReconcilemethod, or at file top for cross-cutting utilities). - Run
make manifestsand commit the regeneratedoperator/src/config/rbac/role.yaml. - Switch the chart''s
templates/05_clusterrole.yamlto render from (or be asserted equal to) the generatedrole.yaml. Options:
a. Replace the hand-written chart template with a generated one (chart copiesrole.yamlat build time).
b. Add a CI check that diffs the chart''s rendered ClusterRole againstmake manifestsoutput and fails on drift. - Add a
maketarget (e.g.make verify-rbac) wired into CI so any future RBAC drift fails the build.
Acceptance criteria
make manifestson a fresh checkout produces arole.yamlthat, when applied, allows every controller path to run successfully against a kind cluster (verified by E2E test suite passing with noforbiddenerrors in operator logs).- A CI check rejects any PR that introduces a
client.*call without a corresponding+kubebuilder:rbacmarker, OR any PR that changes the chart''s ClusterRole without a matching marker change. - The chart''s ClusterRole template either is generated, or contains a comment pointing reviewers at the
make verify-rbactarget.
Related
- Helm chart improvements for GA readiness #381 (chart GA audit)
- chore(helm): trim over-broad ClusterRole permissions #386 (immediate dead-grant trim; doesn''t address marker drift)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity