Skip to content

docs(rbac): add read-only DBA persona samples and viewer role - #11684

Merged
leonardoce merged 8 commits into
mainfrom
dev/11519
Oct 26, 2026
Merged

leonardoce merged 8 commits into
mainfrom
dev/11519

Conversation

@gbartolini

@gbartolini gbartolini commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Document how to give a human DBA read-only operational access without resorting to cluster-admin, and ship a CloudNativePG-only viewer role.

Add a new manifest, cnpg-viewer-role, a ClusterRole with read-only access to the whole postgresql.cnpg.io group, as well as barmancloud.cnpg.io and klio.cnpg.io API groups (CNPG projects).

Add a few samples in docs/src/samples, each with an example RoleBinding:

  • rbac-dba-viewer.yaml: cnpg-dba-viewer, a self-contained read-only role covering all CloudNativePG resources, the Barman Cloud and Klio plugin resources, and the Kubernetes objects needed to diagnose a Cluster (pods, pod logs, events, services, configmaps, PVCs, jobs, PDBs, StatefulSets, VolumeSnapshots, leases). It also grants get on pods/proxy, which kubectl cnpg status needs. It grants no access to Secrets, pods/exec, pods/attach or pods/portforward.
  • rbac-dba-portforward.yaml: optional, separate role for port-forward.
  • rbac-dba-app-secret.yaml: optional namespaced Role granting get on a single named application Secret.

Add a new rbac.md page ("RBAC for Users") describing the available roles, which kubectl-cnpg commands work with cnpg-dba-viewer (derived from the API calls each command makes), the namespace-wide scope of these roles, the split between Kubernetes RBAC and PostgreSQL authentication, and how to aggregate cnpg-viewer-role into the built-in view role. It is a separate page so that security.md, which already covers the operator's own RBAC, does not grow further; security.md keeps a short pointer and its cross-references are updated.

Closes #11519

Assisted-by: Claude

@gbartolini
gbartolini requested a review from a team as a code owner October 17, 2026 13:50
@gbartolini
gbartolini marked this pull request as draft October 17, 2026 13:50
@gbartolini
gbartolini force-pushed the dev/11519 branch 6 times, most recently from 1aeab8b to 9d7c4d5 Compare October 19, 2026 08:53
@gbartolini
gbartolini marked this pull request as ready for review October 19, 2026 08:53

@valeriodelsarto valeriodelsarto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Gabriele, the split between a standing read-only persona and the opt-in port-forward and Secret roles reads well. I checked the kubectl cnpg table against the plugin code: two rows need fixing, plus a question on Helm installs and a few nits inline.

Comment thread docs/src/rbac.md Resolved
Comment thread docs/src/rbac.md Resolved
Comment thread docs/src/rbac.md Resolved
Comment thread docs/src/rbac.md Resolved
Comment thread docs/src/samples/rbac-dba-viewer.yaml Resolved
Comment thread docs/src/rbac.md Resolved
@gbartolini
gbartolini force-pushed the dev/11519 branch 2 times, most recently from 4efccac to b714f2a Compare October 20, 2026 06:41
gbartolini and others added 8 commits October 26, 2026 09:16
Document how to give a human DBA read-only operational access without resorting to cluster-admin, and ship a CloudNativePG-only viewer role.

Add a new manifest, `cnpg-viewer-role`, a ClusterRole with read-only access to the whole postgresql.cnpg.io group, as well as barmancloud.cnpg.io and klio.cnpg.io API groups (CNPG projects).

Add a few samples in `docs/src/samples`, each with an example RoleBinding:

- rbac-dba-viewer.yaml: cnpg-dba-viewer, a self-contained read-only role covering all CloudNativePG resources, the Barman Cloud and Klio plugin resources, and the Kubernetes objects needed to diagnose a Cluster (pods, pod logs, events, services, configmaps, PVCs, jobs, PDBs, StatefulSets, VolumeSnapshots, leases). It also grants get on pods/proxy, which `kubectl cnpg status` needs. It grants no access to Secrets, pods/exec, pods/attach or pods/portforward.
- rbac-dba-portforward.yaml: optional, separate role for port-forward.
- rbac-dba-app-secret.yaml: optional namespaced Role granting `get` on a single named application Secret.

Add a new `rbac.md` page ("RBAC for Users") describing the available roles, which kubectl-cnpg commands work with cnpg-dba-viewer (derived from the API calls each command makes), the namespace-wide scope of these roles, the split between Kubernetes RBAC and PostgreSQL authentication, and how to aggregate `cnpg-viewer-role` into the built-in `view` role. It is a separate page so that `security.md`, which already covers the operator's own RBAC, does not grow further; `security.md` keeps a short pointer and its cross-references are updated.

Closes #11519

Assisted-by: Claude

Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Valerio Del Sarto <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Valerio Del Sarto <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Valerio Del Sarto <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Valerio Del Sarto <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Valerio Del Sarto <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Helm installs do not get `cnpg-viewer-role`: the chart renders its own
`<release>-view` ClusterRole, aggregated into `view`, `edit` and `admin`
by `rbac.aggregateClusterRoles`. Say so where the roles are introduced
and in the aggregation section.

Assisted-by: Claude

Signed-off-by: Gabriele Bartolini <[email protected]>
`kubectl auth can-i create pods/exec` reads `pods/exec` as the Pod named
`exec`, so it checks `create` on Pods and answers `no` for the wrong
reason: a user allowed to create Pods but not to exec gets `yes`, and a
user allowed to port-forward gets `no` from the same form. Use
`--subresource=exec` and say why.

`kubectl cnpg psql` runs `kubectl exec` without the impersonation flags,
and `kubectl cnpg report --logs` streams logs with a client built from
the plain kubeconfig, so under `--as` both run with the caller's own
identity and succeed even when the role forbids them. Warn against using
them to try a role.

The chart names its view role after its full name, which is
`cnpg-cloudnative-pg-view` for a release named `cnpg`, not
`<release>-view`. Its `rbac.aggregateClusterRoles` value also aggregates
the chart's edit role into `edit` and `admin`, granting write access to
CloudNativePG resources: say so where the value is recommended.

Since #11687, `kubectl cnpg status` reports a missing `pods/exec`
permission instead of failing those parts with an error: update the
command table accordingly.

Signed-off-by: Armando Ruocco <[email protected]>
@leonardoce leonardoce added the do not backport This PR must not be backported - it will be in the next minor release label Oct 26, 2026
@leonardoce

Copy link
Copy Markdown
Contributor

/ok-to-merge no code change

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 26, 2026
@leonardoce
leonardoce merged commit 10bfae1 into main Oct 26, 2026
35 of 37 checks passed
@leonardoce
leonardoce deleted the dev/11519 branch October 26, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release ok to merge 👌 This PR can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants