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

Support role configuration parameters #305

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wilsonjackson
Copy link
Contributor

Adds an optional, repeatable parameter block to the postgresql_role resource, which is used to define arbitary configuration parameters for the role. This is equivalent to using ALTER ROLE [role] SET [param] TO [value].

Example:

resource "postgresql_role" "test_role" {
  name = "audited_user"

  parameter {
    name  = "pgaudit.log"
    value = "all"
  }
}

This is more or less an alternate implementation to #211, and is in line with the suggestion in a comment on that PR.

Some implementation notes:

  1. Some configuration parameters are already supported by dedicated arguments: search_path, statement_timeout, idle_in_transaction_timeout, and role. To prevent those existing arguments from conflicting with this one and causing perpetual diffs, those parameters cannot be set with a parameter block.

  2. There are some peculiarities with value quoting:

    Most general configuration parameters, for example client_min_messages, can either be quoted string literals or bare tokens in the ALTER ROLE statement. At least one — search_pathcannot be quoted. Or rather, quoting will give you unexpected results. Others, for instance pgaudit.log, must be quoted, or the statement will produce an error.

    To accommodate all circumstances including ones I wasn't able to personally test, I opted to include an optional quote property in the parameter block that defaults to true, so quoting can be selectively disabled if required.

Closes #210

@ayoul3
Copy link

ayoul3 commented Jun 5, 2023

Hey @cyrilgdn, this MR could really help us handle pg_audit for roles, do you think we can have it in the next release ? 🙏, cheers

@gregarndt
Copy link

@cyrilgdn Looks like someone has a possible PR posted to resolve this gap. Is there something the community can do to help move this PR along?

@vmercierfr
Copy link

Hello,
We have been using the fork with success for a while to manage pg_audit configuration for PostgreSQL roles
@cyrilgdn is there any plan to move further with this PR?

@bhoriuchi
Copy link

bhoriuchi commented Nov 3, 2023

This is a great addition, however I do not think it supplants #211 because it requires the role to be created in the same resource. If you are for example using cloudsql postgres IAM users you must use the google provider to create the user. If you are using that user for the vault database secrets backend you need to add the CREATEROLE permission to that iam user after its added.

Additionally for special permissions https://www.postgresql.org/docs/current/sql-createrole.html i have not seen a way to use "ALTER ROLE %s SET %s TO %s" to set them so they likely need to be special cased to use ALTER ROLE [role name] [special permission]. CREATEROLE is one of these special permissions

@cyrilgdn cyrilgdn self-requested a review February 24, 2024 18:58
@jyriok
Copy link

jyriok commented Apr 12, 2024

@cyrilgdn
hello, do you planning to merge this PR into the next release?
This would be very useful to us!
thanks :)

@Anton-Shutik
Copy link

@jyriok Seems like that repo is weakly supported :( I have similar PR, but it's waiting for a long time as well

@igor-nikiforov
Copy link

@cyrilgdn just a friendly ping here

@cyrilgdn cyrilgdn force-pushed the main branch 3 times, most recently from f2c2e47 to dea1401 Compare September 8, 2024 17:06
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.

Support for ALTER ROLE xxx SET yyy = zzz;
8 participants