Review contained database authentication in GCP Cloud SQL

Disable SQL Server database-level authentication when it is unnecessary

Description

With contained database authentication enabled, contained users can authenticate in their database without a SQL Server instance login.

Potential impact

Someone who can create database users can grant access to an account that does not appear in the instance’s login list.

Remediation

Check which users and applications rely on this method. If it is unnecessary, migrate those connections before setting the flag to off in settings.database_flags, then test application access. If it is required, limit who can create users.

Examples

The examples also change the same instance from 2017 Express to 2019 Standard. Keep the current version and edition when changing only the flag and supply the other required instance 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  = "contained database authentication"
      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  = "contained database authentication"
      value = "off"
    }
  }
}

References