FIELD NOTESAWS · AZURE · GOOGLE CLOUD

Deploying from CI without long-lived cloud keys

Stored access keys turn a CI pipeline into a breach. OIDC federation replaces them with short-lived tokens, but only a narrowly scoped subject condition stops the trust policy recreating the same hole.

By Braxx-90003 min readPublished
ON THIS PAGE
Open original
Alpaca Mango technical archive cover art.

CI pipelines that deploy with stored cloud access keys are keeping a long-lived credential in the place most likely to receive untrusted code. Workload identity federation replaces the stored key with a short-lived token minted only after the CI system identifies itself, and the whole design stands or falls on one condition in the cloud's trust policy.

Take a repository we call acme/platform, which deploys from main and from release tags. The sub claim in the OIDC token carries that ref. A trust policy that accepts any subject containing repo:acme/platform lets a pull-request branch exchange its token for the deployment identity. Pin the subject to refs/heads/main and the tag release breaks with a failure that looks like the cloud is down. One condition too wide is a security failure; one condition too narrow is an availability failure that looks like an outage. The same sub claim takes two values, and the condition matches only one.

How the token is minted and checked#

In GitHub Actions, a workflow asks for an OIDC token by setting id-token: write and passing an audience. The token carries a sub claim identifying the repository and the branch, tag or environment, and an aud claim naming the receiving party. The cloud verifies the token against its OIDC provider, then evaluates the token's claims against the conditions you wrote in the trust policy.

  • AWS starts with a distraction: the console still shows a TLS certificate thumbprint when you create the OIDC provider, though for well-known providers such as GitHub, AWS now validates the certificate against its own trusted authorities instead. Either way, that check is about the endpoint, not about which repository is speaking. The decision sits in the IAM role's trust policy, where token.actions.githubusercontent.com:sub and :aud are matched with audience sts.amazonaws.com.
  • Azure matches a federated credential subject as a string. A credential scoped to repo:acme/platform:ref:refs/heads/main will not cover refs/heads/staging. The audience is api://AzureADTokenExchange. Create one credential per ref or environment you actually deploy from. That set grows multiplicatively with branches and environments, nothing prunes a credential when a branch is deleted, and the stale entries are invisible until someone audits.
  • Google Cloud maps the token into attributes such as google.subject, then selects a service account only when the attribute conditions pass. The audience is whatever you registered with the pool.

The allowlist is the boundary#

Treat the subject condition as an allowlist, not a pattern you expand until the failure stops. A trusted repository is not a trusted branch. A branch is identified by the git history; an environment name is assigned by whoever edits the workflow. A subject that matches only an environment name rather than a ref is weaker, because an attacker with workflow-write access can point that environment at a branch they control. Pin the subject to the ref you deploy from, and add an environment condition only where the environment itself is a security boundary.

Where OIDC does not help#

OIDC moves trust from a secret to the runner. If acme/platform runs on a self-hosted runner that executes jobs from people you do not control, every subject condition you write is only as good as that machine. In that case, do not retrofit OIDC and call the deployment boundary fixed; isolate the runner first, or use a deployment path that does not inherit the runner's identity. Otherwise the trust policy is doing all the work behind a boundary that is fiction.