Skip to content

fix(roles): revoke every grant of a membership removed from inRoles - #11826

Open
armru wants to merge 1 commit into
mainfrom
dev/role-membership-grantors
Open

armru wants to merge 1 commit into
mainfrom
dev/role-membership-grantors

Conversation

@armru

@armru armru commented Nov 2, 2026

Copy link
Copy Markdown
Member

From PostgreSQL 16 a membership can be granted once per grantor: every role holding the ADMIN option on a role can grant it again, and a REVOKE acts only on the grant of the grantor it names, which for a superuser defaults to the bootstrap superuser. Removing a role from inRoles, or finding a membership the role does not list, therefore revoked only the grant the operator had made, and a membership granted by another role survived with just a warning in the PostgreSQL log, both for inline managed roles and for a DatabaseRole.

The memberships are now read with their grantor, and from PostgreSQL 16 the operator names it through GRANTED BY on each grant it revokes. Before 16 a membership has a single grant, which a superuser REVOKE removes whoever granted it, so the statements there are unchanged: on 14.24 and 15.19 the plain REVOKE leaves no row, while on 16.15 it leaves the grant of the other role. The major version comes from a getPostgresMajorVersion function set on RoleSynchronizer and DatabaseRoleReconciler when they are built, as SubscriptionReconciler already does.

A revoke can now fail with dependent privileges exist when the member used its ADMIN option to grant the role to others, where before the membership was silently left in place.

The managed roles e2e test gains a step, from PostgreSQL 16, where another role grants pg_monitor to a managed role, first alone and then next to the grant of the operator. On kind with PostgreSQL 18.6 the step fails on main at the first case, where the membership survives, and passes with this change, which revokes every grant in both cases.

This leaves alone the status counting a membership once per grant, #11624, which #11686 fixes.

Closes #11825

@armru
armru requested review from a team, NiccoloFei and litaocdl as code owners November 2, 2026 15:41
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

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

@armru

armru commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

I had a look at the PR and I think we need to analyze carefully the consequences of this patch.

Today, when a role is removed from inRoles, the operator runs a plain REVOKE, which removes only the grant made by the bootstrap superuser. Grants made by other roles survive with just a warning in the PostgreSQL log. In this PR we read the grantor and issues REVOKE ... GRANTED BY <grantor> for every grant, so all of them are removed.

Both behaviors are right and wrong, for different reasons:

Current behavior respects PG's ownership model, because the operator never removes what it didn't grant. But inRoles stops being the source of truth: after removing an entry, the role can keep the membership, and the privileges it inherits, through another role's grant.

Behavior after this PR guarantees that the declared state matches the catalog, which is what pre-16 versions did. But it overrides other grantors' decisions, even though the operator can now tell its own grants apart. On upgrade it will remove existing grants made out of band, and a revoke can now fail with dependent privileges exist.

Open questions before merging: which semantics the operator promises, whether to revoke only its own grants and report the rest (status or event), whether this should be opt-in, and how to handle dependent grants (RESTRICT vs CASCADE). Whatever we choose, we need to document it and call out the upgrade impact.

From PostgreSQL 16 a membership can be granted once per grantor: every
role holding the `ADMIN` option on a role can grant it again, and a
`REVOKE` acts only on the grant of the grantor it names, which for a
superuser defaults to the bootstrap superuser. Removing a role from
`inRoles` therefore revoked only the grant the operator had made, and a
membership granted by another role survived, both for inline managed
roles and for a `DatabaseRole`.

The memberships are now read with their grantor, and from PostgreSQL 16
the operator names it through `GRANTED BY` on each grant it revokes, so
the role is no longer a member of a role it does not list. Before 16 a
membership has a single grant, which a superuser `REVOKE` removes
whoever granted it, so the statements there are unchanged. A revoke can
now fail with `dependent privileges exist` when the member used its
`ADMIN` option to grant the role to others, where before the membership
was silently left in place.

Closes #11825

Signed-off-by: Armando Ruocco <[email protected]>
@leonardoce
leonardoce force-pushed the dev/role-membership-grantors branch from 20cc41e to 9dbb695 Compare November 10, 2026 17:49
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 release-1.28 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: a membership granted by another role is not revoked when missing from inRoles

3 participants