Review Cloud SQL MySQL local file loading

Disable unneeded LOAD DATA LOCAL use and limit client file access.

Description

MySQL’s LOAD DATA LOCAL sends a file from the client to the server. Both the server’s local_infile flag and the client’s LOCAL capability must allow it.

Potential impact

An untrusted server can request a file the client process can read. Disabling LOCAL also interrupts jobs that import local files.

Remediation

If you do not import local files, set the server flag to off and disable LOCAL on clients. Where imports are required, verify the server’s identity, restrict the client’s file access and SQL privileges, and test the approved imports.

Examples

Both examples configure 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  = "local_infile"
      value = "on"
    }
  }
}

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  = "local_infile"
      value = "off"
    }
  }
}

Explanation:

  • Before: on lets the server accept local file imports.
  • After: off disables local imports on this server. The added db-f1-micro is a separate machine type setting.

References