Repository navigation
Description
CloudNativePG currently provides no documentation or sample manifests for what Kubernetes RBAC a human Database Administrator (DBA) should be granted.
In practice, users who need to inspect cluster state and connect to PostgreSQL (without managing the Kubernetes platform itself) are routinely granted the cluster-admin Role. This happens because cluster-admin is often the only operational RBAC profile users are shown in examples.
cluster-admin grants unrestricted access to every API group across every namespace, which is a wildly disproportionate grant simply to inspect a Cluster status or open a connection to PostgreSQL.
Proposed Solution
Define, sample, and document a distinct "DBA" / Read-Only Operational Persona via Kubernetes RBAC, separate from both platform/cluster administrators and the CloudNativePG operator's own ServiceAccount.
Suggested RBAC Scope
The sample ClusterRole (or Role) should include:
| API Group / Resource | Verbs | Purpose |
|---|---|---|
postgresql.cnpg.io/* (Cluster, Backup, ScheduledBackup, Pooler, etc.) |
get, list, watch |
Read-only visibility into CNPG Custom Resource states |
coordination.k8s.io/leases |
get, list, watch |
Inspect leader election and failover status |
core/configmaps |
get, list, watch |
Inspect cluster configuration state and generated settings |
core/services |
get, list |
Inspect connection endpoints |
core/secrets |
get (Scoped) |
Fetch application-user connection Secrets (never superuser credentials) |
core/pods/portforward |
create |
Establish local tunnels to the database |
Explicitly Excluded:
pods/execandpods/attach: Kubernetes RBAC handles subresources independently, allowingportforwardaccess without granting shell access inside database containers.- Write/Update access on
postgresql.cnpg.ioresources,leases, orconfigmaps.
Call for Community Input and Further Analysis
This proposed list is a starting point. Proper analysis should follow to determine the complete set of resources required for operational diagnosis without over-privileging the user. There could certainly be additional resources needed (such as events, pods read status, or nodes).
We would like to ask the community to provide feedback on:
- Additional Kubernetes resources or subresources necessary for daily DBA operational workflows.
- Whether certain credentials (e.g., specific secret patterns) should be further restricted via RBAC or documentation best practices.
- Any real-world edge cases where
portforwardalone is insufficient for non-operator roles.
Architectural Principle
Kubernetes RBAC should only govern network path access and resource visibility (who can inspect status and open a tunnel). Database authentication, individual roles, client certificates, pg_hba.conf rules, and auditing remain entirely the responsibility of PostgreSQL once connected.
Concrete Deliverables
- Sample YAML: A new sample manifest (e.g.,
samples/dba-role.yamlorsamples/rbac/dba-persona.yaml) containing aClusterRoleand exampleRoleBinding. - Documentation Updates: Dedicated guidance in
docs/src/security.md(and/or relevant RBAC sections) explaining how to configure non-admin human access safely.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
smiyc commentedon Sep 23, 2026
I was also thinking of an rbac for every day usage.
My use case was not being able to delete resources, but
kubectl-cnpg psqlkubectl-cnpg backupkubectl-cnpg logskubectl-cnpg reportpg_activityfor a quick session overview ordf -h)Which kubectl-cnpg would work / not work with the proposed rbac?
+1 for
nodes,eventsandpodsgbartolini commentedon Sep 27, 2026
I forgot
VolumeSnapshotobjects.vonpanda commentedon Sep 27, 2026
I'd like to work on this after assignment, following the contribution guide.
For the sample, I would start with a namespace-scoped
RoleandRoleBindingand enumerate the current CNPG resources plus the Kubernetes resources needed for inspection (pods,services,events,leases, andvolumesnapshots). I would keep credential access out of the base role:list/watchon Secrets exposes their contents, and an optionalgetgrant should name only the specific application credential Secret. I would document PostgreSQL authentication separately from Kubernetes RBAC.The
kubectl-cnpgcommands raised above deserve a tested capability table. I would check their actual API calls before saying thatpsql,logs, orreportwork with this role;backupand a pod shell should not be presented as read-only access. Does this scope fit what you want for the first sample and documentation change? If so, please assign the issue to me.LaurentP-Pro commentedon Sep 30, 2026
Feedback from running CNPG multi-tenant in a regulated bank.
cluster-adminisn't available to our DBAs or our automation: only to our Kubernetes platform team, and only to install/upgrade the operator and the Barman plugin. Here's what we had to build to work around the current RBAC, and what we measured.We needed two personas, neither of which CNPG ships:
get/liston everything except Secrets.postgresql.cnpg.ioresources, nothing else.For manual troubleshooting, we have privileged accounts bound to the admin role of the namespaces we own.
What we did
1. Aggregated CNPG's viewer roles into the built-in
view. The read-only persona we needed is almost exactly Kubernetes' built-inviewClusterRole, which upstream defines as read access to most namespaced objects while deliberately excluding Secrets. It just can't see CRDs. Adding[rbac.authorization.k8s.io/aggregate-to-view:](http://rbac.authorization.k8s.io/aggregate-to-view:) "true"to the viewer roles closes that gap with no new sample role and no per-tenant binding: tenants who already haveviewsimply start seeing Clusters.2. Hand-wrote a viewer role
config/rbac/kustomization.yamlonly shipsdatabase,publication, andsubscriptioneditor/viewer roles.cluster,backup,pooler, andscheduledbackupexist inconfig/rbac/but aren't listed, so they never reach the released bundle;imagecatalogsandfailoverquorumshave none at all. We maintain our own role covering all ten CRDs, updated every time CNPG adds one. That's the step where we need to be super vigilant.3. Added imagecatalog write verbs to
cnpg-managerand aggregated it intoadmin. This is the ugly one. Our automation needs topatchImageCatalogobjects, there's no imagecatalog editor role, and minting a bespoke ClusterRole needs privilege we don't have. So we widen the operator's own role and aggregate it into the built-inadmin. It works, and the real exposure is small (adminalready grants Secrets andpods/execin-namespace), but the shape is wrong: every release that widens operator RBAC silently widens what our namespace admins get, with no review gate. We'd delete it the day a realimagecatalog-editor-roleships.4. Rewrote every
ClusterImageCatalogas a namespacedImageCatalog, and stripped theValidatingAdmissionPolicy. Both are cluster-scoped, so writing them is out of reach for anyone withoutClusterRoleBindingrights.What we measured
For illustration, these are my read-only permissions on a prod cluster with my standard account. The aggregation works: all ten CNPG CRDs appear with
get list watch, along withobjectstores.barmancloud.cnpg.io, with no CNPG-specific binding:No
secrets, nopods/exec, nopods/portforward. Everything the plugin needs is present:pods,pods/log,jobs.batch,persistentvolumeclaims,events,poddisruptionbudgets.policywith exactly one exception:pods/proxyis absent.So the measured gap between a stock
view-derived persona and a fully working CNPG read-only DBA is a single subresource.What would replace all of it
view.cluster-admin.kubectl get clusterrole viewon our own clusters, because reading RBAC definitions is itself cluster-scoped. Guidance that assumes the reader can inspect or mint ClusterRoles doesn't reach the teams that may need it.On Secrets, and on portforward
We grant the read-only persona no Secret access at all. Scoping
getviaresourceNamesisn't maintainable from my standpoint: it can't be templated or label-selected, so with clusters created and destroyed by automation the Role needs reconciling on every lifecycle event, which relocates the privileged action rather thanremoving it.
And please make
pods/portforwarda separate role. For us it isn't grantable as a standing permission: interactive production database access requires an incident ticket or approved change order. Bundled into one role we can't adopt the sample.gbartolini commentedon Oct 17, 2026
Thanks @LaurentP-Pro for the hints. I have drafted a proposal for this ticket and created a new one for the write permissions (#11685).
1 remaining item
docs(rbac): add read-only DBA persona samples and viewer role
docs(rbac): add read-only DBA persona samples and viewer role
fix(plugin): show a clear message for the status size without exec
fix(plugin): handle a missing exec permission in status (#11687)
fix(plugin): handle a missing exec permission in status (#11687)
fix(plugin): handle a missing exec permission in status (#11687)
docs(rbac): add read-only DBA persona samples and viewer role
docs(rbac): add read-only DBA persona samples and viewer role
docs(rbac): add read-only DBA persona samples and viewer role (#11684)