-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/postgres grant role when creating database #11452
Conversation
Another issue that this commit fixes: Roles cannot be destroyed after they are created. Error is: Error applying plan:
1 error(s) occurred:
* postgresql_role.my-role: Error deleting role: pq: permission denied to reassign objects |
This is definitely an issue with AWS RDS, any idea if/when it'll be merged? |
hopefully soon. There is a workaround - but then you have to manually log into the postgres instance and grant the role. |
@pbthorste can it be done from provisioner? do you have a code example handy? Thanks! |
@mindw No, it is a manual operation - I'll try to explain the steps :)
That is until you log into your postgres instance and run: GRANT new_role to provider_user; after this granting has taken place, you can run terraform and the db will be created. |
Without this PR the Postgresql provider in Terraform is broken if you use RDS. Please merge. |
Any news on this one? |
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.
LGTM, thanks
…ase. For `ROLE`s who have been delegated `CREATEDB` privileges and are not a superuser, in order for them to `CREATE DATABASE` they need to be a member of the `ROLE` who will be `OWNER` for the new database. Once the `CREATE DATABASE` is complete, `REVOKE` the `GRANT` that was given to role so that the user who ran the `CREATE DATABASE` looses all privileges to the target database (unless of course they're a superuser). Fixes a regression introduced in hashicorp#11452
Uses the helper functions introduced in hashicorp#11452
* Fix doc bug. Spell `collation` like `lc_collate`. * Whitespace nit in error message * Use %q as the format verb for error messages in postgresql_database resource messages. * REVOKE the `GRANT` given to the connection user when creating a database. For `ROLE`s who have been delegated `CREATEDB` privileges and are not a superuser, in order for them to `CREATE DATABASE` they need to be a member of the `ROLE` who will be `OWNER` for the new database. Once the `CREATE DATABASE` is complete, `REVOKE` the `GRANT` that was given to role so that the user who ran the `CREATE DATABASE` looses all privileges to the target database (unless of course they're a superuser). Fixes a regression introduced in #11452 * Delegated DBA ROLEs can now fix OWNER drift for PostgreSQL databases. Uses the helper functions introduced in #11452
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
The code here is reintroduced from older commits. See:
2e52914
and
f3add9e
(the part related to grantRoleMembership).
Without this code - creating a new database with a terraform generated role as the owner will not work. You will get the error: