PIVTR-D
RGoogle Cloud playbook · Identity and access

Backdoor service accounts, keys and IAM bindings

An attacker with a privileged identity adds access that survives the first clean-up: service accounts, keys, IAM bindings at any level, custom roles and impersonation grants. Some also deploy a function or scheduled job that runs as a privileged account, or add SSH keys to metadata. Save the IAM policies, then disable what the attacker created before you delete anything.

Look here

LogSearch for
Admin Activity audit log, IAMNew service accounts, keys and custom roles, and service accounts turned back on: google.iam.admin.v1.CreateServiceAccount, google.iam.admin.v1.CreateServiceAccountKey, google.iam.admin.v1.UploadServiceAccountKey, google.iam.admin.v1.EnableServiceAccount, google.iam.admin.v1.CreateRole, google.iam.admin.v1.UpdateRole
Admin Activity audit log, IAMGrants on a service account that add roles/iam.serviceAccountTokenCreator (getAccessToken, signBlob, signJwt) or roles/iam.serviceAccountUser (actAs): google.iam.admin.v1.SetIAMPolicy
Admin Activity audit log, Resource ManagerRole grants on the organization. The match ignores case. Repeat with --folder and --project: gcloud logging read 'protoPayload.serviceName="cloudresourcemanager.googleapis.com" AND protoPayload.methodName:"setIamPolicy"' --organization=<org-id> --freshness=30d
Cloud Asset InventoryEvery binding for one member: gcloud asset search-all-iam-policies --scope=organizations/<org-id> --query='policy:<member>'
Cloud Asset InventoryEvery Token Creator grant: gcloud asset search-all-iam-policies --scope=organizations/<org-id> --query='policy:roles/iam.serviceAccountTokenCreator'
Admin Activity audit log, Cloud Run functions and Cloud SchedulerFunctions and scheduled jobs created or changed to run as a privileged account: google.cloud.functions.v2.FunctionService.CreateFunction, google.cloud.functions.v2.FunctionService.UpdateFunction, google.cloud.scheduler.v1.CloudScheduler.CreateJob, google.cloud.scheduler.v1.CloudScheduler.UpdateJob
Admin Activity audit log, Compute EngineSSH keys and startup scripts in metadata: protoPayload.methodName:"setCommonInstanceMetadata" OR protoPayload.methodName:"setMetadata"
Security Command Center (Event Threat Detection, Premium or Enterprise tier)IAM and SSH key findings: Persistence: IAM Anomalous Grant, Persistence: Service Account Key Created Persistence: Project SSH Key Added, Persistence: GCE Admin Added SSH Key, Defense Evasion: Project-Level Service Account Token Creator Role Added Privilege Escalation: New Service Account is Owner or Editor

Contain

#Item
1Save IAM policies as evidence, and the same for folders and projects: gcloud organizations get-iam-policy <org-id> --format=json
2Disable service accounts the attacker created: gcloud iam service-accounts disable <sa-email>
3Disable keys created in the window: gcloud iam service-accounts keys disable <key-id> --iam-account=<sa-email>
4Remove impersonation grants. Repeat for roles/iam.serviceAccountUser: gcloud iam service-accounts remove-iam-policy-binding <sa-email> --member='<type>:<member>' --role=roles/iam.serviceAccountTokenCreator --all
5Remove bindings the attacker added at the organization. Use gcloud resource-manager folders and gcloud projects with the same flags: gcloud organizations remove-iam-policy-binding <org-id> --member='<type>:<member>' --role=<role> --all
6Pause attacker jobs: gcloud scheduler jobs pause <job> --location=<location>
7Record each function's runtime service account: gcloud functions describe <function> --region=<region>
8Remove attacker SSH keys from project and instance metadata, and attacker grants of roles/compute.osLogin or roles/compute.osAdminLogin

Eradicate and recover

#Item
1List custom roles. Repeat with --project: gcloud iam roles list --organization=<org-id>
2Read each custom role's permissions: gcloud iam roles describe <role-id> --organization=<org-id>
3Delete custom roles the attacker created destructive: gcloud iam roles delete <role-id> --organization=<org-id>
4Enable OS Login: gcloud compute project-info add-metadata --metadata=enable-oslogin=TRUE
5Enforce compute.requireOsLogin at the organization
6Block service account key creation where keys are not required: iam.managed.disableServiceAccountKeyCreation
7Block service account key upload where keys are not required: iam.managed.disableServiceAccountKeyUpload
8Re-run the Asset Inventory searches and compare policies with the saved copies
9Delete attacker service accounts after evidence is recorded destructive. Remove their bindings first: gcloud iam service-accounts delete <sa-email>
10Delete attacker functions destructive: gcloud functions delete <function> --region=<region>
11Delete attacker scheduled jobs destructive: gcloud scheduler jobs delete <job> --location=<location>
Watch out
  • A Token Creator or Service Account User grant at project level covers every service account in the project. Check project and folder policies as well as each service account's own policy.
  • A deleted service account stays in bindings with a deleted: prefix for up to 60 days. For 30 days gcloud iam service-accounts undelete <unique-id> restores it with its roles, using the 21-digit unique ID. Remove its bindings before deletion.
  • Token minting with getAccessToken and signBlob appears only in Data Access logs for iamcredentials.googleapis.com. Trace chains with impersonation and delegation.

Google Cloud documentation: IAM audit logging; Resource Manager audit logging; Cloud Run functions audit logging; Cloud Scheduler audit logging; Logging query language; Roles for service account authentication; Delete and undelete service accounts; Restrict IAM service account usage; Create and manage custom roles; gcloud reference for asset, organizations, resource-manager folders, iam service-accounts, scheduler, functions and compute project-info; Restrict SSH keys from VMs; SSH login access best practices; Security Command Center IAM and Compute Engine threat findings. Checked September 2026. Re-checked October 2026: Delete and undelete service accounts (30-day undelete, bindings purged within 60 days, unique ID); gcloud reference for iam service-accounts undelete (GA).

Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.