Table: gcp_logging_sinks

This table shows data for GCP Logging Sinks.

https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks#LogSink (opens in a new tab)

The composite primary key for this table is (project_id, name).

Columns

NameType
_cq_iduuid
_cq_parent_iduuid
project_id (PK)utf8
name (PK)utf8
destinationutf8
filterutf8
descriptionutf8
disabledbool
exclusionsjson
output_version_formatutf8
writer_identityutf8
include_childrenbool
optionsjson
create_timetimestamp[us, tz=UTC]
update_timetimestamp[us, tz=UTC]

Example Queries

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

Ensure that retention policies on log buckets are configured using Bucket Lock (Automated)

SELECT
  DISTINCT
  gsb.name AS resource_id,
  'Ensure that retention policies on log buckets are configured using Bucket Lock (Automated)'
    AS title,
  gls.project_id AS project_id,
  CASE
  WHEN gls.destination LIKE 'storage.googleapis.com/%'
  AND (
      (gsb.retention_policy->>'IsLocked')::BOOL = false
      OR (gsb.retention_policy->>'RetentionPeriod')::INT8 = 0
    )
  THEN 'fail'
  ELSE 'pass'
  END
    AS status
FROM
  gcp_logging_sinks AS gls
  JOIN gcp_storage_buckets AS gsb ON
      gsb.name = replace(gls.destination, 'storage.googleapis.com/', '');

Ensure that sinks are configured for all log entries (Automated)

WITH
  found_sinks
    AS (
      SELECT
        project_id, name, count(*) AS configured_sinks
      FROM
        gcp_logging_sinks AS gls
      WHERE
        gls.filter = ''
      GROUP BY
        project_id, name
    )
SELECT
  name AS resource_id,
  'Ensure that sinks are configured for all log entries (Automated)' AS title,
  project_id AS project_id,
  CASE WHEN configured_sinks = 0 THEN 'fail' ELSE 'pass' END AS status
FROM
  found_sinks;