Table: gcp_sql_instances

This table shows data for GCP SQL Instances.

https://cloud.google.com/sql/docs/mysql/admin-api/rest/v1beta4/instances#DatabaseInstance (opens in a new tab)

The primary key for this table is self_link.

Relations

The following tables depend on gcp_sql_instances:

Columns

NameType
_cq_iduuid
_cq_parent_iduuid
project_idutf8
available_maintenance_versionslist<item: utf8, nullable>
backend_typeutf8
connection_nameutf8
create_timeutf8
current_disk_sizeint64
database_installed_versionutf8
database_versionutf8
disk_encryption_configurationjson
disk_encryption_statusjson
etagutf8
failover_replicajson
gce_zoneutf8
instance_typeutf8
ip_addressesjson
ipv6_addressutf8
kindutf8
maintenance_versionutf8
master_instance_nameutf8
max_disk_sizeint64
nameutf8
on_premises_configurationjson
out_of_disk_reportjson
projectutf8
regionutf8
replica_configurationjson
replica_nameslist<item: utf8, nullable>
root_passwordutf8
satisfies_pzsbool
scheduled_maintenancejson
secondary_gce_zoneutf8
self_link (PK)utf8
server_ca_certjson
service_account_email_addressutf8
settingsjson
stateutf8
suspension_reasonlist<item: utf8, nullable>

Example Queries

These SQL queries are sampled from CloudQuery policies and are compatible with PostgreSQL.

Ensure that Cloud SQL database instances are not open to the world (Automated)

SELECT
  DISTINCT
  gsi.name AS resource_id,
  'Ensure that Cloud SQL database instances are not open to the world (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND gsisican->>'value' = '0.0.0.0/0'
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi,
  jsonb_array_elements(gsi.settings->'ipConfiguration'->'authorizedNetworks')
    AS gsisican;

Ensure that Cloud SQL database instances do not have public IPs (Automated)

SELECT
  DISTINCT
  gsi.name AS resource_id,
  'Ensure that Cloud SQL database instances do not have public IPs (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND gsiia->>'type' = 'PRIMARY'
  OR gsi.backend_type != 'SECOND_GEN'
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi, jsonb_array_elements(gsi.ip_addresses) AS gsiia;

Ensure that the Cloud SQL database instance requires all incoming connections to use SSL (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the Cloud SQL database instance requires all incoming connections to use SSL (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND (gsi.settings->'ipConfiguration'->>'requireSsl')::BOOL = false
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi;

Ensure that Cloud SQL database instances are configured with automated backups (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that Cloud SQL database instances are configured with automated backups (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND (gsi.settings->'backupConfiguration'->>'enabled')::BOOL = false
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi;

Ensure that the "local_infile" database flag for a Cloud SQL Mysql instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "local_infile" database flag for a Cloud SQL Mysql instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'MYSQL%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'local_infile';

Ensure "skip_show_database" database flag for Cloud SQL Mysql instance is set to "on" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "skip_show_database" database flag for Cloud SQL Mysql instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'MYSQL%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'skip_show_database';

Ensure that the "log_checkpoints" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_checkpoints" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_checkpoints';

Ensure that the "log_connections" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_connections" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_connections';

Ensure that the log_disconnections" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the log_disconnections" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_disconnections';

Ensure "log_duration" database flag for Cloud SQL PostgreSQL instance is set to "on" (Manual)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_duration" database flag for Cloud SQL PostgreSQL instance is set to "on" (Manual)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_duration';

Ensure "log_error_verbosity" database flag for Cloud SQL PostgreSQL instance is set to "DEFAULT" or stricter (Manual)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_error_verbosity" database flag for Cloud SQL PostgreSQL instance is set to "DEFAULT" or stricter (Manual)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' NOT IN ('default', 'terse'))
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_error_verbosity';

Ensure "log_executor_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_executor_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_executor_stats';

Ensure "log_hostname" database flag for Cloud SQL PostgreSQL instance is set appropriately (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_hostname" database flag for Cloud SQL PostgreSQL instance is set appropriately (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_hostname';

Ensure that the "log_lock_waits" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_lock_waits" database flag for Cloud SQL PostgreSQL instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_lock_waits';

Ensure that the "log_min_duration_statement" database flag for Cloud SQL PostgreSQL instance is set to "-1" (disabled) (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_min_duration_statement" database flag for Cloud SQL PostgreSQL instance is set to "-1" (disabled) (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != '-1')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_min_duration_statement';

Ensure that the "log_min_messages" database flag for Cloud SQL PostgreSQL instance is set appropriately (Manual)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_min_messages" database flag for Cloud SQL PostgreSQL instance is set appropriately (Manual)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND (
      (f->>'value') IS NULL
      OR f->>'value' NOT IN ('error', 'log', 'fatal', 'panic')
    )
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_min_error_statement';

Ensure "log_parser_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_parser_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_parser_stats';

Ensure "log_planner_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_planner_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_planner_stats';

Ensure "log_statement_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "log_statement_stats" database flag for Cloud SQL PostgreSQL instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_statement_stats';

Ensure that the "log_temp_files" database flag for Cloud SQL PostgreSQL instance is set to "0" (on) (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "log_temp_files" database flag for Cloud SQL PostgreSQL instance is set to "0" (on) (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'POSTGRES%'
  AND ((f->>'value') IS NULL OR f->>'value' != '0')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'log_temp_files';

Ensure that the "contained database authentication" database flag for Cloud SQL on the SQL Server instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "contained database authentication" database flag for Cloud SQL on the SQL Server instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'contained database authentication';

Ensure that the "cross db ownership chaining" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure that the "cross db ownership chaining" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'cross db ownership chaining';

Ensure "external scripts enabled" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "external scripts enabled" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'external scripts enabled';

Ensure "remote access" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "remote access" database flag for Cloud SQL SQL Server instance is set to "off" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'off')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'remote access';

Ensure "3625 (trace flag)" database flag for Cloud SQL SQL Server instance is set to "on" (Automated)

-- In the original document in CIS GCP v1.2.0, it describes the configuration should be 'off', but it is a typo.
-- This constraint has been updated on CIS GCP v1.3.0, this flag should be 'on'.
 
SELECT
  gsi.name AS resource_id,
  'Ensure "3625 (trace flag)" database flag for Cloud SQL SQL Server instance is set to "on" (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%'
  AND ((f->>'value') IS NULL OR f->>'value' != 'on')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = '3625';

Ensure "user connections" database flag for Cloud SQL SQL Server instance is set as appropriate (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "user connections" database flag for Cloud SQL SQL Server instance is set as appropriate (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%' AND (f->>'value') IS NULL
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'user connections';

Ensure "user options" database flag for Cloud SQL SQL Server instance is not configured (Automated)

SELECT
  gsi.name AS resource_id,
  'Ensure "user options" database flag for Cloud SQL SQL Server instance is not configured (Automated)'
    AS title,
  gsi.project_id AS project_id,
  CASE
  WHEN gsi.database_version LIKE 'SQLSERVER%' AND (f->>'value') IS NOT NULL
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_sql_instances AS gsi
  LEFT JOIN jsonb_array_elements(gsi.settings->'databaseFlags') AS f ON
      f->>'name' = 'user options';