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

Feature request: Revoking access privileges #180

Open
BojanKomazec opened this issue Oct 30, 2024 · 1 comment
Open

Feature request: Revoking access privileges #180

BojanKomazec opened this issue Oct 30, 2024 · 1 comment

Comments

@BojanKomazec
Copy link

It would be useful if having an empty list for privileges in mysql_grant would revoke all privileges (if exist) for a given user, database and table.

resource "mysql_grant" {
   ...
   privileges = []
}

Alternatively, a new resource named like e.g. mysql_revoke should be introduced to complement the existing mysql_grant.

Provider version

3.0.65

MySQL version and settings

8.0

Terraform Configuration Files

I tried to grant user some privileges on all tables apart from one:

resource "mysql_grant" "my-user" {
  user       = mysql_user.my-user.user
  host       = mysql_user.my-user.host
  database   = "%"
  privileges = ["SELECT", "INSERT", "UPDATE", "DELETE", "CREATE"]
}

resource "mysql_grant" "revoke_my-user_access_to_table-a" {
  user       = mysql_user.my-user.user
  host       = mysql_user.my-user.host
  database   = "my-db"
  table      = "table-a"
  privileges = []
}

Expected Behavior

mysql provider grants my-user listed privileges on all tables apart from table-a.

Actual Behavior

terraform apply fails with error:

mysql_grant.revoke_my-user_access_to_table-a: Creating...
╷
│ Error: Error running SQL (GRANT  ON `my-db`.`table-a` TO 'my-user'@'%'): Error 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON `my-db`.`table-a` TO 'my-user'@'%'' at line 1

Steps to Reproduce

terraform apply

References

To achieve this currently I'd need to create a list of all tables and create "mysql_grant" for each of them (like in #179), with customized privileges for the exceptional table.

@petoju
Copy link
Owner

petoju commented Nov 1, 2024

What we should do is handle this properly - warn soon about the issue.

However, we're trying to enforce import everywhere. Without import, running provider may be dangerous as it may remove some already existing privileges not managed by provider yet.

For now, I believe the best idea is to import resources with grants for all the tables (like in #179).

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

No branches or pull requests

2 participants