Table: gcp_compute_instances

This table shows data for GCP Compute Instances.

https://cloud.google.com/compute/docs/reference/rest/v1/instances#Instance (opens in a new tab)

The primary key for this table is self_link.

Columns

NameType
_cq_iduuid
_cq_parent_iduuid
project_idutf8
advanced_machine_featuresjson
can_ip_forwardbool
confidential_instance_configjson
cpu_platformutf8
creation_timestamputf8
deletion_protectionbool
descriptionutf8
disksjson
display_devicejson
fingerprintutf8
guest_acceleratorsjson
hostnameutf8
idint64
instance_encryption_keyjson
key_revocation_action_typeutf8
kindutf8
label_fingerprintutf8
labelsjson
last_start_timestamputf8
last_stop_timestamputf8
last_suspended_timestamputf8
machine_typeutf8
metadatajson
min_cpu_platformutf8
nameutf8
network_interfacesjson
network_performance_configjson
paramsjson
private_ipv6_google_accessutf8
reservation_affinityjson
resource_policieslist<item: utf8, nullable>
resource_statusjson
satisfies_pzsbool
schedulingjson
self_link (PK)utf8
service_accountsjson
shielded_instance_configjson
shielded_instance_integrity_policyjson
source_machine_imageutf8
source_machine_image_encryption_keyjson
start_restrictedbool
statusutf8
status_messageutf8
tagsjson
zoneutf8

Example Queries

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

Ensure that IP forwarding is not enabled on Instances (Automated)

SELECT
  name AS resource_id,
  'Ensure that IP forwarding is not enabled on Instances (Automated)' AS title,
  project_id AS project_id,
  CASE WHEN can_ip_forward = true THEN 'fail' ELSE 'pass' END AS status
FROM
  gcp_compute_instances;

Ensure that instances are not configured to use the default service account (Automated)

SELECT
  DISTINCT
  gci.name AS resource_id,
  'Ensure that instances are not configured to use the default service account (Automated)'
    AS title,
  gci.project_id AS project_id,
  CASE
  WHEN gci.name NOT LIKE 'gke-'
  AND gcisa->>'email'
    = (
        SELECT
          default_service_account
        FROM
          gcp_compute_projects
        WHERE
          project_id = gci.project_id
      )
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances AS gci,
  jsonb_array_elements(gci.service_accounts) AS gcisa;

Ensure that instances are not configured to use the default service account with full access to all Cloud APIs (Automated)

SELECT
  DISTINCT
  gci.name AS resource_id,
  'Ensure that instances are not configured to use the default service account with full access to all Cloud APIs (Automated)'
    AS title,
  gci.project_id AS project_id,
  CASE
  WHEN gcisa->>'email'
  = (
      SELECT
        default_service_account
      FROM
        gcp_compute_projects
      WHERE
        project_id = gci.project_id
    )
  AND ARRAY['https://www.googleapis.com/auth/cloud-platform']
    <@ ARRAY (SELECT jsonb_array_elements_text(gcisa->'scopes'))
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances AS gci,
  jsonb_array_elements(gci.service_accounts) AS gcisa;

Ensure that Compute instances do not have public IP addresses (Automated

SELECT
  DISTINCT
  gci.name AS resource_id,
  'Ensure that Compute instances do not have public IP addresses (Automated'
    AS title,
  gci.project_id AS project_id,
  CASE
  WHEN gci.name NOT LIKE 'gke-%'
  AND (
      (ac4->>'nat_i_p') IS NOT NULL
      OR ac4->>'nat_i_p' != ''
      OR (ac6->>'nat_i_p') IS NOT NULL
      OR ac6->>'nat_i_p' != ''
    )
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances AS gci,
  jsonb_array_elements(gci.network_interfaces) AS ni
  LEFT JOIN jsonb_array_elements(ni->'access_configs') AS ac4 ON true
  LEFT JOIN jsonb_array_elements(ni->'ipv6_access_configs') AS ac6 ON true;

Ensure Compute instances are launched with Shielded VM enabled (Automated)

SELECT
  name AS resource_id,
  'Ensure Compute instances are launched with Shielded VM enabled (Automated)'
    AS title,
  project_id AS project_id,
  CASE
  WHEN (shielded_instance_config->>'enable_integrity_monitoring')::BOOL = false
  OR (shielded_instance_config->>'enable_vtpm')::BOOL = false
  OR (shielded_instance_config->>'enable_secure_boot')::BOOL = false
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances;

Ensure "Block Project-wide SSH keys" is enabled for VM instances (Automated)

SELECT
  gci.name AS resource_id,
  'Ensure "Block Project-wide SSH keys" is enabled for VM instances (Automated)'
    AS title,
  gci.project_id AS project_id,
  CASE
  WHEN (gcmi->>'key') IS NULL
  OR NOT (gcmi->>'value' = ANY ('{1,true,True,TRUE,y,yes}'))
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances AS gci
  LEFT JOIN jsonb_array_elements(gci.metadata->'items') AS gcmi ON
      gcmi->>'key' = 'block-project-ssh-keys';

Ensure that Compute instances have Confidential Computing enabled (Automated)

SELECT
  name AS resource_id,
  'Ensure that Compute instances have Confidential Computing enabled (Automated)'
    AS title,
  project_id AS project_id,
  CASE
  WHEN (confidential_instance_config->>'enable_confidential_compute')::BOOL
  = false
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances;

Ensure "Enable connecting to serial ports" is not enabled for VM Instance (Automated)

SELECT
  name AS resource_id,
  'Ensure "Enable connecting to serial ports" is not enabled for VM Instance (Automated)'
    AS title,
  project_id AS project_id,
  CASE
  WHEN gcmi->>'key' = 'serial-port-enable'
  AND gcmi->>'value' = ANY ('{1,true,True,TRUE,y,yes}')
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_compute_instances AS gci,
  jsonb_array_elements(gci.metadata->'items') AS gcmi;