Skip to content

fix(plugin): handle a missing exec permission in status - #11687

Merged
gbartolini merged 6 commits into
mainfrom
dev/status-size-forbidden
Oct 20, 2026
Merged

gbartolini merged 6 commits into
mainfrom
dev/status-size-forbidden

Conversation

@gbartolini

@gbartolini gbartolini commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

kubectl cnpg status runs commands in the primary Pod through exec: du for the cluster size and, with -v -v, cat to read custom.conf and pg_hba.conf. Without the pods/exec permission, it printed raw exec errors, and the configuration sections made the command fail.

Check permissions first with a SelfSubjectAccessReview on the primary Pod, and show not permitted: requires the pods/exec permission in place of the size and configuration sections. If the review itself fails, run the command anyway and report the actual error. When no Pod holds the primary role, as during bootstrap or a failover, skip the check, because the review would have no namespace and be evaluated at cluster scope.

Mark pods/exec as optional for status in the kubectl plugin documentation.

Assisted-by: Claude

References #11519

@gbartolini
gbartolini requested a review from a team as a code owner October 18, 2026 07:28
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@gbartolini gbartolini added this to the 1.31.0 milestone Oct 19, 2026
@gbartolini gbartolini moved this to Waiting for Second Review in CloudNativePG operator development Oct 19, 2026
@mnencia
mnencia force-pushed the dev/status-size-forbidden branch from 38d8aa9 to 0080ac0 Compare October 19, 2026 16:35
@mnencia mnencia changed the title fix(plugin): show a clear message for the status size without exec fix(plugin): show a clear message in status without exec Oct 19, 2026
@mnencia
mnencia force-pushed the dev/status-size-forbidden branch from 0080ac0 to 5c48d75 Compare October 19, 2026 16:37
@mnencia

mnencia commented Oct 19, 2026

Copy link
Copy Markdown
Member

/ok-to-merge tested locally on kind with a read-only user: size and --verbose config show "not permitted" without pods/exec, and work with it. E2E does not cover this path.

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 19, 2026
@mnencia
mnencia force-pushed the dev/status-size-forbidden branch from 5c48d75 to bc7982c Compare October 19, 2026 16:54
gbartolini and others added 6 commits October 20, 2026 08:41
`kubectl cnpg status` computes the cluster size with `du`, which needs
the `pods/exec` permission. Without it, the raw exec error was printed
on the `Size` line. Check the permission first and show that it is not
permitted instead.

Assisted-by: Claude

Relates #11519

Signed-off-by: Gabriele Bartolini <[email protected]>
When no Pod holds the primary role, as during bootstrap or a failover,
the access review had no namespace and was evaluated at cluster scope.
A user allowed to exec only in the Cluster namespace was told that the
`pods/exec` permission was missing.

There is no Pod to run `du` in, so skip the check in that case and
report the size error as before.

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
With `--verbose`, `kubectl cnpg status` reads the PostgreSQL
configuration through exec. Without the `pods/exec` permission it
printed the raw errors and empty sections. Reuse the permission check
and show that it is not permitted.

Signed-off-by: Marco Nenciarini <[email protected]>
@gbartolini
gbartolini force-pushed the dev/status-size-forbidden branch from bc7982c to 6ba68b6 Compare October 20, 2026 06:41
@gbartolini gbartolini changed the title fix(plugin): show a clear message in status without exec fix(plugin): handle a missing exec permission in status Oct 20, 2026
@gbartolini
gbartolini merged commit 69dab5d into main Oct 20, 2026
@gbartolini
gbartolini deleted the dev/status-size-forbidden branch October 20, 2026 06:48
@github-project-automation github-project-automation Bot moved this from Waiting for Second Review to Done in CloudNativePG operator development Oct 20, 2026
mnencia added a commit that referenced this pull request Oct 20, 2026
`kubectl cnpg status` runs commands in the primary Pod through exec:
`du` for the cluster size and, with `-v -v`, `cat` to read `custom.conf`
and `pg_hba.conf`. Without the `pods/exec` permission, it printed raw
exec errors, and the configuration sections made the command fail.

Check permissions first with a `SelfSubjectAccessReview` on the primary
Pod, and show `not permitted: requires the pods/exec permission` in
place of the size and configuration sections. If the review itself
fails, run the command anyway and report the actual error. When no Pod
holds the primary role, as during bootstrap or a failover, skip the
check, because the review would have no namespace and be evaluated at
cluster scope.

Mark `pods/exec` as optional for `status` in the kubectl plugin
documentation.

Assisted-by: Claude

References #11519

Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 69dab5d)
Signed-off-by: Marco Nenciarini <[email protected]>
mnencia added a commit that referenced this pull request Oct 20, 2026
`kubectl cnpg status` runs commands in the primary Pod through exec:
`du` for the cluster size and, with `-v -v`, `cat` to read `custom.conf`
and `pg_hba.conf`. Without the `pods/exec` permission, it printed raw
exec errors, and the configuration sections made the command fail.

Check permissions first with a `SelfSubjectAccessReview` on the primary
Pod, and show `not permitted: requires the pods/exec permission` in
place of the size and configuration sections. If the review itself
fails, run the command anyway and report the actual error. When no Pod
holds the primary role, as during bootstrap or a failover, skip the
check, because the review would have no namespace and be evaluated at
cluster scope.

Mark `pods/exec` as optional for `status` in the kubectl plugin
documentation.

Assisted-by: Claude

References #11519

Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 69dab5d)
Signed-off-by: Marco Nenciarini <[email protected]>
leonardoce pushed a commit that referenced this pull request Oct 23, 2026
`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 pushed a commit that referenced this pull request Oct 26, 2026
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases no-issue ok to merge 👌 This PR can be merged release-1.28 release-1.30

Development

Successfully merging this pull request may close these issues.

4 participants