Lesson 6 of 12 · 15m
CI Secrets and OIDC
Stored cloud keys in CI are standing credentials waiting for a leak; OIDC federation and environment gates replace them with short-lived proof of what ran.
A GitHub Actions job that deploys to AWS used to mean an IAM user with AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY stored as repository secrets — a standing credential, valid until someone rotates it, readable by every workflow run on that repo, and forkable into any fork's context if the triggers are careless. GitHub masks registered secrets in logs with ***, but the masking is literal string matching over complete values: echo $KEY | base64, echo ${KEY:0:4} in a loop, tr character-rotated, even the raw value with a newline injected — all of it sails through unmasked. The masking is a courtesy filter for accidents, not a control. The defense is not a better mask. It is not storing the key.
pull_request_target: the loaded footgun
pull_request events from forks get a read-only GITHUB_TOKEN and no secrets — safe by construction. pull_request_target runs in the base repo's context: real secrets, a write-capable token. It exists for labeling and commenting on PRs — GitHub's own docs say it should only ever operate on the PR metadata, never on the PR's code. The trap: checking out the PR's code under pull_request_target runs attacker-controlled code with your secrets in its environment. Every "checkout fork head + run tests" recipe under that trigger is a secrets exfiltration pipeline with a friendly name, and it has been the entry point for real supply-chain attacks on repos that should have known better.
March 2025 made this concrete. tj-actions/changed-files had its release tags rewritten by a compromised PAT; the poisoned action dumped the runner's process memory — which held every secret loaded into the job — as base64 into public workflow logs across roughly 23,000 repositories (CVE-2025-30066). The lesson isn't only about one action: a mutable tag is a standing trust decision you re-approve on every run.
OIDC: proof instead of possession
The mechanism replacing stored keys:
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy-from-ci
aws-region: us-east-1id-token: write lets the job request a signed JWT from GitHub's OIDC issuer (token.actions.githubusercontent.com) attesting repo, ref, environment, actor, workflow, and more. AWS STS's AssumeRoleWithWebIdentity verifies the signature against GitHub's published JWKS, checks the audience (sts.amazonaws.com), evaluates the role's trust policy — which should pin the subject to something like repo:org/repo:environment:prod or repo:org/repo:ref:refs/heads/main — and mints credentials that expire in about an hour. A token minted for the wrong ref, a fork, or a different environment simply fails the trust evaluation; there is nothing to leak because there is nothing stored — the job proves what it is and the cloud hands back access that dies before the run ends. GCP (google-github-actions/auth with Workload Identity Federation) and Azure (azure/login with federated credentials on a managed identity) implement the same pattern with the same shape: an OIDC assertion in, short-lived access out.
Concrete practice
- No long-lived cloud keys in repo or org secrets. OIDC role assumption or a self-hosted runner's instance identity — pick per platform.
- Pin every third-party action to a full-length commit SHA:
uses: tj-actions/changed-files@<sha>; tags are mutable, SHAs are not. permissions:per job, minimal.id-token: writeonly on the jobs that assume roles.- Production goes through an
environment:with required reviewers — the OIDC subject includes it, so the trust policy enforces the approval, not just the UI. - Fork PRs that need secrets don't get
pull_request_target+ checkout. Run them onpull_requestwith no secrets, or gate with an environment approval.
A stored CI credential is a credential that will eventually run attacker code. Federation makes the workflow itself the credential — and the only thing left to guard is which workflows are allowed to prove it.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
RSA Is Simple. Deploying RSA Correctly Almost Never Is.
The capstone to our RSA series. The math checks out. Shipping it as written gets you breached. This is the nineteen-year-old attack that proves it, and what belongs in production instead.
RSA in JavaScript Part 2: The JWT Is Where You'll Actually Meet It
Most JavaScript developers never call an RSA function directly. They verify an RS256 token, and two classic attacks turn that into an authentication bypass — both demonstrated here, both fixed by one line.
Implementing RSA, AES-GCM, and a TLS 1.3 Handshake from Scratch in Python
What is Encryption? The Math That Keeps Your Data Private
Encryption transforms readable data into unreadable ciphertext that only someone with the right key can reverse. It's what makes HTTPS, messaging apps, banking, and password storage work. Here's how it actually functions.