Skip to content

02Governance and loggingService 2 of 13

Cloud Audit Logs and Cloud Loggingsecurity hardening

Enable Data Access audit logs, route an org-wide sink to a locked, CMEK-protected log bucket, guard exclusions and build the CIS 2.5 to 2.12 alerts.

Baseline
12 controls
Category
Governance and logging
Updated
Reading
10 min read

Cloud Audit Logs records who did what, where and with which identity across Google Cloud, and Cloud Logging stores, routes and queries those records. At defaults you get Admin Activity and System Event logs, but Data Access logs are off for almost every service, logs sit in the same project as the workload, the _Default bucket keeps them for 30 days, and any project owner can add an exclusion or delete a sink. The pattern seen in cloud intrusions is predictable: an attacker with a stolen service account key reads data that was never logged at the data plane, or reaches a privileged role and impairs logging before acting. This page enables the logs that answer incident questions, centralizes them out of reach of project owners, and alerts on the changes CIS asks you to watch.

Baseline controls

Configure these once at the organization node so every current and future project inherits them. CIS IDs refer to the CIS GCP Foundations Benchmark v5.0.1.

ControlWhyHow to checkCIS / SCC
Enable Data Access logs for allServices, no exemptionsRecords reads and writes of datagcloud organizations get-iam-policy ORG_ID --format="yaml(auditConfigs)"CIS 2.1, AUDIT_LOGGING_DISABLED
Share Workspace or Cloud Identity audit logs with Google CloudAdmin console actions land in Cloud LoggingAdmin console: Account > Account settings > Legal and complianceCIS 2.2
Route all logs with an org-level aggregated sinkProject owners cannot erase the copygcloud logging sinks list --organization=ORG_IDCIS 2.3, LOG_NOT_EXPORTED
Lock retention on log destinationsLogs cannot be shortened or deletedgcloud logging buckets describe org-audit --location=LOCATION --project=prj-c-loggingCIS 2.4, LOCKED_RETENTION_POLICY_NOT_SET
Keep log storage buckets privateLogs leak names, IPs and queriesgcloud storage buckets get-iam-policy gs://BUCKETPUBLIC_LOG_BUCKET
Protect log buckets with CMEKKey control over stored logsgcloud logging buckets describe BUCKET_ID --location=LOCATIONn/a
Alert on ownership and audit config changesClassic persistence and evasion stepsgcloud logging metrics listCIS 2.5, CIS 2.6, OWNER_NOT_MONITORED, AUDIT_CONFIG_NOT_MONITORED
Alert on custom role changesHidden privilege in role editsgcloud logging metrics listCIS 2.7, CUSTOM_ROLE_NOT_MONITORED
Alert on firewall, route and network changesExposure and traffic redirectiongcloud logging metrics listCIS 2.8, CIS 2.9, CIS 2.10, FIREWALL_NOT_MONITORED
Alert on bucket IAM and Cloud SQL changesData exposure changesgcloud logging metrics listCIS 2.11, CIS 2.12, BUCKET_IAM_NOT_MONITORED, SQL_INSTANCE_NOT_MONITORED
Enable Cloud DNS logging on all VPCsExfiltration and C2 lookups visiblegcloud dns policies listCIS 2.13, DNS_LOGGING_DISABLED
Enable Cloud Asset InventoryConfig history and searchgcloud services list --enabled --filter=cloudassetCIS 2.14, CLOUD_ASSET_API_DISABLED

Audit log types

Cloud Audit Logs writes four streams for each project, folder and organization:

LogRecordsDefault stateDefault retention
Admin ActivityConfiguration and metadata changes (create VM, set IAM policy)Always on, cannot be disabled400 days in _Required
System EventGoogle-initiated changes (live migration, automatic actions)Always on400 days in _Required
Policy DeniedRequests denied by VPC Service Controls or organization policyOn, can be excluded30 days in _Default
Data AccessADMIN_READ (config reads), DATA_READ, DATA_WRITEOff, except BigQuery30 days in _Default

