adding support for postgres SET ROLE? #625
Replies: 1 comment 1 reply
-
A more general solution might be to introduce a new command-line argument named something like I would be more in favor of this than a Postgres-specific change that's limited to only invoking a The one trap that your PR does illuminate is that when we use external executables for certain functionality, such as dumping the schema, we may not have a way of passing along these initialization SQL statements to the external program to invoke before it does its work. There's a separate discussion #547 around why there's no mechanism for supplying additional command line arguments to the dump command that dbmate invokes, so these two changes (init-sql, dump options) combined would solve your problem in a very general way, and allow for a lot of other problems to be solved with no additional changes to dbmate. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm considering using dbmate for my current project using Postgres, although to make it work for my setup I need the ability to switch role after the db connection is established.
why ?
My Postgres users are configured to have (almost) no permissions themselves, but are allowed to switch temporarily to some specific roles depending on the tasks, similarly to the
sudo
linux logic.Expressed in Postgres lingo: those users are granted some roles but do not inherit automatically their permissions.
A simplified version of the setup looks as follows
The way this works is that users first connect with their credentials:
Then depending on what they need to do, they can switch to read-only or read-write role (if they're allowed to):
SET ROLE my_read_write
Common GUI tools like DBeaver support this pattern, allowing to specify an additional role to switch to as part of the connection details.
How
dbmate
does not support to automaticallySET ROLE
at the moment, although it seems pretty straightforward to add it. I created a quick proof of concept here with hardcoded values, and I confirm it works with the setup I describe above:https://github.com/sv3ndk/dbmate/pull/1/files
Next steps?
Would this be a feature you'd be open to? I'm happy to work on this and re-work my proof into a workable solution.
If so, let me know your thought on how to approach this. I have in mind to extend the
Driver
struct to contain an additionalrole
field, although I'm happy to align on any direction you give me in that regard.Looking forward to your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions