Skip to content

feat(postgresql): support WITH INHERIT FALSE on role membership grants (PostgreSQL 16+)#361

Open
matthewgreenwaldagility wants to merge 4 commits into
crossplane-contrib:masterfrom
matthewgreenwaldagility:feat/psql-inheritance
Open

feat(postgresql): support WITH INHERIT FALSE on role membership grants (PostgreSQL 16+)#361
matthewgreenwaldagility wants to merge 4 commits into
crossplane-contrib:masterfrom
matthewgreenwaldagility:feat/psql-inheritance

Conversation

@matthewgreenwaldagility
Copy link
Copy Markdown

Closes #359

What this does

Adds a withInherit boolean field to spec.forProvider on the PostgreSQL Grant resource, enabling WITH INHERIT FALSE on role membership grants — a feature introduced in PostgreSQL 16.

apiVersion: postgresql.sql.crossplane.io/v1alpha1
kind: Grant
spec:
  forProvider:
    withInherit: false   # emits: GRANT admin TO master_user WITH INHERIT FALSE
    roleRef:
      name: master-user
    memberOfRef:
      name: admin-role

When withInherit is omitted, behaviour is unchanged. When combined with withOption: ADMIN, the emitted SQL is WITH ADMIN OPTION, INHERIT FALSE.

The field is only valid on memberOf grants — setting it on a privilege grant (privileges field) 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 admin role that holds rds_iam creates 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 FALSE grants membership (satisfying ALTER DEFAULT PRIVILEGES FOR ROLE admin) without inheriting rds_iam.

Changes

File Change
apis/cluster/postgresql/v1alpha1/grant_types.go Add WithInherit *bool field to GrantParameters
apis/cluster/postgresql/v1alpha1/zz_generated.deepcopy.go Regenerated
package/crds/postgresql.sql.crossplane.io_grants.yaml Regenerated — CRD schema updated
pkg/controller/cluster/postgresql/grant/reconciler.go New membershipWithClauses helper; selectGrantQuery filters pg_auth_members.inherit_option when set; createGrantQueries uses new helper; validation rejects withInherit on privilege grants
pkg/controller/cluster/postgresql/grant/reconciler_test.go 7 new test cases covering WithInherit nil/true/false for both Observe and Create
examples/cluster/postgresql/grant-with-inherit-false.yaml New example illustrating the RDS IAM pattern
Makefile Bump GOLANGCILINT_VERSION from 2.1.22.10.1 to match CI and support Go 1.26
README.md Fix stale Go version (1.18→1.26.1), add mise recommendation, fix copy-paste "Developing locally" section (was provider-helm content), add Schema to PostgreSQL resource list, fix example paths

Testing

make reviewable passes (generate + lint + all 26 test packages).

The inherit_option column on pg_auth_members was added in PostgreSQL 16. Setting withInherit on an older cluster will result in a SQL error, which is the expected and documented behaviour.

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>
@matthewgreenwaldagility
Copy link
Copy Markdown
Author

@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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also update the same file in namedspaced/

return roleMember, nil
}

if gp.WithInherit != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be checked with a CEL expression

ao,
}

if gp.WithInherit != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like with the types, we must also have the same code in pkg/controller/namespaced/

Comment thread README.md
- **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))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do this and Makefile in another PR?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile changes are in master now, FYI

Copy link
Copy Markdown
Collaborator

@chlunde chlunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewgreenwaldagility thanks for your contribution, please take a look at the comments!

@chlunde
Copy link
Copy Markdown
Collaborator

chlunde commented May 15, 2026

@matthewgreenwaldagility could you rebase or merge master into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(postgresql): support WITH INHERIT FALSE on role membership grants (PostgreSQL 16+)

2 participants