Review Cloud SQL MySQL database-listing privileges

Limit database-name visibility to accounts that need it.

Description

With skip_show_database enabled, only accounts with the SHOW DATABASES privilege can run that command. This privilege allows them to see the full list of names.

Potential impact

Database names can reveal internal structure. Restricting the list can break tools or applications that depend on it.

Remediation

To restrict listing for ordinary accounts, identify dependent tools and schedule the required restart. Set the flag to on, then test as an ordinary user and as an administrator. Review SHOW DATABASES and broad global grants, and restrict access to the data separately.

Examples

Both examples use the same MySQL 8.0 instance. Supply a supported engine version, machine type and other required settings for your environment.

Before

hcl
resource "google_sql_database_instance" "db" {
  name             = "mysql-instance"
  database_version = "MYSQL_8_0"
  region           = "us-central1"

  settings {
    database_flags {
      name  = "skip_show_database"
      value = "off"
    }
  }
}

After

hcl
resource "google_sql_database_instance" "db" {
  name             = "mysql-instance"
  database_version = "MYSQL_8_0"
  region           = "us-central1"

  settings {
    tier = "db-f1-micro"

    database_flags {
      name  = "skip_show_database"
      value = "on"
    }
  }
}

Explanation:

  • Before: With off, users can run the command. Their privileges determine which names they see.
  • After: on requires the listing privilege. The added db-f1-micro machine type is a separate setting.

References