Skip to content

postgresql_default_privileges should allow empty list of privileges #117

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

Closed
alec-rabold opened this issue Aug 16, 2021 · 1 comment · Fixed by #118
Closed

postgresql_default_privileges should allow empty list of privileges #117

alec-rabold opened this issue Aug 16, 2021 · 1 comment · Fixed by #118

Comments

@alec-rabold
Copy link
Contributor

alec-rabold commented Aug 16, 2021

Hi, I was trying to revoke default privileges for functions/procedures from the PUBLIC role, which can be done by:

ALTER DEFAULT PRIVILEGES FOR ROLE <role> 
  REVOKE EXECUTE ON FUNCTIONS FROM public;

However it seems privileges currently requires at least one item in its list:

"privileges": &schema.Schema{
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
MinItems: 1,
Description: "The list of privileges to apply as default privileges",
},

I imagine this can be accomplished with something similar to what postgresql_grant does:

privileges := []string{}
for _, priv := range d.Get("privileges").(*schema.Set).List() {
privileges = append(privileges, priv.(string))
}
if len(privileges) == 0 {
log.Printf("[DEBUG] no privileges to grant for role %s in database: %s,", d.Get("role").(string), d.Get("database"))
return nil
}

The use-case is tighter access control for functions/procedures and help prevent privilege escalation.

Terraform Version

0.13.7

Affected Resource(s)

  • postgresql_default_privileges

Terraform Configuration Files

resource "postgresql_default_privileges" "revoke_functions_from_public" {
  role     = "public"
  database = postgresql_database.database.name

  owner       = "<role>"
  object_type = "function"
  privileges  = []
}

Expected Behavior

All privileges for the object_type are revoked, none are granted.

Actual Behavior

Error: privileges: attribute supports 1 item as a minimum, config has 0 declared

Steps to Reproduce

  1. terraform apply

Important Factoids

In case it helps, running on AWS RDS, therefore template1 and the master user need to be used for the ALTER DEFAULT PRIVILEGES command to be successful.

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

@alec-rabold
Copy link
Contributor Author

alec-rabold commented Aug 17, 2021

Gave it a shot in #118, seems to work after building the provider locally and testing with that. Haven't had a chance to run the full test suite locally yet though.

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 a pull request may close this issue.

1 participant