Review external script execution in GCP Cloud SQL

Disable unused SQL Server external script execution

Description

external scripts enabled is SQL Server’s external script execution flag. Cloud SQL exposes the flag but does not support Machine Learning and R Services or registering external languages.

Potential impact

Script access to data requires both a runtime and execution privileges. The flag alone cannot show that a script can run on the instance.

Remediation

Check scheduled jobs and their permissions. If the flag is unnecessary, schedule the required restart before setting external scripts enabled to off in settings.database_flags. Check the effective value and existing jobs after the restart.

Examples

The example also changes 2017 Express to 2019 Standard. To turn off only the flag on the same instance, keep its current engine version, edition and other required settings.

Before

hcl
resource "google_sql_database_instance" "sqlserver_instance" {
  name             = "sqlserver-instance"
  database_version = "SQLSERVER_2017_EXPRESS"
  region           = "us-central1"

  settings {
    database_flags {
      name  = "external scripts enabled"
      value = "on"
    }
  }
}

After

hcl
resource "google_sql_database_instance" "sqlserver_instance" {
  name             = "sqlserver-instance"
  database_version = "SQLSERVER_2019_STANDARD"
  region           = "us-central1"

  settings {
    database_flags {
      name  = "external scripts enabled"
      value = "off"
    }
  }
}

References