Repository navigation
Description
Is there an existing issue already for this feature request/idea?
- I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.
What problem is this feature going to solve? Why should it be added?
Right now, the Database CRD only manages the owner of the schema.
PostgreSQL provides two privileges as part of the GRANT command on schemas: CREATE and USAGE. See "SQL Grant".
Users are now using the post initialization scripts for this, making it imperative, one-off and thus fragile.
Describe the solution you'd like
Providing usage permissions on managed schema objects as part of the Database CRD.
The GRANT SQL command in Postgres has the following syntax:
GRANT { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
ON SCHEMA schema_name [, ...]
TO role_specification [, ...] [ WITH GRANT OPTION ]
[ GRANTED BY role_specification ]Both GRANTED BY and WITH GRANT OPTION are not suitable for a declarative environment typical of CloudNativePG, so we will focus only on CREATE and USAGE.
A possible implementation could be:
# ...
spec:
schemas:
- name: app
owner: app
create:
- name: angus
type: grant
- name: brian
type: revoke
usage:
- name: angus
type: grant
- name: brian
type: grant
# ...The default type is grant.
For example, the above will check that angus hasn't got yet the create privilege for the app database and run the required GRANT CREATE ON app TO angus. Similarly, if brian has create usage on the same app schema, it will run REVOKE CREATE ON app FROM angus.
See: REVOKE.
Please feel free to change the above proposal if you have a better idea.
Describe alternatives you've considered
We could do nothing, and delegate this operation to another tool.
However, I personally think that this is a good responsibility for the schema management feature in the Database CRD.
Additional context
N/A
Backport?
No
Are you willing to actively contribute to this feature?
Yes
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsDone
Activity
gbartolini commentedon Jul 4, 2025
This could actually be a project for a future mentorship program.
dikshant182004 commentedon Jul 7, 2025
Hi @gbartolini ,I would like to contribute on this project .I do have good knowledge of postgresql and schema management .It would be great if u can guide me from where i can start .and is there any conversationn channel where we can have our future conversation regarding this project .
gbartolini commentedon Jul 18, 2025
Hi @dikshant182004, thanks for volunteering. Here you have more information on the mentorship program: https://github.com/cloudnative-pg/cloudnative-pg/blob/main/contribute/lfx-mentorship-program.md
dikshant182004 commentedon Jul 20, 2025
hi @gbartolini thanks for the resources ,i will look into it and starts contributing.Just wanted to confirm one thing ,Is this project for next year program.
24 remaining items
gbartolini commentedon Aug 17, 2026
Follow-up idea for this feature, not part of this PR: extend permissions with table-level grants scoped to
ALL TABLES IN SCHEMAonly (never naming individual tables, as CNPG should never need to know about, let alone create, application tables). Something like:Each list reuses the existing grant/revoke UsageSpec shape, and maps directly onto GRANT/REVOKE ON ALL TABLES IN SCHEMA ... TO/FROM ....
The open question before this is buildable: ALL TABLES IN SCHEMA only affects tables that exist when the GRANT runs. Tables are created by the application, not by CNPG, on their own schedule. So this only works if something re-applies the grant periodically.
Today, the Database reconciler doesn't do that: once a Database is applied, it goes fully idle until the next spec change (no steady-state polling). Making this feature actually catch newly created tables means adding real always-on periodic reconciliation for Database objects that opt into table-level grants, which has its own cost/interval trade-offs (grant cost scales with table count in the schema, unlike the O(1) schema-level grants). Needs its own design pass before implementation.
In my opinion, this is another reason why these operations should not be under CNPG's scope.
feat(database): add `USAGE` and `CREATE` schema privilege grants (clo…
feat(database): add `USAGE` and `CREATE` schema privilege grants (clo…