Ensure GCP MySQL instance with local_infile database flag is disabled

Error: GCP MySQL instance with local_infile database flag is not disabled

Bridgecrew Policy ID: BC_GCP_SQL_1
Checkov Check ID: CKV_GCP_50
Severity: LOW

GCP MySQL instance with local_infile database flag is not disabled


The local_infile database flag controls the server-side LOCAL capability for LOAD DATA statements. Depending on the local_infile setting, the server refuses or permits local data loading by clients that have LOCAL enabled on the client side.

To explicitly cause the server to refuse LOAD DATA LOCAL statements start mysqld with local_infile disabled, regardless of how client programs and libraries are configured at build time or runtime. local_infile can also be set at runtime.

We recommended you set the local_infile database flag for a Cloud SQL MySQL instance to off to address the security issues associated with the flag.

Fix - Runtime

GCP Console

To change the policy using the GCP Console, follow these steps:

  1. Log in to the GCP Console at https://console.cloud.google.com.
  2. Navigate to Cloud SQL Instances.
  3. Select the MySQL instance where the database flag needs to be enabled.
  4. Click Edit.
  5. Scroll down to the Flags section.
  6. To set a flag that has not been set on the instance before, click Add item.
  7. Select the flag local_infile from the drop-down menu, and set its value to off.
  8. Click Save.
  9. Confirm the changes in the Flags section on the Overview page.

CLI Command

  1. List all Cloud SQL database instances using the following command:
    gcloud sql instances list
  2. Configure the local_infile database flag for every Cloud SQL Mysql database instance using the below command:
    gcloud sql instances patch INSTANCE_NAME --database-flags local_infile=off



This command will overwrite all database flags previously set. To keep those flags, and add new ones, include the values for all flags to be set on the instance. Any flag not specifically included is set to its default value. For flags that do not take a value, specify the flag name followed by an equals sign (=).

Fix - Buildtime


  • Resource: google_sql_database_instance
  • Arguments:
    databaseversion = "MYSQL* "
    settings::database_flags: key:"local_infile", value: by default set to "on"
resource "google_sql_database_instance" "default" {
  name             = "master-instance"
  database_version = "MYSQL_8_0"
  region           = "us-central1"

  settings {
+         database_flags {
+            name  = "local_infile"
+            value = "off"