Overview
Curated: · Written: · Reviewed:
Secrets Management in Pipelines
In one line
Give each pipeline job a short-lived, narrowly scoped credential issued after it proves its identity, never a long-lived key sitting in source, logs, workspaces or runner disks. Reach for OIDC federation or a dedicated secret service whenever a job can touch production.
Key definitions
- OIDC federation: the CI platform signs a token describing the job, and the cloud checks issuer, audience and subject before issuing a session credential.
- sub claim: the identity the trust policy matches, such as
repo:acme/web:ref:refs/heads/mainorrepo:acme/web:environment:production. - Secret zero: the bootstrap identity a workload needs before it can fetch anything else.
- Lease and TTL: how long a dynamic credential lives. Renewal extends it, revocation ends it early.
- Response wrapping: a single-use token that unwraps once to the secret, so a copy of the wrapping token exposes it at most once.
- Untrusted-to-trusted boundary: the point where attacker-influenced code (fork PR code, dependencies, package scripts) shares a context with privileged material.
Formulas and complexity
The exposure window after exfiltration ends at the earlier of expiry or revocation:
With issue at 10:00, TTL 15 min, exfiltration at 10:07 and revocation at 10:50, exposure is min(10:15, 10:50) minus 10:07 = 8 minutes.
How it works
The job asks the CI platform for an OIDC token. The cloud validates the token's aud and sub against the role's trust policy. A match returns a session credential that expires at its TTL. A mismatch returns AccessDenied. Nothing is stored in the repository, and the credential dies with the job.
When to use and when not to
| Situation | Use | Avoid |
|---|---|---|
| Production cloud deploy | OIDC with an exact sub, bound to an environment or protected branch | Stored access key, or a repo:acme/* wildcard |
| Database access | Dynamic credentials fetched at use, with lease renewal | Static password in a Secret rotated by hand |
| Fork and PR tests | No secrets, no privileged token | pull_request_target that checks out and runs head code |
| Signing | KMS sign operation | Exporting the private key to a runner |
| Low-stakes value | CI-native secret store | Anything a production role can reach |
Traps interviewers probe
- Wildcard subject.
repo:acme/*:*lets any repository in the org assume the prod role. Fix:StringEqualson the exact sub, ideally the environment form. - Branch sub after moving to an environment. Once a job runs under an environment, its sub becomes
environment:production, so aref:refs/heads/mainmatch fails. Fix: update the trust policy to the environment sub. - Fetching once and holding forever. A service that reads a dynamic credential at startup breaks when the lease ends. Fix: fetch per lease, renew before expiry and reconnect on auth failure.
- Rotating the wrong secret. Rotating database passwords while the Vault token that fetches them never changes leaves the attacker a way back in. Fix: rotate and revoke the bootstrap identity too.
- Trusting the masker. Redaction matches exact registered values and misses encodings, splits and error dumps. Fix: keep secrets out of logs and treat redaction as defense in depth.
- Passing secrets on the command line or into images. Process listings show arguments, and image layers outlive the job. Fix: pass secrets through a runtime fetch or a file the job removes.
Interview tips
Open with the threat, not the product: "Fork PRs and dependencies are attacker-controlled, so whatever the job can reach is the blast radius. I start by deciding what each job can reach."
Expect these follow-ups:
- A malicious dependency runs in the build. It reads any token in the environment, so the answer is short TTL, a registry scope limited to one repo and deployment by digest, not tag.
- The OIDC trust policy has a wildcard. Write the exact
StringEqualssub and explain what the wildcard allowed. - A credential appeared in a build log. Revoke first, then review use in the audit log, then clean the log.
- The CI issuer is compromised. Revoke trust in the issuer, rotate the trust relationship, and fail new privileged jobs closed.
30-second outline: "Untrusted code runs in the pipeline, so I give each job only what its stage needs. Production jobs get OIDC credentials whose subject is pinned to the protected environment and whose TTL covers only the deploy. Secrets never enter source, logs or images. Dynamic credentials are fetched at use and renewed before expiry. I audit issuance and use, and I rotate the bootstrap identity on a schedule so a leaked token cannot outlive its purpose."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.