feat(postgresql): support WITH INHERIT FALSE on role membership grants (PostgreSQL 16+)#361
Conversation
Signed-off-by: Matthew Greenwald <matthew.greenwald@agilityrobotics.com>
Signed-off-by: Matthew Greenwald <matthew.greenwald@agilityrobotics.com>
Signed-off-by: Matthew Greenwald <matthew.greenwald@agilityrobotics.com>
|
@Duologic @jdotw @jvrplmlmn @iainlane Can I get a review on this please? Or at least trigger CI? |
| // WithInherit controls whether the grantee automatically inherits the privileges | ||
| // of the granted role. When set to false, emits WITH INHERIT FALSE (PostgreSQL 16+), | ||
| // granting membership without automatic privilege inheritance. Only valid when | ||
| // memberOf is set. When omitted, PostgreSQL's default behavior (inherit true) applies. |
There was a problem hiding this comment.
When omitted the field is not managed, i.e. if we set it as false, and then remove it, it doesn't become true, we just ignore it? OK but documentation could reflect that?
| @@ -156,6 +156,13 @@ type GrantParameters struct { | |||
| // RevokePublicOnDb apply the statement "REVOKE ALL ON DATABASE %s FROM PUBLIC" to make database unreachable from public | |||
| // +optional | |||
| RevokePublicOnDb *bool `json:"revokePublicOnDb,omitempty" default:"false"` | |||
There was a problem hiding this comment.
also update the same file in namedspaced/
| return roleMember, nil | ||
| } | ||
|
|
||
| if gp.WithInherit != nil { |
There was a problem hiding this comment.
this should also be checked with a CEL expression
| ao, | ||
| } | ||
|
|
||
| if gp.WithInherit != nil { |
There was a problem hiding this comment.
like with the types, we must also have the same code in pkg/controller/namespaced/
| - **MySQL**: `Database`, `Grant`, `User` (See [the examples](examples/mysql)) | ||
| - **PostgreSQL**: `Database`, `Grant`, `DefaultPrivileges`, `Extension`, `Role` (See [the examples](examples/postgresql)) | ||
| - **MSSQL**: `Database`, `Grant`, `User` (See [the examples](examples/mssql)) | ||
| - **MySQL**: `Database`, `Grant`, `User` (See [the examples](examples/cluster/mysql)) |
There was a problem hiding this comment.
Could you do this and Makefile in another PR?
There was a problem hiding this comment.
Makefile changes are in master now, FYI
chlunde
left a comment
There was a problem hiding this comment.
@matthewgreenwaldagility thanks for your contribution, please take a look at the comments!
|
@matthewgreenwaldagility could you rebase or merge master into this? |
Closes #359
What this does
Adds a
withInheritboolean field tospec.forProvideron the PostgreSQLGrantresource, enablingWITH INHERIT FALSEon role membership grants — a feature introduced in PostgreSQL 16.When
withInheritis omitted, behaviour is unchanged. When combined withwithOption: ADMIN, the emitted SQL isWITH ADMIN OPTION, INHERIT FALSE.The field is only valid on
memberOfgrants — setting it on a privilege grant (privilegesfield) returns a validation error.Motivation
The primary use case is RDS PostgreSQL with IAM database authentication. Without this field, granting a master user membership in an
adminrole that holdsrds_iamcreates a transitive chain (master_user → admin → rds_iam), which causes RDS to route all connections for that user through PAM/IAM token verification, breaking password authentication.WITH INHERIT FALSEgrants membership (satisfyingALTER DEFAULT PRIVILEGES FOR ROLE admin) without inheritingrds_iam.Changes
apis/cluster/postgresql/v1alpha1/grant_types.goWithInherit *boolfield toGrantParametersapis/cluster/postgresql/v1alpha1/zz_generated.deepcopy.gopackage/crds/postgresql.sql.crossplane.io_grants.yamlpkg/controller/cluster/postgresql/grant/reconciler.gomembershipWithClauseshelper;selectGrantQueryfilterspg_auth_members.inherit_optionwhen set;createGrantQueriesuses new helper; validation rejectswithInheriton privilege grantspkg/controller/cluster/postgresql/grant/reconciler_test.goWithInheritnil/true/false for bothObserveandCreateexamples/cluster/postgresql/grant-with-inherit-false.yamlMakefileGOLANGCILINT_VERSIONfrom2.1.2→2.10.1to match CI and support Go 1.26README.mdSchemato PostgreSQL resource list, fix example pathsTesting
make reviewablepasses (generate + lint + all 26 test packages).The
inherit_optioncolumn onpg_auth_memberswas added in PostgreSQL 16. SettingwithInheriton an older cluster will result in a SQL error, which is the expected and documented behaviour.