OIDC from CI to the cloud

Intermediate · 28 min

Give a pipeline short-lived cloud credentials with OIDC instead of stored keys, write the trust policy in Terraform, and watch for GitHub's 2026 subject change.

Before thisAuthenticating providers without static keysTerraform in CI: saved plans and approvals

Integrations Ninjas · 28 min

OIDC from CI to the cloud

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Integrations NinjasReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • OIDC replaces a stored access key: the CI platform signs a token per job, and the cloud checks its claims against a trust policy before issuing credentials that last about an hour.
  • The sub condition is the security model: pin the full repository and, for production, the environment; a wildcard like repo:acme* also matches lookalike organisations.
  • GitHub repositories created after 15 July 2026 emit sub values with immutable owner and repo IDs, so trust policies copied from older tutorials may not match.
  • Terraform's S3 backend can use web identity (assume_role_with_web_identity or AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN), or you configure credentials in the environment first.

The key that never expires

The pipeline needs to talk to AWS, so someone creates an IAM user, generates an access key and pastes it into a repository secret. It works. A year later the key is still there. It belongs to someone who left. Every repository admin can read how it is used, every fork-triggered workflow is one mistake away from printing it, and rotating it means a coordinated change in every pipeline that holds a copy. A leaked key is valid from the moment it leaks until someone notices.

OIDC federation removes the stored secret. Instead of the pipeline holding a key, the CI platform vouches for each run: “this job is running in repository X, on branch Y, in environment Z,” in a signed token. The cloud trusts the platform’s signature, checks those claims against a rule you wrote, and hands the job a credential that lasts about an hour. The git-github lesson on deploying from Actions with OIDC covers the mechanism from the Actions side. This lesson is about the Terraform side: setting it up as code, scoping it so one repo cannot assume another’s role, and getting Terraform’s own backend to use the same credentials.

What the token says

GitHub publishes its OIDC configuration at a well-known URL, so anyone can see what a token can contain. I fetched it:

$ curl -s https://token.actions.githubusercontent.com/.well-known/openid-configuration | jq -c '{issuer, id_token_signing_alg_values_supported, claims_supported}'
{"issuer":"https://token.actions.githubusercontent.com","id_token_signing_alg_values_supported":["RS256"],"claims_supported":["sub","aud","exp","iat","iss","jti","nbf","ref","sha","repository","repository_id","repository_owner","repository_owner_id", ... ,"workflow","workflow_ref", ..., "environment", ... ]}

(I trimmed the middle of the claims list.) The signing keys are at the jwks_uri, and when I fetched it there were four RSA keys, all RS256. The cloud verifies the signature with those keys, so no shared secret exists. The claim that matters most is sub, the subject, which encodes where the job runs. aud, the audience, says who the token is for; for AWS it is sts.amazonaws.com.

Writing the trust relationship in Terraform

On AWS the pieces are an IAM OIDC provider for GitHub and a role whose trust policy lets that provider’s tokens assume it. From the AWS provider’s docs and the configure-aws-credentials README, not run by me:

resource "aws_iam_openid_connect_provider" "github" {
  url            = "https://token.actions.githubusercontent.com"
  client_id_list = ["sts.amazonaws.com"]
}

data "aws_iam_policy_document" "trust" {
  statement {
    actions = ["sts:AssumeRoleWithWebIdentity"]
    principals {
      type        = "Federated"
      identifiers = [aws_iam_openid_connect_provider.github.arn]
    }
    condition {
      test     = "StringEquals"
      variable = "token.actions.githubusercontent.com:aud"
      values   = ["sts.amazonaws.com"]
    }
    condition {
      test     = "StringEquals"
      variable = "token.actions.githubusercontent.com:sub"
      values   = ["repo:acme/infra:environment:production"]
    }
  }
}

resource "aws_iam_role" "terraform_prod" {
  name               = "terraform-prod"
  assume_role_policy = data.aws_iam_policy_document.trust.json
}

The AWS provider docs say that for GitHub, AWS relies on its own library of trusted root CAs and ignores any configured thumbprint_list, so you can leave it out. The role needs a permissions policy too, which is where least privilege matters. A role that can do anything makes OIDC a nicer way to give away the same power.