Admin Activity tells you someone changed a bucket's IAM policy. Only Data Access tells you someone downloaded every object in it, which is what you need when investigating data from cloud storage. Policy Denied logs are how you see VPC Service Controls blocks (see VPC Service Controls) and organization policy dry-run results (see Organization Policy).

Data Access audit logs

Enable them at the organization

CIS 2.1 asks for ADMIN_READ, DATA_READ and DATA_WRITE on all services with no exempted principals. That is the right default: start from everything and remove targeted high-volume, low-value streams, rather than enabling a few services and missing the one an attacker uses.

Audit configuration lives in the auditConfigs section of the IAM allow policy, is inherited and additive. Fetch the organization policy:

gcloud organizations get-iam-policy ORG_ID --format=yaml > org-iam.yaml

Add this block at the top level:

auditConfigs:
- auditLogConfigs:
  - logType: ADMIN_READ
  - logType: DATA_READ
  - logType: DATA_WRITE
  service: allServices

Apply it. The file contains an etag that stops you from overwriting a concurrent change:

gcloud organizations set-iam-policy ORG_ID org-iam.yaml

Manage the audit config in the same Terraform that manages organization IAM (google_organization_iam_audit_config), or an authoritative IAM apply may silently drop it.

Console: IAM & Admin > Audit Logs (select the organization).

Control cost without blind spots

Data Access logs are billed as ingested volume, and DATA_READ on a busy analytics bucket generates a lot. Do not exempt principals in exemptedMembers: an exempted admin group is a gift to an attacker who compromises one of its members. Instead, drop specific noisy streams with an exclusion on the _Default sink (for example, reads by one pipeline service account on one bucket) while the organization sink still sends a complete copy to the central bucket.

Verify

Generate an access (list objects in a bucket) and search for it:

gcloud logging read \
  'logName:"cloudaudit.googleapis.com%2Fdata_access" AND protoPayload.serviceName="storage.googleapis.com"' \
  --project=PROJECT_ID --limit=5 --freshness=1h

Workspace and Cloud Identity admin logs

Admin console actions (creating users, adding a super admin, changing 2-Step Verification policy) are recorded by Google Workspace or Cloud Identity, not by Google Cloud. CIS 2.2 asks you to share them with Google Cloud so they land next to your cloud audit logs. A super admin turns this on in the Admin console under Account > Account settings > Legal and compliance > Sharing options, by selecting Enabled.

Shared Admin events arrive as Admin Activity logs at the organization, and Login and SAML events as Data Access logs. Query them at organization scope:

gcloud logging read \
  'logName="organizations/ORG_ID/logs/cloudaudit.googleapis.com%2Factivity" AND protoPayload.serviceName="admin.googleapis.com"' \
  --organization=ORG_ID --limit=10

Alert on super admin grants and changes to sign-in security there, alongside the organization controls.

Centralized log storage

Organization aggregated sink

Logs that stay in each project can be excluded or allowed to expire by that project's owners. Route a copy of every log entry from every project to a dedicated logging project in the common folder, protected by a lien. CIS 2.3 asks for a sink with no filter, so all entries are exported; if cost forces a filter, keep at minimum all cloudaudit.googleapis.com logs.

Create the destination bucket with long retention and Log Analytics:

gcloud logging buckets create org-audit \
  --project=prj-c-logging \
  --location=europe-west1 \
  --retention-days=400 \
  --enable-analytics \
  --cmek-kms-key-name=projects/prj-c-kms/locations/europe-west1/keyRings/logging/cryptoKeys/org-audit

Create the sink at the organization with --include-children, so every current and future folder and project is covered:

gcloud logging sinks create org-all-logs \
  logging.googleapis.com/projects/prj-c-logging/locations/europe-west1/buckets/org-audit \
  --organization=ORG_ID \
  --include-children

Grant the printed writer identity permission on the destination:

gcloud projects add-iam-policy-binding prj-c-logging \
  --member="serviceAccount:WRITER_IDENTITY" \
  --role="roles/logging.bucketWriter"

Console: Logging > Log Router (at organization scope).

Lock retention

Once logs arrive, lock the bucket. Nobody, including project owners, can then reduce retention or delete the bucket before entries expire. Locking cannot be undone, so confirm the retention value first:

