Ensure Cloud SQL SQL server instance database flag cross db ownership chaining is set to Off

Error: Cloud SQL SQL server instance database flag cross db ownership chaining is set to On

Bridgecrew Policy ID: BC_GCP_SQL_9
Checkov Check ID: CKV_GCP_58
Severity: MEDIUM

Cloud SQL SQL server instance database flag cross db ownership chaining is set to On

Description

Use the cross db ownership chaining database flag to configure cross-database ownership chaining for an instance of Microsoft SQL Server. This server option allows you to control cross-database ownership chaining at database-level, or to allow cross-database ownership chaining for all databases.

We recommend you disable the cross db ownership chaining flag for Cloud SQL SQL Server instances, by setting it to Off. Enabling cross db ownership chaining is only effective when all of the databases hosted by the instance of SQL Server participate in cross-database ownership chaining, and you are aware of the security implications of this setting.

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

📘

Note

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

Terraform

  • Resource: google_sql_database_instance
  • Arguments:
    databaseversion = "SQLSERVER* "
    settings::database_flags: key:"cross db ownership chaining", 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"
          }
  }
}