Repository navigation
Conversation
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
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]>
When updating an existing role, the `DatabaseRole` reconciler granted and revoked its memberships before running `ALTER ROLE`. From PostgreSQL 16 a membership granted without an `inherit` option takes it from the `inherit` attribute the role has at that moment, so a membership added in the same change that turned the attribute off was granted with `inherit_option` set, and the role kept inheriting the privileges of that role. Memberships are now applied after the attributes and the comment. Closes #11824 Signed-off-by: Armando Ruocco <[email protected]>
A `DatabaseRole` could only list the roles it is a member of through
`inRoles`, which grants each membership with the PostgreSQL defaults.
This adds `roleGrants`, one entry per membership with the `admin`,
`inherit` and `set` options of the `GRANT` that makes it:
```yaml
inRoles:
- pg_read_all_data
roleGrants:
- name: app
inherit: false
- name: pg_monitor
admin: true
```
An entry carrying only a `name` is the same as an `inRoles` item, and an
option left out is not managed: PostgreSQL applies its default when the
membership is granted, and the operator leaves it alone afterwards. The
field exists only on `DatabaseRole`, which reports a failure on the
object that caused it, while inline managed roles keep `inRoles`.
The options of each grant are read from `pg_auth_members`, where
`inherit_option` and `set_option` exist only from PostgreSQL 16, so the
columns are chosen from the major version of the instance. The admin
option is granted with `WITH ADMIN OPTION` and removed with `REVOKE ADMIN
OPTION FOR`, which every supported version accepts and which, from
PostgreSQL 16, refuses to drop an option other grants depend on, where
`WITH ADMIN FALSE` drops it anyway. `inherit` and `set` need PostgreSQL
16, and on an older server the `DatabaseRole` is reported as not applied
rather than having them ignored.
From PostgreSQL 16 a membership can be granted once per grantor, each
grant with its own options. The declared options are set on every grant
of the membership, naming its grantor through `GRANTED BY`, since any of
them can give the member what the spec denies.
A repeated `roleGrants` entry is rejected by the API server. A role
listed in both `inRoles` and `roleGrants` fails the reconciliation
instead, since a CEL rule comparing the two lists exceeds the cost
budget of the CRD while `inRoles` is unbounded.
Closes #10007
Signed-off-by: Armando Ruocco <[email protected]>
Member
Author
|
/test |
Contributor
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/41474464342 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
DatabaseRolecould only list the roles it is a member of throughinRoles, which grants each membership with the PostgreSQL defaults, leaving any other option to a manualGRANTthe operator would not track. This addsroleGrants, one entry per membership with theadmin,inheritandsetoptions of theGRANTthat makes it, following the interface proposed in #10007 (comment):An entry carrying only a
nameis the same as aninRolesitem, and an option left out is not managed: PostgreSQL applies its default when the membership is granted, and the operator leaves it alone afterwards. The two lists declare the whole membership set of the role, so removing an entry revokes the membership. The field exists only onDatabaseRole, which reports a failure on the object that caused it, while inline managed roles keepinRoles. This supersedes #11031, whose author no longer has time to carry it on: it is a new implementation rather than a continuation, since that PR put the field in theRoleConfigurationshared with theCluster, and readinherit_optionandset_optionon every role reconciliation, which fails on PostgreSQL 14 and 15.Two points depart from the SQL in the issue, both measured on PostgreSQL 14.24, 15.19, 16.15, 17.11, 18.6 and 19rc1.
inherit_optionandset_optionexist inpg_auth_membersonly from 16, so the columns the memberships are read with are chosen from the major version of the instance, which the reconcilers get from the same function #11826 added forGRANTED BY. The admin option is granted withWITH ADMIN OPTIONand removed withREVOKE ADMIN OPTION FORon every version: from 16 theREVOKEfails withdependent privileges existwhen the member used the option to grant the role to others, whereWITH ADMIN FALSEdrops the option anyway. The version also rejectsinheritandseton 14 and 15, which is reported in the status of theDatabaseRolebefore any statement runs, rather than ignoring options whose absence changes what the member can do.From PostgreSQL 16 a membership can be granted once per grantor, each grant with its own options. The declared options are set on every grant of the membership, naming its grantor through
GRANTED BY, since any of them can give the member what the spec denies: a membership granted by a role holding theadminoption, as in the issue, would otherwise keep letting the member inherit when the spec saysinherit: false.A repeated
roleGrantsentry is rejected by the API server throughlistType=map. A role listed in bothinRolesandroleGrantsfails the reconciliation instead: the CEL rule comparing the two lists exceeds the cost budget of the CRD, by 6.7 times even withmaxItems: 64onroleGrants, becauseinRolesis unbounded.This builds on #11826 and #11827, and includes their commits until they are merged: only the last commit belongs to this PR.
Closes #10007