
GCP Security Assessment and Enumeration
GCP security assessment methodology covering project enumeration, service account discovery, storage bucket exposure, and metadata API exploitation.
Introduction
GCP security is built around projects, service accounts and IAM bindings, not the policy documents AWS uses. Cloud IAM governs every API call, and what a compromised identity can reach depends on which roles it holds in which projects. Service accounts are the main target. They get attached to GCE instances, other accounts can impersonate them, and their JSON key files can be exported and used from anywhere on the internet.
From a compromised GCE instance, the metadata service at http://metadata.google.internal/computeMetadata/v1/ is the quickest pivot. One HTTP request gives you the attached service account, its access token and the project details. Unlike AWS IMDSv2 there is no session token exchange. The only protection is the required Metadata-Flavor: Google header, so any SSRF that lets you set request headers can read it.
How you got in decides where you start. From a compromised GCE instance you pull tokens directly from the metadata API. With a stolen service account JSON key, you authenticate with gcloud auth activate-service-account. With an OAuth token obtained via phishing or token theft, you configure it directly via gcloud config set auth/access_token_file. Each path lands in the same enumeration workflow once you have working credentials.
Authorization required
GCP assessments must have explicit written authorization covering the specific project IDs and services in scope. Cloud audit logs record every API call with caller IP and identity. Unauthorized enumeration against GCP projects violates Google's Terms of Service and triggers automated abuse detection.
Impact
- Service account with
roles/ownerorroles/editoron a project grants full control over all resources including billing, compute, and storage - Publicly readable Cloud Storage buckets expose data with no authentication and leave no trace in access logs unless Data Access audit logging is explicitly enabled
- Service account JSON keys don't expire unless rotated, so a leaked key file works until someone revokes it
- Workload Identity Federation misconfigurations allow external identities (GitHub Actions, AWS roles) to impersonate GCP service accounts
- Organization-level IAM policy mistakes propagate to every project under the org
- Cloud Functions and Cloud Run services running with overprivileged service accounts allow privilege escalation through code execution
- In older GCP environments the default compute service account has
roles/editoron the project, and GCE instances get that account by default
Technical details
GCP's IAM hierarchy flows from Organization → Folder → Project → Resource. Roles bound at a higher level inherit downward. The resourcemanager.projects.list permission lets you enumerate all projects visible to your identity, which is the first step in mapping the attack surface.
Service accounts exist in a specific project but can be granted roles in other projects. The IAM policy for a project (getIamPolicy) returns every principal with bindings, including external service accounts from other projects. Cross-project service account usage is a common lateral movement path.
Cloud Storage ACLs operate at two levels: the bucket ACL (legacy) and IAM policies. Uniform bucket-level access (UBL) disables per-object ACLs and centralizes control in IAM. When UBL is disabled, individual objects can be publicly accessible even if the bucket policy appears restricted.
The metadata endpoint returns short-lived access tokens (1-hour expiry) tied to the instance's bound service account. What the token can do is limited by the access scopes set when the instance was created. With the cloud-platform scope the token can call any GCP API, limited only by the service account's IAM roles.
Identify the initial access context
Work out how you have access before you start enumerating.
# With gcloud configured
gcloud auth list
gcloud config list
# With OAuth token (e.g., from SSRF or token theft)
curl -H "Authorization: Bearer $TOKEN" \
https://www.googleapis.com/oauth2/v1/tokeninfo
# Activate service account from JSON key
gcloud auth activate-service-account \
--key-file=/path/to/service-account-key.json
# Set project context
gcloud config set project <PROJECT_ID>Pull credentials from the GCE metadata service
From a compromised GCE instance, the metadata API gives you the attached service account identity and a live access token.
BASE="http://metadata.google.internal/computeMetadata/v1"
HDR='-H "Metadata-Flavor: Google"'
# Project info
curl -s $BASE/project/project-id $HDR
curl -s $BASE/project/numeric-project-id $HDR
# Instance info
curl -s $BASE/instance/name $HDR
curl -s $BASE/instance/zone $HDR
curl -s $BASE/instance/service-accounts/ $HDR
# Service account details
curl -s $BASE/instance/service-accounts/default/email $HDR
curl -s $BASE/instance/service-accounts/default/scopes $HDR
# Pull access token (expires in ~1 hour)
curl -s $BASE/instance/service-accounts/default/token $HDR
# Returns: {"access_token":"ya29.xxx","expires_in":3599,"token_type":"Bearer"}
# SSH keys and custom metadata
curl -s $BASE/instance/attributes/ $HDR
curl -s $BASE/instance/attributes/ssh-keys $HDRExport the token and use it directly for API calls:
TOKEN=$(curl -s http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token \
-H "Metadata-Flavor: Google" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
curl -H "Authorization: Bearer $TOKEN" \
"https://cloudresourcemanager.googleapis.com/v1/projects"Enumerate projects and the organization
Map the full scope of accessible resources.
# List all accessible projects
gcloud projects list --format="table(projectId,name,projectNumber,lifecycleState)"
# Organization discovery
gcloud organizations list
# Folders (requires resourcemanager.folders.list)
gcloud resource-manager folders list --organization=<ORG_ID>
# Project ancestors (full hierarchy)
gcloud projects get-ancestors <PROJECT_ID>IAM policy enumeration
IAM policies reveal every identity with access and what they can do.
# Project-level IAM policy
gcloud projects get-iam-policy <PROJECT_ID> \
--format=json > project-iam-policy.json
# Organization-level policy (high value if accessible)
gcloud organizations get-iam-policy <ORG_ID> \
--format=json > org-iam-policy.json
# List all service accounts in project
gcloud iam service-accounts list \
--project=<PROJECT_ID> \
--format="table(email,displayName,disabled)"
# Service account IAM policy (who can act as this SA)
gcloud iam service-accounts get-iam-policy <SA_EMAIL> \
--format=json
# Check for SA keys (key material exported externally)
gcloud iam service-accounts keys list \
--iam-account=<SA_EMAIL> \
--filter="keyType=USER_MANAGED"Parse the policy for overprivileged bindings:
# Find all bindings with primitive roles (owner/editor/viewer)
gcloud projects get-iam-policy <PROJECT_ID> \
--format=json | \
python3 -c "
import sys, json
p = json.load(sys.stdin)
for b in p.get('bindings', []):
role = b['role']
if 'owner' in role or 'editor' in role or 'admin' in role:
print(f'{role}:')
for m in b['members']:
print(f' {m}')
"
# Find allUsers / allAuthenticatedUsers bindings (public access)
gcloud projects get-iam-policy <PROJECT_ID> \
--format=json | \
grep -E "allUsers|allAuthenticatedUsers"Enumerate compute resources
# All instances across all zones
gcloud compute instances list --format="table(name,zone,status,serviceAccounts.email)"
# Instance details including startup scripts (may contain secrets)
gcloud compute instances describe <INSTANCE_NAME> \
--zone=<ZONE> \
--format=json
# Firewall rules — look for overly permissive ingress
gcloud compute firewall-rules list \
--format="table(name,direction,priority,sourceRanges,targetTags,allowed)"
# VPC networks
gcloud compute networks list
# Check for instances with public IPs and broad SSH access
gcloud compute firewall-rules list \
--filter="direction=INGRESS AND allowed.ports:22 AND sourceRanges:0.0.0.0/0"
# Cloud Run services (often publicly accessible)
gcloud run services list --platform=managed
# Cloud Functions
gcloud functions list
gcloud functions describe <FUNCTION_NAME> --format=jsonCloud Storage bucket enumeration and ACL audit
# List all buckets in project
gsutil ls -p <PROJECT_ID>
# Alternative with gcloud
gcloud storage buckets list --project=<PROJECT_ID> \
--format="table(name,location,storageClass,iamConfiguration.uniformBucketLevelAccess.enabled)"
# Check bucket ACL (legacy ACL, only relevant if UBL disabled)
gsutil acl get gs://<BUCKET_NAME>
# Check IAM policy on bucket
gsutil iam get gs://<BUCKET_NAME>
# Check if bucket allows public access
gsutil iam get gs://<BUCKET_NAME> | grep -E "allUsers|allAuthenticatedUsers"
# List bucket contents (if readable)
gsutil ls -la gs://<BUCKET_NAME>
# Recursive list (careful with large buckets)
gsutil ls -r gs://<BUCKET_NAME>/**
# Check object ACLs on specific file (when UBL is disabled)
gsutil acl get gs://<BUCKET_NAME>/<OBJECT_KEY>
# Download interesting files
gsutil cp gs://<BUCKET_NAME>/credentials.json ./
gsutil cp gs://<BUCKET_NAME>/terraform.tfstate ./Check for public access across all project buckets:
for bucket in $(gsutil ls -p <PROJECT_ID>); do
echo "=== $bucket ==="
gsutil iam get $bucket 2>/dev/null | grep -E "allUsers|allAuthenticatedUsers" \
&& echo " [!] PUBLIC ACCESS FOUND" || echo " [ok] Not public"
doneEnumerate enabled services and APIs
The list of enabled services shows you where to look next: BigQuery data, Kubernetes clusters, Secret Manager entries.
# All enabled services
gcloud services list --enabled \
--format="table(config.name,config.title)"
# Kubernetes clusters
gcloud container clusters list \
--format="table(name,location,status,currentMasterVersion)"
# Cloud SQL instances
gcloud sql instances list
# Cloud Spanner
gcloud spanner instances list
# Secret Manager secrets (names only — need secretmanager.versions.access for values)
gcloud secrets list --format="table(name,createTime,replication)"
# Access a secret version (requires secretmanager.versions.access)
gcloud secrets versions access latest --secret=<SECRET_NAME>
# BigQuery datasets
bq ls --project_id=<PROJECT_ID>
# Pub/Sub topics and subscriptions
gcloud pubsub topics list
gcloud pubsub subscriptions listTools
ScoutSuite automates multi-service configuration assessment and generates an HTML report with findings categorized by severity.
# Install
pip install scoutsuite
# Scan with application default credentials
scout gcp --user-account
# Scan with specific project
scout gcp --user-account --project-id <PROJECT_ID>
# Scan with service account key
scout gcp --service-account /path/to/key.json
# Generate report to specific directory
scout gcp --user-account --report-dir ./scoutsuite-report
# Scan specific services only
scout gcp --user-account --services iam,gcs,compute,cloudsql
# Skip specific services
scout gcp --user-account --skip cloudfunctions,cloudbuildScoutSuite checks for: public storage buckets, overprivileged service accounts, weak firewall rules, unencrypted resources, audit logging disabled, MFA enforcement, and OS Login configuration.
# ScoutSuite also outputs raw JSON
python3 -c "
import json
with open('scoutsuite-results/scoutsuite_results_gcp-<project>.js') as f:
# Strip the leading 'scoutsuite_results =' assignment
data = json.loads(f.read().split('=',1)[1].strip().rstrip(';'))
services = data.get('services', {})
for svc, svc_data in services.items():
findings = svc_data.get('findings', {})
for finding_id, finding in findings.items():
if finding.get('flagged_items', 0) > 0:
print(f'[{svc}] {finding[\"description\"]}: {finding[\"flagged_items\"]} items')
"Detection
GCP Cloud Audit Logs are the primary detection data source. There are three log types: Admin Activity (always on, no charge), Data Access (disabled by default, must be explicitly enabled per service), and System Event (automatic).
The big gap: without Data Access audit logging, reads from Cloud Storage, Secret Manager and other data services never show up in the logs. An attacker reading bucket contents or secrets leaves no trace.
# Admin Activity logs — always enabled
logName="projects/<PROJECT>/logs/cloudaudit.googleapis.com%2Factivity"
# Data Access logs — must be enabled
logName="projects/<PROJECT>/logs/cloudaudit.googleapis.com%2Fdata_access"
# System events
logName="projects/<PROJECT>/logs/cloudaudit.googleapis.com%2Fsystem_event"Key event types to alert on
| Event | Log source | Indicator |
|---|---|---|
GetIamPolicy from unexpected IP | Data Access | IAM policy dumping |
ListBuckets + ListObjects in sequence | Data Access (GCS) | Storage enumeration |
serviceAccounts.keys.create | Admin Activity | SA key exfiltration |
SetIamPolicy granting primitive roles | Admin Activity | Privilege escalation |
instances.setMetadata | Admin Activity | SSH key injection |
secrets.versions.access | Data Access | Secret exfiltration |
GenerateAccessToken (IAM Credentials API) by an unexpected principal | Data Access | Service account impersonation |
SIEM detection queries (Log Analytics or Chronicle)
-- Service account key creation — user-managed keys are persistent backdoors
SELECT
timestamp,
protoPayload.authenticationInfo.principalEmail AS actor,
protoPayload.resourceName AS service_account,
protoPayload.requestMetadata.callerIp AS source_ip
FROM
`<PROJECT>.cloudaudit_googleapis_com_activity`
WHERE
protoPayload.methodName = "google.iam.admin.v1.CreateServiceAccountKey"
AND protoPayload.request.privateKeyType = "TYPE_GOOGLE_CREDENTIALS_FILE"
ORDER BY timestamp DESC-- Alert when allUsers or allAuthenticatedUsers added to any IAM policy
SELECT
timestamp,
protoPayload.authenticationInfo.principalEmail AS actor,
protoPayload.resourceName AS resource,
protoPayload.request AS request_detail
FROM
`<PROJECT>.cloudaudit_googleapis_com_activity`
WHERE
protoPayload.methodName IN ("SetIamPolicy", "google.iam.v1.IAMPolicy.SetIamPolicy")
AND (
TO_JSON_STRING(protoPayload.request) LIKE '%allUsers%'
OR TO_JSON_STRING(protoPayload.request) LIKE '%allAuthenticatedUsers%'
)-- Metadata queries from non-GCE IPs (potential SSRF exploitation)
SELECT
timestamp,
protoPayload.authenticationInfo.principalEmail,
protoPayload.requestMetadata.callerIp,
protoPayload.methodName
FROM
`<PROJECT>.cloudaudit_googleapis_com_data_access`
WHERE
protoPayload.requestMetadata.callerIp NOT LIKE "10.%"
AND protoPayload.requestMetadata.callerIp NOT LIKE "172.16.%"
AND protoPayload.requestMetadata.callerIp NOT LIKE "192.168.%"
AND protoPayload.serviceName = "iamcredentials.googleapis.com"
AND protoPayload.methodName = "GenerateAccessToken"Behavioral indicators by attacker privilege level
| Attacker privilege | What it looks like |
|---|---|
| Viewer only | Bursts of Get* and List* calls across many services, typical of automated enumeration |
| Editor | serviceAccounts.keys.create with no matching deployment activity; instances.setMetadata adding SSH keys |
Owner or setIamPolicy | Role binding changes that add external accounts or primitive roles |
Remediation
IAM hardening
- Eliminate
roles/ownerandroles/editorbindings; replace with least-privilege custom roles or predefined roles scoped to specific resources - Enforce
constraints/iam.allowedPolicyMemberDomainsorg policy to prevent external account bindings - Disable service account key creation org-wide with
constraints/iam.disableServiceAccountKeyCreationunless operationally required - Enable
constraints/iam.disableServiceAccountKeyUploadto prevent importing external keys - Audit
iam.serviceAccounts.actAsbindings. This permission lets the holder run workloads as the target SA - Require Workload Identity Federation instead of exported JSON keys for non-GCP workloads
Compute hardening
- Do not use the default compute service account; create dedicated SAs with minimal permissions
- Disable access scopes that grant broad API access (
cloud-platformscope); specify only required scopes - Enable OS Login (
enable-oslogin=truemetadata) to use Cloud IAM for SSH instead of metadata-based keys - Enable Shielded VMs and Confidential Computing for sensitive workloads
- Block project-wide SSH key inheritance at instance level for sensitive instances
Storage hardening
- Enable Uniform Bucket-Level Access (UBL) on all buckets so per-object ACLs no longer apply
- Enable Public Access Prevention at org or bucket level
- Audit for
allUsersandallAuthenticatedUsersIAM bindings regularly - Enable Data Access audit logging for Cloud Storage in all production projects
- Use VPC Service Controls to restrict storage access to specific VPC networks
Audit logging
- Enable Data Access audit logs for: Cloud Storage, Secret Manager, BigQuery, IAM, Cloud KMS
- Export logs to a separate project with restricted access to prevent tampering
- Set log retention to minimum 400 days for compliance
- Alert on
SetIamPolicy,CreateServiceAccountKey, andAccessSecretVersionevents
Secret management
- Migrate all secrets from environment variables, startup scripts, and instance metadata to Secret Manager
- Rotate all service account keys; move to keyless auth where possible
- Scan GCS buckets and instance metadata for embedded credentials as part of regular audits
References
MITRE ATT&CK techniques
- T1526 - Cloud Service Discovery
- T1087.004 - Account Discovery: Cloud Account
- T1530 - Data from Cloud Storage Object
Tool documentation
- ScoutSuite - Multi-Cloud Security Auditing Tool
- enumerate-iam-gcp
- GCPBucketBrute
- gcloud CLI Reference
- GCP Metadata Server Documentation
- Cloud Audit Logs Documentation
- GCP IAM Roles Reference
- Workload Identity Federation
Next steps
AWS Security Assessment and Enumeration
Systematic methodology for AWS security assessments covering IAM analysis, S3 bucket enumeration, EC2 exploitation, and cloud-native attack techniques.
AWS IAM Privilege Escalation
AWS IAM privilege escalation techniques including policy exploitation, role assumption, and permission enumeration for cloud penetration testing.
AWS S3 Bucket Enumeration and Exploitation
Discovering and exploiting misconfigured Amazon S3 buckets including enumeration techniques, permission testing, and data exfiltration methods.
Container Security and Kubernetes Hardening
Container security including Docker escape techniques, containerization fundamentals, and hardening best practices for penetration testing and security assessments.
GCP IAM Privilege Escalation Techniques
GCP IAM privilege escalation paths including service account impersonation, binding escalation, and workload identity abuse.
Container Security
Container security including Docker escape techniques, containerization fundamentals, and hardening best practices for penetration testing and security assessments.