gcloud logging buckets update org-audit \
  --project=prj-c-logging --location=europe-west1 --locked

For multi-year archives at low cost, add a second sink to a Cloud Storage bucket with a locked retention policy, which is what CIS 2.4 and the LOCKED_RETENTION_POLICY_NOT_SET finding test:

gcloud storage buckets create gs://example-com-audit-archive \
  --project=prj-c-logging --location=EU \
  --uniform-bucket-level-access --public-access-prevention \
  --retention-period=7y

gcloud storage buckets update gs://example-com-audit-archive --lock-retention-period

Grant that sink's writer identity roles/storage.objectCreator on the bucket. Bucket Lock details are on the Cloud Storage page. A BigQuery dataset is a third destination when your detection team works in SQL.

CMEK for log buckets

Log buckets are encrypted by Google by default. To hold the key yourself, grant the Logging service agent of the project that owns the bucket access to a key in the same location, then create the bucket with --cmek-kms-key-name as above:

gcloud logging settings describe --project=prj-c-logging \
  --format="value(kmsServiceAccountId)"

gcloud kms keys add-iam-policy-binding org-audit \
  --project=prj-c-kms --location=europe-west1 --keyring=logging \
  --member="serviceAccount:KMS_SERVICE_ACCOUNT" \
  --role="roles/cloudkms.cryptoKeyEncrypterDecrypter"

To protect the _Default and _Required buckets of new projects too, set organization-wide Logging settings:

gcloud logging settings update --organization=ORG_ID \
  --storage-location=europe-west1 \
  --kms-key-name=projects/prj-c-kms/locations/europe-west1/keyRings/logging/cryptoKeys/default-logs

Disabling or destroying the key makes the logs unreadable, so keep the key project separate and restrict who can manage it (see Cloud KMS).

Restrict who reads logs

Data Access logs contain object names, query text and caller IPs. Reading them requires roles/logging.privateLogViewer; grant it to the auditors and security operations groups on the logging project only. Only the security admins group should hold roles/logging.configWriter at the organization.

Sinks and exclusions are attack surface

Exclusions and sink edits are the quiet way to blind you. An exclusion filter on a project's _Default sink drops matching entries before storage, and a sink filter edited to NOT logName:"cloudaudit" stops your central copy. The _Required bucket cannot be excluded, modified or deleted, so Admin Activity and System Event logs always keep 400 days in the source project, even if a sink is tampered with.

  • Review exclusions with gcloud logging sinks describe _Default --project=PROJECT_ID and organization sinks with gcloud logging sinks list --organization=ORG_ID.
  • Never exclude audit logs from the organization sink; apply cost exclusions only to project _Default sinks.
  • Alert on every sink, exclusion and bucket change (below).

CIS log metric alerts

CIS 2.5 to 2.12 require a log-based metric and an alerting policy for each change below. Because the organization sink writes into the central bucket, create bucket-scoped metrics there: they count every entry stored in the bucket, whatever project it came from.

CISMonitorFilter
2.5Project ownership changesprotoPayload.serviceName="cloudresourcemanager.googleapis.com" AND protoPayload.serviceData.policyDelta.bindingDeltas.role="roles/owner"
2.6Audit configuration changesprotoPayload.methodName="SetIamPolicy" AND protoPayload.serviceData.policyDelta.auditConfigDeltas:*
2.7Custom role changesresource.type="iam_role" AND protoPayload.methodName:("CreateRole" OR "DeleteRole" OR "UpdateRole" OR "UndeleteRole")
2.8Firewall rule changesresource.type="gce_firewall_rule" AND protoPayload.methodName:("compute.firewalls.insert" OR "compute.firewalls.patch" OR "compute.firewalls.delete")
2.9Route changesresource.type="gce_route" AND protoPayload.methodName:("compute.routes.insert" OR "compute.routes.delete")
2.10VPC network changesresource.type="gce_network" AND protoPayload.methodName:("compute.networks.insert" OR "compute.networks.patch" OR "compute.networks.delete")
2.11Cloud Storage IAM changesresource.type="gcs_bucket" AND protoPayload.methodName="storage.setIamPermissions"
2.12Cloud SQL configuration changesprotoPayload.methodName="cloudsql.instances.update"

