Opened 2 years ago

Last modified 9 months ago

#34200 closed New feature

Allow setting postgres role during connection setup — at Initial Version

Reported by: Mike Crute Owned by: nobody
Component: Database layer (models, ORM) Version: 4.1
Severity: Normal Keywords:
Cc: Florian Apolloner Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When attempting to mutate database objects (tables, enumerations, etc...) Postgres requires that the logged-in role match the owning role for those objects. Typically the owning role of an object is the role that created it. This is a problem when using systems such as Hashicorp Vault which create ephemeral single-use roles for applications since those roles will, by definition, never match the creating role. This results in permission errors during structural changes such as migrations. These errors are of the general form "sequence must have same owner as table it is linked to".

The solution to this problem is pretty straightforward. First create a grouping role for the application (roles do not distinguish between being a user or a group) that can become the owner of the database objects. Then create the temporary roles generated by the credential management system as members of this grouping role. Finally, assume that grouping role before performing actions on the database using the SET ROLE statement during connection setup. This will cause all of the temporary roles to act as the grouping role which has ownership of all of these objects and eliminate the permission issues.

I propose adding a postgres-specific driver option in the settings called role which, if present, will cause the connection setup code to issue the appropriate SET ROLE statement at connection creation.

I have a patch for this that I'm testing and will submit soon.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top