Skip to content

[Feature]: Support for CREATE and USAGE grants on database schemas #7872

Description

@gbartolini

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

Activity

  1. self-assigned this
    on Jun 23, 2025
  2. added
    triage
    on Jun 23, 2025
  3. added
    enhancement 🪄
    and removed
    triage
    on Jun 23, 2025
  4. added theissue type on Jun 23, 2025
  5. added this to the 1.27.0 milestone on Jun 23, 2025
  6. gbartolini commented on Jul 4, 2025

    @gbartolini
    ContributorAuthor

    This could actually be a project for a future mentorship program.

  7. dikshant182004 commented on Jul 7, 2025

    @dikshant182004

    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 .

  8. gbartolini commented on Jul 18, 2025

    @gbartolini
    ContributorAuthor

    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 .

    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

  9. dikshant182004 commented on Jul 20, 2025

    @dikshant182004

    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.

  10. 24 remaining items

  11. gbartolini commented on Aug 17, 2026

    @gbartolini
    ContributorAuthor

    Follow-up idea for this feature, not part of this PR: extend permissions with table-level grants scoped to ALL TABLES IN SCHEMA only (never naming individual tables, as CNPG should never need to know about, let alone create, application tables). Something like:

      permissions:
        usage: [...]
        create: [...]
        tables:
          select: [...]
          insert: [...]
          update: [...]
          delete: [...]
          truncate: [...]
          references: [...]
          trigger: [...]
          maintain: [...]
          all: [...]

    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.

  12. moved this from Todo to In Progress in Roadmapon Aug 17, 2026
  13. moved this from In Progress to Done in Roadmapon Nov 2, 2026
  14. added a commit that references this issue on Nov 2, 2026
    d1cc2f8
  15. added a commit that references this issue on Nov 2, 2026
    8cdcb36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

LFX Mentorshipenhancement 🪄good first issueno-stale

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions