-
Notifications
You must be signed in to change notification settings - Fork 78
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tommi2Day Thanks for opening this PR and for your work on that!
Unfortunately it's not that simple to fully implement the postgresql_grant
resource for functions.
The first apply works great and grant the expected privileges but revoke is not working if you remove the resource.
Also if I don't remove the resource in the Terraform code but revoke manually the EXECUTE
privilege, I expect Terraform to re-grant it on next apply but it's not the case.
I quickly check why it's not working; The postgresql_grant
resource read the current granted privileges with this query by reading the pg_class
table. It works for tables and sequences but not for functions (neither for database
for which we already wrote another query).
We need another query to get the currently granted privileges for functions. It's actually stored in pg_proc
table. I'm able to see this privileges with a query like:
SELECT proname, proacl FROM pg_proc
JOIN pg_namespace ON pronamespace = pg_namespace.oid
WHERE nspname = 'test_schema';
I think we just need the specific query (which will parse proacl
with aclexplode) but then use the same code to compare them with the current state.
Let me know if you need help on that or more explanations.
@cyrilgdn : thanks for your review. I just added a second commit which addresses your remarks by adding such query on pg_proc. Hopefully it will do the revoke the right way . The use case you described (dropping the right in psql and apply terraform again) worked for me now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tommi2Day Thanks a lot for your work.
I tested it and it works fine 👍
I rebased it on master and will merge it.
FYI, this has just been released in v1.7.0. |
FYI a change in this PR breaks compatibility with Postgres versions older than 11. #159 (comment) |
This extends both, postgresql_grant and postgresql_default_privileges to grant execute on functions in addition to the existing table and sequence object types. Test are updated as well documentations