Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Sabotaz
Copy link

@Sabotaz Sabotaz commented May 14, 2025

Description of your changes

Fixes #217

This PR is a rework of #218 who is still a draft and will probably be closed soon by his owner (cf. comments).

This PR create more fields in the forProvider part of the Grant kind for managing grants on different objects.

I refactored #218 by removing the defined objectType and objects fields, and using specific fields for each type of grant. I believe it follows the original philosophy of the Grant kind better.

This PR does not cover the GRANT xxx ON ALL xxx IN SCHEMA yyy case.

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

I tested this PR using both make test and make e2e.
I tested the raw queries on my local database.

e2e tests & unit tests have been updated with more Grant configurations :

  • grant some privileges on schema
  • grant some privileges on 1 table
  • grant some privileges on 1 column of 1 table
  • grant some privileges on 1 routine
  • grant some privileges on 1 sequence
  • grant some privileges on 1 foreign data wrapper
  • grant some privileges on 1 foreign server

However, I have only tested requests for multiple objets (i.e: grant all on table1, table2 to user ) on my local database.

I did not test this PR against sql injections, as I believe it is already a problem for the actual Grant feature (see #18 , #22 for mysql, and I would say #22 did not fully fix the problem for mysql as the injection can still be performed using some other fields: database, table, user).

Bastichou and others added 7 commits May 14, 2025 15:46
Signed-off-by: Bastien CERIANI <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
Signed-off-by: Julien Christophe <[email protected]>
@Sabotaz Sabotaz force-pushed the feat/extend-pgsql-grant-support-to-schema branch from 31dbebe to e0f9a4b Compare May 14, 2025 19:14
@Sabotaz
Copy link
Author

Sabotaz commented May 19, 2025

@Duologic, can anyone among the maintainers review this PR?
@Bastichou as you already worked on this issue, perhaps you can review it too? :D

@dawidmalina
Copy link

Adding @chlunde to the loop - this change is really needed by many Postgres users

@dawidmalina
Copy link

dawidmalina commented Jun 5, 2025

Just tested and I can confirmed that I can achieve GRANT USAGE, CREATE ON SCHEMA public TO <ROLE>; with crossplane:

---
apiVersion: postgresql.sql.crossplane.io/v1alpha1
kind: Grant
metadata:
  name: public
spec:
  forProvider:
    databaseRef:
      name: <DATABASE>
    privileges:
      - CREATE
      - USAGE
    roleRef:
      name: <ROLE>
    schema: public
  providerConfigRef:
    name: admin

Looking forward to use official provider not custom build.

@chlunde
Copy link
Collaborator

chlunde commented Jun 5, 2025

@dawidmalina thanks for testing!

If we have consensus on the schema design, I think that (and testing) is most important.

Linewise, the change is huge (+2000 lines), so getting a few eyes on this would be very helpful.

@dawidmalina
Copy link

Any updates on this? I would really like to see that to be part of the official release.

@chlunde
Copy link
Collaborator

chlunde commented Jun 17, 2025

@Bastichou could you take a look at this version?

I've read through all the issues and closed duplicates, and I think this solves a lot of them. I'd like to make this part of the next release, so thanks a lot for everyone working on this!

Two things I would like to test:

  • That this is 100% compatible with existing grants
  • That we're sure this is the right design

This PR does not cover the GRANT xxx ON ALL xxx IN SCHEMA yyy case.

@Sabotaz do you think this could be handled in the future, could you expand a bit on this? Thanks!

@Kidswiss
Copy link

That we're sure this is the right design

Can you elaborate what design you mean? The CRD design? Code design?

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.

[PGSQL] Extend Grant kind to support more than database object
5 participants