The condition is the whole security model

The trust policy’s sub condition is the only thing that decides which repositories and branches may become that role. Getting it wrong is easy, so I built a small evaluator for StringEquals and StringLike against example subjects, to see what each policy lets through. It is my own Python, standing in for IAM’s matching:

P1 = branch-only (old format): StringEquals repo:acme/infra:ref:refs/heads/main
P2 = branch-only (new format): StringEquals repo:acme@1001/infra@2002:ref:refs/heads/main
P3 = environment (new format): StringEquals repo:acme@1001/infra@2002:environment:production
P4 = wildcard repo (dangerous): StringLike repo:acme*

token sub                           P1      P2      P3      P4
push to main, old repo           ALLOW       -       -   ALLOW
push to main, new repo               -   ALLOW       -   ALLOW
pull request, new repo               -       -       -   ALLOW
prod environment, new repo           -       -   ALLOW   ALLOW
other repo in same org               -       -       -   ALLOW
lookalike org 'acme-evil'            -       -       -   ALLOW

P4 lets everything through, including the blog repository and an organisation called acme-evil, because repo:acme* is a prefix match. Pin the full repository and, for production, the environment. A pull request token has a different sub from a push to main (in the table it is pull_request), so a policy pinned to main or to an environment blocks plans from unreviewed branches. Use a second, read-only role for pull-request plans.

The subject format changed in 2026

This is the part older tutorials get wrong. GitHub’s changelog of 23 April 2026 says repositories created after 15 July 2026 get a sub that includes immutable owner and repository IDs, repo:octocat@123456/my-repo@456789:ref:refs/heads/main, instead of just names. The old form used mutable names, so a recycled name could let a new owner mint a token with a matching subject. Existing repositories keep the old format unless you opt in at organisation or repository level. After you opt in, the sub changes and any trust policy that matches the old format needs updating. The post suggests using a preview endpoint to prepare. The configure-aws-credentials README, v6.3.1 on 25 November 2026, carries the same note. So when you copy a trust policy from a video, check which format your repo emits, and fetch it rather than guess.

Terraform’s backend uses it too

The job’s credentials apply to the AWS provider and also to the S3 backend. If you assume a role for state access, the S3 backend docs list an assume_role block, and an assume_role_with_web_identity block that reads a token from web_identity_token_file or the AWS_WEB_IDENTITY_TOKEN_FILE variable, with AWS_ROLE_ARN for the role. The docs recommend environment variables for sensitive values, since an inline token can end up in the .terraform directory and plan files. In practice most workflows use the configure-aws-credentials action to put short-lived credentials in the environment, and both Terraform’s backend and provider pick them up.

The same idea exists elsewhere: Google Cloud workload identity federation, Azure federated credentials, and the earlier lesson on authenticating providers without static keys, which this lesson specialises for CI.

About the video

The embed is Integrations Ninjas’ “Terraform + GitHub Actions with OIDC: Provision AWS Infrastructure Without Access Keys”, 28 minutes 27 seconds, published July 2026. Its description says it builds a pipeline where a git push provisions an S3 bucket with temporary credentials, explains the GitHub-to-IAM trust handshake, and structures Terraform into a bootstrap part and the rest. It is recent, so it may already reflect the new subject format, but I did not watch it to check. It is AWS only and from a small channel. English was judged from the title, description, channel and its English auto-caption track. The same channel’s shorter, general video on GitHub-to-AWS OIDC is in deeper.

Where this fits

Credentials solved, a pipeline still needs a way to run a plan per pull request without writing it all yourself. Atlantis is the self-hosted answer.

Check yourself

  1. 01Why is a trust policy of repo:acme* dangerous?

    It is a prefix match, so any repository in the organisation, and any organisation whose name starts with acme, can assume the role.

  2. 02What changed in the GitHub OIDC sub claim for new repositories?

    It now includes immutable owner and repository IDs, as in repo:octocat@123456/my-repo@456789:ref:refs/heads/main, instead of only mutable names.

  3. 03Why use a separate read-only role for pull-request plans?

    A pull request token has a different subject from a push to main, and an unreviewed branch should be able to plan but never change infrastructure.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark