Skip to content

feat(pgsql): extend Grant kind specification with schema, tables, columns, sequences, routines, foreign data wrappers, foreign servers#345

Merged
fernandezcuesta merged 38 commits into
masterfrom
follow-up-235
May 15, 2026
Merged

feat(pgsql): extend Grant kind specification with schema, tables, columns, sequences, routines, foreign data wrappers, foreign servers#345
fernandezcuesta merged 38 commits into
masterfrom
follow-up-235

Conversation

@fernandezcuesta
Copy link
Copy Markdown
Collaborator

@fernandezcuesta fernandezcuesta commented Mar 18, 2026

Description of your changes

This is a follow up of #235 with some minor issues found while merging from master.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Added tests

Bastichou and others added 14 commits May 14, 2025 15:46
Signed-off-by: Bastien CERIANI <bastien.ceriani@gmail.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Julien Christophe <julien.christophe@datanumia.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Quote multiple parameters in GRANT/REVOKE statements to prevent SQL injection.
Qualify aclexplode ACL column references with their table aliases
(n.nspacl, db.datacl) for consistency.
Error instead of panic for Observe, Create, and Delete.
Add tests to assert generated SQL strings directly.

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Comment thread apis/namespaced/postgresql/v1alpha1/database_types.go Outdated
@baburciu
Copy link
Copy Markdown
Contributor

hey @fernandezcuesta, I think another issue stemming from the rebase and Crossplane v2 adjustment may be the fact that cluster variant of Grant reconciler is able to use the Database.spec.forProvider.database and only default to ProviderConfig.spec.defaultDatabase if not specified, here, but the namespaced variant is not, as it directly uses ProviderConfig's DefaultDatabase here.
For me I could only get

 apiVersion: postgresql.sql.crossplane.io/v1alpha1
  kind: Grant
  metadata:
    name: demo-application-staging-user-1
  spec:
    deletionPolicy: Delete
    forProvider:
      database: demo-application-staging-dedicated
      databaseRef:
        name: demo-application-staging-dedicated
      privileges:
        - SELECT
      role: demo-application-staging-user
      roleRef:
        name: demo-application-staging-user
      schema: public
      tables:
        - deployments
    managementPolicies:
      - '*'
    providerConfigRef:
      name: demo-application-staging-user-db-connection

to apply after adding the same behaviour to namespaced reconciler (this PR with these 2 commits)

demo-application-staging-dedicated=> SELECT table_schema, table_name, privilege_type
  FROM information_schema.table_privileges
  WHERE grantee = 'demo-application-staging-user';
 table_schema | table_name  | privilege_type
--------------+-------------+----------------
 public       | deployments | SELECT
(1 row)

demo-application-staging-dedicated=>

baburciu and others added 4 commits March 19, 2026 01:24
…cific database — tables, schemas, sequences, columns, routines, fallback to provider config one's otherwise

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
…espaced

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
@fernandezcuesta
Copy link
Copy Markdown
Collaborator Author

hey @fernandezcuesta, I think another issue stemming from the rebase and Crossplane v2 adjustment may be the fact that cluster variant of Grant reconciler is able to use the Database.spec.forProvider.database and only default to ProviderConfig.spec.defaultDatabase if not specified, here, but the namespaced variant is not, as it directly uses ProviderConfig's DefaultDatabase here. For me I could only get

 apiVersion: postgresql.sql.crossplane.io/v1alpha1
  kind: Grant
  metadata:
    name: demo-application-staging-user-1
  spec:
    deletionPolicy: Delete
    forProvider:
      database: demo-application-staging-dedicated
      databaseRef:
        name: demo-application-staging-dedicated
      privileges:
        - SELECT
      role: demo-application-staging-user
      roleRef:
        name: demo-application-staging-user
      schema: public
      tables:
        - deployments
    managementPolicies:
      - '*'
    providerConfigRef:
      name: demo-application-staging-user-db-connection

to apply after adding the same behaviour to namespaced reconciler (this PR with these 2 commits)

demo-application-staging-dedicated=> SELECT table_schema, table_name, privilege_type
  FROM information_schema.table_privileges
  WHERE grantee = 'demo-application-staging-user';
 table_schema | table_name  | privilege_type
--------------+-------------+----------------
 public       | deployments | SELECT
(1 row)

demo-application-staging-dedicated=>

Thanks! added

@fernandezcuesta fernandezcuesta marked this pull request as ready for review March 19, 2026 16:32
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
@fernandezcuesta
Copy link
Copy Markdown
Collaborator Author

@dawidmalina ghcr.io/crossplane-contrib/provider-sql:v0.15.0-rc.1

@dawidmalina
Copy link
Copy Markdown

@fernandezcuesta - no issues after switching to this version. Working as expected :) thank you

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
@fernandezcuesta fernandezcuesta requested a review from chlunde April 17, 2026 05:59
@dawidmalina
Copy link
Copy Markdown

@fernandezcuesta - Just a reminder :) Is there any news on this matter?

@fernandezcuesta
Copy link
Copy Markdown
Collaborator Author

We need an approval from a maintainer :(

@matthewgreenwaldagility
Copy link
Copy Markdown

@fernandezcuesta Do you have some spare time to review this PR? 🙏

@fernandezcuesta
Copy link
Copy Markdown
Collaborator Author

Even if I could, that would look awkward 😄

@dawidmalina
Copy link
Copy Markdown

Pinging @chlunde, @Duologic, and other maintainers for a 👍 on this.

@matthewgreenwaldagility
Copy link
Copy Markdown

Even if I could, that would look awkward 😄

Whoops your handle and name didn't match and I wasn't being careful enough. My mistake.

@chlunde chlunde changed the title Follow up 235 feat(pgsql): extend Grant kind specification with schema, tables, columns, sequences, routines, foreign data wrappers, foreign servers May 14, 2026
Comment thread apis/namespaced/postgresql/v1alpha1/grant_types.go Outdated
Comment thread cluster/local/postgresdb_functions.sh
Comment thread cluster/local/postgresdb_functions.sh Outdated
Comment thread cluster/local/postgresdb_functions.sh Outdated
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.

Not super excited about calling GetServerVersion with sql.Open every reconcile, but I don't have a good alternative now either :)

@chlunde
Copy link
Copy Markdown
Collaborator

chlunde commented May 14, 2026

Just a few nits - and a conflict (sorry about that, I should have reviewed this one first). LGTM soon!

fernandezcuesta and others added 4 commits May 15, 2026 09:16
Co-authored-by: Carl Henrik Lunde <chlunde@gmail.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
@fernandezcuesta
Copy link
Copy Markdown
Collaborator Author

Not super excited about calling GetServerVersion with sql.Open every reconcile, but I don't have a good alternative now either :)

OK "addressed" that by calling it once per Connect rather than once per Create/Observe, mainly the same though but easier to tackle in the future

@fernandezcuesta fernandezcuesta merged commit 586a825 into master May 15, 2026
8 checks passed
@baburciu
Copy link
Copy Markdown
Contributor

thank you for this great work! Do you guys think we could issue a new tag to include this PR? :) I know v0.15.0 was just released

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.

7 participants