Skip to content

GCP SQL Server instance database flag 'contained database authentication' is enabled

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.

Code Example

go
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"
          }
  }
}

Remediation

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

. Log in to the GCP Console at https://console.cloud.google.com.

. Navigate to https://console.cloud.google.com/sql/instances [Cloud SQL Instances].

. Select the * PostgreSQL instance* where the database flag needs to be enabled.

. Click * Edit*.

. Scroll down to the * Flags* section.

. To set a flag that has not been set on the instance before, click * Add item*.

. Select the flag * contained database authentication* from the drop-down menu, and set its value to * Off*.

. Click * Save*.

. Confirm the changes in the * Flags* section on the * Overview* page.

  • CLI Command*

. List all Cloud SQL database Instances using the following command: `gcloud sql instances list`

. 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: database_version = "SQLSERVER_* " settings::database_flags: key:"contained database authentication", value: by default set to "on"

Rule Details

FieldValue
IDIAC-0918
SeverityLOW
IaC TypeTerraform
FrameworksTerraform, TerraformPlan
Checkov IDCKV_GCP_59

References