Skip to content
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

fix: Optional revoke on postgresql_grant_role #384

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

faymard
Copy link

@faymard faymard commented Dec 13, 2023

Since PostgreSQL 16.0, there is a dependency check made when revoking grants on roles.

Specifically, if role A has a grant with admin rights on role B, and uses these rights to grant role B to role C, then it can't be revoked without cascading.

This PR allows to use postgresql_grant_role without doing an initial REVOKE query. Our use case for this feature is applying two different DB stacks (one for development and one for unit testing) which share grants on common roles.

@faymard faymard force-pushed the grant-role-optional-revoke branch 2 times, most recently from bfa51f0 to 0dd7039 Compare December 13, 2023 14:35
@faymard
Copy link
Author

faymard commented Feb 7, 2024

Hi, could we had a quick review and feedback on this one please ? A few of our teams are starting their upgrades to PG16 and they start experiencing errors due to the systematic revoke.

@faymard
Copy link
Author

faymard commented Mar 4, 2024

Hi, I would like some view on when this PR could be checked (if it ever could be). Thank you very much :)

@cyrilgdn
Copy link
Owner

cyrilgdn commented Mar 4, 2024

Hi,

Thank you for opening this PR and sorry for the response delay.

Actually I wonder why it revokes the role before granting him again 🤔

I know in postgresql_grant we do that to be sure to revoke potential extra permission, but in this we want the role to be granted eventually so 🤔

As it's possible to grant the same role twice, it will just print a NOTICE log saying that the role is already a member, I think we could get rid of this revoke. I'll just quickly check if it's the same behavior in all supported versions.

@faymard
Copy link
Author

faymard commented Mar 4, 2024

Hi,

Thank you for opening this PR and sorry for the response delay.

Actually I wonder why it revokes the role before granting him again 🤔

I know in postgresql_grant we do that to be sure to revoke potential extra permission, but in this we want the role to be granted eventually so 🤔

As it's possible to grant the same role twice, it will just print a NOTICE log saying that the role is already a member, I think we could get rid of this revoke. I'll just quickly check if it's the same behavior in all supported versions.

Hi, thank you very much for your feedback 😄 I also had the same feeling about this potentially-useless revoke, but I was not confident enough in my DBA skills to assume it in the first place. Thank you for comforting this point of view.

I'm waiting for your feedback then.

Have a nice day/evening

@faymard
Copy link
Author

faymard commented Apr 8, 2024

Hi, any news ? We're being sollicitated on this issue, we have a work-around to provide (we built a custom version of the provider, and we tell people to change the version temporarily) but it's not easy to understand for our colleagues.

@faymard faymard force-pushed the grant-role-optional-revoke branch from 0dd7039 to 1b99a50 Compare May 21, 2024 13:11
@faymard
Copy link
Author

faymard commented May 23, 2024

Hi,

I did a small change to disable the REVOKE query by default. For me it makes more sense since its usage is not trivial in all cases, but I do get that it could be useful for some. Hence it should be opt-in for me.

@cyrilgdn cyrilgdn marked this pull request as draft August 29, 2024 19:39
@cyrilgdn cyrilgdn marked this pull request as ready for review August 29, 2024 19:39
@faymard
Copy link
Author

faymard commented Oct 3, 2024

Hi, is it possible for you to review/merge this soon ? Thanks in advance

@cyrilgdn
Copy link
Owner

Hi @faymard ,

since its usage is not trivial in all cases, but I do get that it could be useful for some. Hence it should be opt-in for me.

Do you have some examples on some use case it could be useful.

Otherwise you can simply remove the revoke I think.

@cyrilgdn cyrilgdn added the waiting-response Further information is requested label Oct 22, 2024
@faymard
Copy link
Author

faymard commented Oct 22, 2024

Hi,

Do you have some examples on some use case it could be useful

Well, I don't but I was just making assumptions 😅 Maybe it's just useful in case the role was granted outside of Terraform to avoid conflicts, but IMHO this should be resolved by imports.

If you're ok with simply removing the revoke part, I'll do it ASAP, no problems. Maybe even tomorrow so it's done quick.

@github-actions github-actions bot removed the waiting-response Further information is requested label Oct 22, 2024
@cyrilgdn
Copy link
Owner

If you're ok with simply removing the revoke part, I'll do it ASAP, no problems. Maybe even tomorrow so it's done quick.

I'm totally ok 👍 (it's the same than having the revoke disable by default, in the worse case of someone complain I'll do a small patch like you did here)

@faymard
Copy link
Author

faymard commented Oct 23, 2024

I made the change this morning. I still need to test it though

@cyrilgdn
Copy link
Owner

@faymard Is it ok for you, can we merge it ?

@faymard
Copy link
Author

faymard commented Oct 30, 2024

Yes, it's good for us and working as intended. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants