Skip to content

Google Cloud SQL with mysql8: Revoke OR change of grants fails for CLOUD_IAM_USER accounts #250

@TreZc0

Description

@TreZc0

Ever since updating our CloudSQL mysql instances to 8, we struggle to remove grants from our users.


│ Error: error revoking REVOKE ALTER, CREATE, DELETE, DROP, INDEX, INSERT, PROCESS, REFERENCES, SELECT, SHOW VIEW, SHOW_ROUTINE, UPDATE ON . FROM 'firstname.lastname'@'%': Error 3879 (HY000): Access denied for AuthId root@% to database 'mysql'.


All our sql users are CLOUD_IAM_USER objects in GCP, embedded into the GCP IAM workflow. Before v8, it was simple to remove users, now, the above error occurs, and users need to be manually removed. The same happens when we try to change the grants of a user.

resource "google_sql_user" "api-dev-users" {
  for_each = toset(concat(var.cloudsql_read_users, var.cloudsql_write_users))
  name     = each.value
  instance = google_sql_database_instance.api-dev.name
  type     = "CLOUD_IAM_USER"
}

resource "mysql_grant" "developer-read-users" {
  for_each   = toset(var.cloudsql_read_users)
  user       = split("@", each.value)[0]
  host       = "%"
  database   = "*"
  privileges = ["SELECT", "SHOW VIEW", "PROCESS", "SHOW_ROUTINE"]
  provider   = mysql.api-dev
  depends_on = [
    google_sql_user.api-dev-users
  ]
}

The only fix seems to be to manually destroy the cloud_iam_user element and then apply the mysql_grant resource again. I tried messing with the depends_on in the mysql_grant resource, but to no effect. The only workaround i could find is to run a time resource inbetween that forces the google_sql_user element to be messed with first and then let the grant depend on the time element, but that only helps for destruction of users, not for altering of grants.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions