Repository navigation
feat(roles): introduce roleGrants field with role membership options - #11031
jonasbadstuebner wants to merge 4 commits into
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
marvin-roesch
left a comment
There was a problem hiding this comment.
Some minor code improvements to point out and one larger question about optional field semantics.
| RoleGrants: []DatabaseRoleGrant{ | ||
| { | ||
| Name: "role1", | ||
| Admin: ptr.To(true), |
There was a problem hiding this comment.
Go 1.26 allows new(true), so using the ptr package no longer is required.
There was a problem hiding this comment.
A quick grep says there are over 400 occurrences of ptr.To(...) in the code base and only a handful of new(...).
I wanted to keep the general style of dealing with bool pointers, but if the maintainers agree with you, @marvin-roesch, I can easily replace ptr.To with new for this newly added code.
e67ab79 to
077cc3e
Compare
077cc3e to
69bd3e0
Compare
208102a to
fd986f8
Compare
fd986f8 to
291affd
Compare
Complements the limited `inRoles` string array with a structured `roleGrants` object array in both the DatabaseRole CRD and managed roles definition to support advanced PostgreSQL membership options, `ADMIN`, `INHERIT` and `SET`. **Why this change?** The `inRoles` option only allows basic role membership. `roleGrants` provides precise control for environments requiring specific PostgreSQL role behaviors, allowing explicit toggling of `ADMIN`, `INHERIT`, and `SET` membership options per granted role. Behavior & Compatibility: - `inRoles` stays supported. - If both are provided, `roleGrants` options takes precedence, but new roles are still created with the `IN ROLE` option - If only `roleGrants` is provided, the role is created first without any memberships and the `GRANT` statements with granular options are run right after creation. - Default behavior for `roleGrants` matches PostgreSQL defaults if flags are omitted/only the name is given. **Why not a Grant CRD?** Choosing to embed `roleGrants` into existing definitions rather than building a broad Grant CRD enforces a strict architectural boundary: the CNPG operator manages cluster-level role membership down to the database, while fine-grained permissions of objects inside databases remain the responsibility of application migrations. Related to cloudnative-pg#10007 Signed-off-by: Jonas Badstübner <[email protected]>
It was suggested that because the function is not only looking up _if_ a user has a role membership granted but also checks that it has the correct membership options set, having the function be named hasMatchingRoleGrants seems to more accurately reflect what is happening inside it. cloudnative-pg#11031 (comment) Signed-off-by: Jonas Badstübner <[email protected]>
This commit changes the way the currently configured membership options are read back from the database. Where previously string concatenation was used, json array aggregation is now utilized instead, making a bloated function obsolete and improving readability overall. Signed-off-by: Jonas Badstübner <[email protected]>
This commit adds documentation especially on how the membership options of `RoleGrant`s behave. Signed-off-by: Jonas Badstübner <[email protected]>
|
Thanks for this, @jonasbadstuebner. Embedding I've written up how I think the interface should look in #10007 (comment). It is mostly what you have here, so the points below are about the implementation. There is one blocker and a few smaller items. Scope: In the issue comment, I suggest limiting Blocker: PostgreSQL 14 and 15 We support PostgreSQL 14–18, but this PR assumes PG 16+. I checked the SQL on PostgreSQL 14.24 and 15.19, and the reconciler needs two paths:
Today:
Please:
Validation
Reconciliation semantics
Docs Nothing under
This is my own feedback, and I'd like the other maintainers, who are more aligned with the code than I am, to weigh in as well, particularly on limiting Thanks again, and let me know if any of this is unclear. |
|
Hi @jonasbadstuebner, do you have time to update this PR? If not, some of us may take over the issue and decide whether to use your work as a base or start a new one. Please let us know. Thank you! |
|
Hey @gbartolini, I really like your concept and idea, would implement the feedback as-is, if I had the time. |
|
Closing this PR. |
Complements the limited
inRolesstring array with a structuredroleGrantsobject array in both the DatabaseRole CRD and managed roles definition to support advanced PostgreSQL membership options,ADMIN,INHERITandSET.Why this change?
The
inRolesoption only allows basic role membership.roleGrantsprovides precise control for environments requiring specific PostgreSQL role behaviors, allowing explicit toggling ofADMIN,INHERIT, andSETmembership options per granted role.Behavior & Compatibility:
inRolesstays supported.roleGrantsoptions takes precedence, but new roles are still created with theIN ROLEoptionroleGrantsis provided, the role is created first without any memberships and theGRANTstatements with granular options are run right after creation.roleGrantsmatches PostgreSQL defaults if flags are omitted/only the name is given.Why not a Grant CRD?
Choosing to embed
roleGrantsinto existing definitions rather than building a broad Grant CRD enforces a strict architectural boundary: the CNPG operator manages cluster-level role membership down to the database, while fine-grained permissions of objects inside databases remain the responsibility of application migrations.Closes #10007