Skip to content

Document and provide sample RBAC for a read-only "DBA" persona #11519

Description

@gbartolini

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/exec and pods/attach: Kubernetes RBAC handles subresources independently, allowing portforward access without granting shell access inside database containers.
  • Write/Update access on postgresql.cnpg.io resources, leases, or configmaps.

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 portforward alone 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

  1. Sample YAML: A new sample manifest (e.g., samples/dba-role.yaml or samples/rbac/dba-persona.yaml) containing a ClusterRole and example RoleBinding.
  2. Documentation Updates: Dedicated guidance in docs/src/security.md (and/or relevant RBAC sections) explaining how to configure non-admin human access safely.

Activity

  1. added this to the 1.31.0 milestone on Sep 21, 2026
  2. added theissue type on Sep 21, 2026
  3. added
    documentation 📖
    on Sep 21, 2026
  4. smiyc commented on Sep 23, 2026

    @smiyc
    Contributor

    I was also thinking of an rbac for every day usage.
    My use case was not being able to delete resources, but

    • kubectl-cnpg psql
    • kubectl-cnpg backup
    • kubectl-cnpg logs
    • kubectl-cnpg report
    • create a pod shell (I use it to run pg_activity for a quick session overview or df -h)

    Which kubectl-cnpg would work / not work with the proposed rbac?

    +1 for nodes, events and pods

  5. gbartolini commented on Sep 27, 2026

    @gbartolini
    ContributorAuthor

    I forgot VolumeSnapshot objects.

  6. vonpanda commented on Sep 27, 2026

    @vonpanda

    I'd like to work on this after assignment, following the contribution guide.

    For the sample, I would start with a namespace-scoped Role and RoleBinding and enumerate the current CNPG resources plus the Kubernetes resources needed for inspection (pods, services, events, leases, and volumesnapshots). I would keep credential access out of the base role: list/watch on Secrets exposes their contents, and an optional get grant should name only the specific application credential Secret. I would document PostgreSQL authentication separately from Kubernetes RBAC.

    The kubectl-cnpg commands raised above deserve a tested capability table. I would check their actual API calls before saying that psql, logs, or report work with this role; backup and 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.

  7. LaurentP-Pro commented on Sep 30, 2026

    @LaurentP-Pro

    Feedback from running CNPG multi-tenant in a regulated bank.
    cluster-admin isn'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:

    • First-line support / investigation only: get/list on everything except Secrets.
    • Automation: full CRUD on all postgresql.cnpg.io resources, 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-in view ClusterRole, 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 have view simply start seeing Clusters.

    2. Hand-wrote a viewer role
    config/rbac/kustomization.yaml only ships database, publication, and subscription editor/viewer roles. cluster, backup, pooler, and scheduledbackup exist in config/rbac/ but aren't listed, so they never reach the released bundle; imagecatalogs and failoverquorums have 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-manager and aggregated it into admin. This is the ugly one. Our automation needs to patch ImageCatalog objects, 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-in admin. It works, and the real exposure is small (admin already grants Secrets and pods/exec in-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 real imagecatalog-editor-role ships.

    4. Rewrote every ClusterImageCatalog as a namespaced ImageCatalog, and stripped the ValidatingAdmissionPolicy. Both are cluster-scoped, so writing them is out of reach for anyone without ClusterRoleBinding rights.

    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 with objectstores.barmancloud.cnpg.io, with no CNPG-specific binding:

    backups.postgresql.cnpg.io                 [get list watch]
    clusterimagecatalogs.postgresql.cnpg.io    [get list watch]
    clusters.postgresql.cnpg.io                [get list watch]
    databases.postgresql.cnpg.io               [get list watch]
    failoverquorums.postgresql.cnpg.io         [get list watch]
    imagecatalogs.postgresql.cnpg.io           [get list watch]
    poolers.postgresql.cnpg.io                 [get list watch]
    publications.postgresql.cnpg.io            [get list watch]
    scheduledbackups.postgresql.cnpg.io        [get list watch]
    subscriptions.postgresql.cnpg.io           [get list watch]
    

    No secrets, no pods/exec, no pods/portforward. Everything the plugin needs is present: pods, pods/log, jobs.batch, persistentvolumeclaims, events, poddisruptionbudgets.policy with exactly one exception: pods/proxy is 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

    • Opt-in aggregation labels (kustomize component or Helm value, default off) on the viewer and editor roles. Highest-leverage change for us: it makes the read-only persona fall out of stock Kubernetes RBAC instead of needing a bespoke manifest that drifts from view.
    • A complete editor/viewer matrix across every CRD. The automation persona is where privilege pressure actually comes from; a read-only sample alone won't stop people reaching for cluster-admin.
    • Docs separating day-0 install from day-2 operation. As a measure of how tight this gets: we can't run kubectl get clusterrole view on 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 get via resourceNames isn'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 than
    removing it.

    And please make pods/portforward a 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.

  8. gbartolini commented on Oct 17, 2026

    @gbartolini
    ContributorAuthor

    Thanks @LaurentP-Pro for the hints. I have drafted a proposal for this ticket and created a new one for the write permissions (#11685).

  9. 1 remaining item

  10. added a commit that references this issue on Oct 19, 2026
    a17e6dd
  11. added 3 commits that reference this issue on Oct 20, 2026
    1bf258b
    931fff6
    69dab5d
  12. added 2 commits that reference this issue on Oct 23, 2026
    3cf1148
    f2152b7
  13. added a commit that references this issue on Oct 26, 2026
    10bfae1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation 📖

    Type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions