Ensure Cloud SQL SQL server instance contained database authentication database flag is set to Off

Error: Cloud SQL SQL server instance contained database authentication database flag is set to On

Bridgecrew Policy ID: BC_GCP_SQL_10
Checkov Check ID: CKV_GCP_59
Severity: MEDIUM

Cloud SQL SQL server instance contained database authentication database flag is set to On

Description

A contained database includes all database settings and metadata required to define the database. It has no configuration dependencies on the instance of the Database Engine where the database is installed. Users can connect to the database without authenticating a login at the Database Engine level. Isolating the database from the Database Engine makes it possible to easily move the database to another instance of SQL Server. Contained databases have some unique threats that should be understood and mitigated by SQL Server Database Engine administrators. Most of the threats are related to the USER WITH PASSWORD authentication process, which moves the authentication boundary from the Database Engine level to the database level,

We recommend you ensure the contained database authentication database flag for SQL Server database instances is disabled. To achieve this, set the value to Off.

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 PostgreSQL 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 contained database authentication 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 contained database authentication database flag for every Cloud SQL SQL Server database instance using the below command:
gcloud sql instances patch INSTANCE_NAME 
--database-flags "contained database authentication=off"

📘

Note

This command will overwrite all database flags previously set. To keep these 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

Terraform

  • Resource: google_sql_database_instance
  • Arguments:
    databaseversion = "SQLSERVER* "
    settings::database_flags: key:"contained database authentication", value: by default set to "on"
resource "google_sql_database_instance" "default" {
  name             = "master-instance"
  database_version = "SQLSERVER_2017_STANDARD"
  region           = "us-central1"
  
  settings {
+         database_flags {
+            name  = "cross db ownership chaining""
+            value = "off"
          }
  }
}