Overview and What You Will Learn
In this lab, you will trigger administrative actions that generate Admin Activity audit logs, enable Data Access logging for a service, and query both log types to reconstruct exactly who did what and when - the foundational skill for any real security investigation.
Why This Matters in Production
A security incident requires answering "who deleted this IAM policy binding, and when" - a question that's impossible to answer without Audit Logs, since regular application logs have no visibility into administrative actions taken through the Console, gcloud, or the API. Audit Logs exist specifically to make this exact question answerable.
Core Principles
GCP Audit Logs come in distinct categories, and knowing which one to check matters as much as knowing Audit Logs exist at all.
+------------------------------------------+| Admin Activity Logs || Records configuration changes - who created, || modified, or deleted a resource || Always enabled, cannot be disabled |+------------------------------------------+| Data Access Logs || Records who read, modified, or accessed || actual data (e.g. who read this Cloud || Storage object) || Disabled by default for most services, || except for a few high-sensitivity ones |+------------------------------------------+| System Event Logs || Records actions Google Cloud itself took || automatically, not caused by a user action || (e.g. a live VM migration during maintenance) |+------------------------------------------+Detailed Step-by-Step Practical Lab
- Create a project:
gcloud projects create gcp-audit-lab-2026 --name="Audit Logs Lab"gcloud config set project gcp-audit-lab-2026gcloud services enable compute.googleapis.com storage.googleapis.com- Perform an administrative action - creating a VM - which automatically generates an Admin Activity log entry:
gcloud compute instances create vm-audit-test \ --zone=asia-south1-a \ --machine-type=e2-small \ --image-family=debian-12 \ --image-project=debian-cloud- Query the Admin Activity log to confirm this action was recorded:
gcloud logging read \ 'logName="projects/gcp-audit-lab-2026/logs/cloudaudit.googleapis.com%2Factivity" AND protoPayload.methodName="v1.compute.instances.insert"' \ --limit=5- Enable Data Access logging for Cloud Storage specifically, since it's disabled by default for most services:
cat > audit-policy.yaml << 'AUDITEOF'auditConfigs: - service: storage.googleapis.com auditLogConfigs: - logType: DATA_READ - logType: DATA_WRITEAUDITEOF gcloud projects get-iam-policy gcp-audit-lab-2026 --format=json > current-policy.json # gcloud projects set-iam-policy with the auditConfigs section included- Create a bucket and upload an object, then read it back - these actions will now generate Data Access log entries:
gcloud storage buckets create gs://audit-lab-bucket-2026 --location=asia-south1echo "test content" > test-file.txtgcloud storage cp test-file.txt gs://audit-lab-bucket-2026/gcloud storage cat gs://audit-lab-bucket-2026/test-file.txt- Query the Data Access log to see the read and write actions recorded:
gcloud logging read \ 'logName="projects/gcp-audit-lab-2026/logs/cloudaudit.googleapis.com%2Fdata_access"' \ --limit=10- Query specifically for who has been granted or modified IAM permissions - a common, high-value security investigation query:
gcloud logging read \ 'protoPayload.methodName="SetIamPolicy"' \ --freshness=7d- Clean up:
gcloud storage rm --recursive gs://audit-lab-bucket-2026gcloud compute instances delete vm-audit-test --zone=asia-south1-a --quietgcloud projects delete gcp-audit-lab-2026 --quietProduction Best Practices & Common Pitfalls
Common MistakeAssuming Data Access logs are captured by default the same way Admin Activity logs are. Admin Activity logs (configuration changes) are always enabled and cannot be turned off, but Data Access logs (who read or wrote actual data) are disabled by default for most services and must be explicitly enabled - a security investigation assuming data access history exists can be disappointed to find it was never being recorded.
TipEnable Data Access logging proactively for any service handling sensitive data, before an incident makes you wish you had that history - logs only exist from the point logging was actually enabled, never retroactively.
- Admin Activity logs cannot be disabled, by design - this is a deliberate guarantee that administrative actions are always auditable, regardless of any configuration choice.
- Route audit logs to a separate, access-restricted project or Log Sink for genuinely sensitive environments, so even someone with permissions in the audited project cannot tamper with or delete the audit trail of their own actions.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
gcloud logging read 'logName=".../cloudaudit.googleapis.com%2Factivity"' |
Query Admin Activity logs |
gcloud logging read 'logName=".../cloudaudit.googleapis.com%2Fdata_access"' |
Query Data Access logs |
gcloud logging read 'protoPayload.methodName="SetIamPolicy"' |
Find IAM policy change events specifically |
gcloud projects get-iam-policy --format=json |
View a project's IAM policy including audit configs |