Create a metric scoped to the central bucket:

gcloud logging metrics create audit-config-changes \
  --project=prj-c-logging \
  --bucket-name=projects/prj-c-logging/locations/europe-west1/buckets/org-audit \
  --description="CIS 2.6 audit configuration changes" \
  --log-filter='protoPayload.methodName="SetIamPolicy" AND protoPayload.serviceData.policyDelta.auditConfigDeltas:*'

Then attach an alerting policy on logging.googleapis.com/user/audit-config-changes with a threshold above zero, routed to your security channel (gcloud monitoring policies create --policy-from-file=policy.json, or Monitoring > Alerting in the console). Security Command Center's *_NOT_MONITORED findings check that these metrics and alerts exist.

DNS logging

Cloud DNS logging records queries from VMs and GKE nodes through the VPC resolver, which is where DNS tunnelling and command and control lookups show up. CIS 2.13 asks for it on every VPC network:

gcloud dns policies create dns-logging \
  --project=PROJECT_ID \
  --networks=NETWORK_NAME \
  --enable-logging \
  --description="Log DNS queries"

For a network that already has a DNS server policy, update it with gcloud dns policies update POLICY_NAME --enable-logging. VPC Flow Logs, firewall rule logging and load balancer logging are covered on the VPC page.

Cloud Asset Inventory

Audit logs tell you about changes; Cloud Asset Inventory tells you the state at any point in the last 35 days, and lets you search every resource and IAM binding across the organization. CIS 2.14 asks that it is enabled:

gcloud services enable cloudasset.googleapis.com --project=prj-c-security

gcloud asset search-all-iam-policies --scope=organizations/ORG_ID \
  --query="policy:allUsers OR policy:allAuthenticatedUsers"

gcloud asset search-all-resources --scope=organizations/ORG_ID \
  --asset-types="logging.googleapis.com/LogSink"

Export snapshots to BigQuery on a schedule for history beyond 35 days, and use real-time feeds to Pub/Sub for changes to critical asset types.

Logging and detection

Protect the logging configuration itself: alert on sink, exclusion and bucket changes at organization, folder and project scope.

protoPayload.serviceName="logging.googleapis.com"
protoPayload.methodName:("ConfigServiceV2.UpdateSink" OR "ConfigServiceV2.DeleteSink" OR "ConfigServiceV2.CreateExclusion" OR "ConfigServiceV2.UpdateExclusion" OR "ConfigServiceV2.UpdateBucket" OR "ConfigServiceV2.DeleteBucket")

Add alerts on the removal of Data Access configuration (the CIS 2.6 metric covers it) and on reads of the central bucket by unexpected principals. Security Command Center Premium's Event Threat Detection reads the same audit logs for threats such as anomalous IAM grants and data exfiltration; see Security Command Center. Security Health Analytics reports AUDIT_LOGGING_DISABLED, LOG_NOT_EXPORTED, LOCKED_RETENTION_POLICY_NOT_SET and PUBLIC_LOG_BUCKET when the baseline slips.

Common mistakes

  • Leaving Data Access logs off because of cost, then having no record of which objects or secrets were read during an incident.
  • Adding human users or admin groups to exemptedMembers to cut volume, which removes exactly the actors you most need to see.
  • Keeping audit logs only in the source projects, where an owner can exclude them and the _Default bucket drops them after 30 days.
  • Locking a log bucket before checking the retention value. A locked bucket cannot be unlocked or shortened.
  • Creating project-scoped log-based metrics in the logging project and expecting them to count entries delivered by the organization sink. Use bucket-scoped metrics.
  • Applying an authoritative IAM policy from Terraform that does not include auditConfigs, silently turning Data Access logging off.
  • Granting roles/logging.viewer broadly and assuming it hides Data Access logs while also granting roles/logging.privateLogViewer to application teams.

References

About the author

Security engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.

Related services

All services