<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abraiz Bashir</title>
    <description>The latest articles on DEV Community by Abraiz Bashir (@abraizbashir).</description>
    <link>https://dev.to/abraizbashir</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4270848%2F7162240c-a1c2-430a-b476-440ebee67602.jpg</url>
      <title>DEV Community: Abraiz Bashir</title>
      <link>https://dev.to/abraizbashir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abraizbashir"/>
    <language>en</language>
    <item>
      <title>GitHub Actions to AWS with OIDC: deploying without a single access key</title>
      <dc:creator>Abraiz Bashir</dc:creator>
      <pubDate>Sat, 28 Nov 2026 13:59:41 +0000</pubDate>
      <link>https://dev.to/abraizbashir/github-actions-to-aws-with-oidc-deploying-without-a-single-access-key-3l1</link>
      <guid>https://dev.to/abraizbashir/github-actions-to-aws-with-oidc-deploying-without-a-single-access-key-3l1</guid>
      <description>&lt;p&gt;The classic way to deploy to AWS from CI goes like this: create an IAM user, generate an access key, paste it into your CI secrets, and hope it never leaks. Those keys don't expire. If one ends up in a log, a fork or an old laptop backup, someone has long-term access to your account until you notice.&lt;/p&gt;

&lt;p&gt;GitHub Actions doesn't need them. With OIDC, every workflow run asks AWS for credentials that last one hour, and AWS checks exactly which repo and branch is asking before it hands anything over.&lt;/p&gt;

&lt;p&gt;This is the first post in a series where I build one small project and grow its pipeline one step at a time. In this one I set up OIDC from scratch with Terraform, deploy a real app with it, and walk through the error that broke my very first run. Spoiler: GitHub now puts numeric IDs in the token, and my trust policy wasn't expecting them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I built
&lt;/h2&gt;

&lt;p&gt;DeployLog is a tiny API that records deployments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;POST /deployments&lt;/code&gt; saves one: service, version, commit, environment and who deployed it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GET /deployments?service=deploylog&lt;/code&gt; lists the latest 20&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The twist: the pipeline that deploys DeployLog writes its own record to it after every successful deploy. So every post in this series ends with real data you can query.&lt;/p&gt;

&lt;p&gt;The stack is Lambda (Python 3.13), API Gateway HTTP API and DynamoDB, deployed with Terraform from GitHub Actions. The repo has four parts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Path&lt;/th&gt;
&lt;th&gt;What it is&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;app/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The Lambda handler&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;bootstrap/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;One-time setup you apply yourself: OIDC provider, deploy role, state bucket&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;infra/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The app's infrastructure, applied only by CI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.github/workflows/deploy.yml&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The pipeline&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All the code is on GitHub at &lt;a href="https://github.com/MuhammadAbraiz/deploylog-aws" rel="noopener noreferrer"&gt;MuhammadAbraiz/deploylog-aws&lt;/a&gt;. The tag &lt;code&gt;step-01&lt;/code&gt; matches this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  How OIDC works between GitHub and AWS
&lt;/h2&gt;

&lt;p&gt;Four things happen at the start of every run:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The job has &lt;code&gt;id-token: write&lt;/code&gt; permission, so it can ask GitHub for a signed token (a JWT). The token says which repo, branch and workflow it came from.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;configure-aws-credentials&lt;/code&gt; action sends that token to AWS STS with &lt;code&gt;AssumeRoleWithWebIdentity&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;STS checks the signature against the GitHub OIDC provider registered in IAM. Then it checks the role's trust policy: does the token's audience (&lt;code&gt;aud&lt;/code&gt;) and subject (&lt;code&gt;sub&lt;/code&gt;) match the conditions?&lt;/li&gt;
&lt;li&gt;If both match, STS returns temporary credentials. Mine expire after one hour.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The only thing GitHub stores is the role ARN. That isn't a credential on its own, because only a token from this exact repo and branch can use it.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;sub&lt;/code&gt; claim does most of the work. It's a string like &lt;code&gt;repo:OWNER/REPO:ref:refs/heads/main&lt;/code&gt;, and your trust policy should match it exactly. Keep that format in mind, because it's where my first run went wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: the one-time bootstrap
&lt;/h2&gt;

&lt;p&gt;The pipeline can't create the role it uses to log in, so a few things have to exist first. I keep them in a separate &lt;code&gt;bootstrap/&lt;/code&gt; folder that I apply once from my own machine with admin credentials:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the GitHub OIDC provider in IAM&lt;/li&gt;
&lt;li&gt;the deploy role and its trust policy&lt;/li&gt;
&lt;li&gt;a permission boundary for any Lambda role the pipeline creates&lt;/li&gt;
&lt;li&gt;an S3 bucket and DynamoDB table for the app's Terraform state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The OIDC provider.&lt;/strong&gt; An AWS account can only have one provider per URL. The account I used already had one for GitHub, so instead of creating a duplicate I read it with a data source, behind a flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_openid_connect_provider"&lt;/span&gt; &lt;span class="s2"&gt;"github"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;count&lt;/span&gt;          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_oidc_provider&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt;            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://token.actions.githubusercontent.com"&lt;/span&gt;
  &lt;span class="n"&gt;client_id_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sts.amazonaws.com"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_openid_connect_provider"&lt;/span&gt; &lt;span class="s2"&gt;"github"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_oidc_provider&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;url&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://token.actions.githubusercontent.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ykwt7glk5i6ayp2stbd.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8ykwt7glk5i6ayp2stbd.webp" alt="The GitHub OIDC provider in IAM" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The trust policy.&lt;/strong&gt; This is the version I started with. It checks the audience and only allows the &lt;code&gt;main&lt;/code&gt; branch of one repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="s2"&gt;"aws_iam_policy_document"&lt;/span&gt; &lt;span class="s2"&gt;"trust"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRoleWithWebIdentity"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;principals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;type&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Federated"&lt;/span&gt;
      &lt;span class="n"&gt;identifiers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;oidc_provider_arn&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;test&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"StringEquals"&lt;/span&gt;
      &lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"token.actions.githubusercontent.com:aud"&lt;/span&gt;
      &lt;span class="n"&gt;values&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sts.amazonaws.com"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;test&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"StringEquals"&lt;/span&gt;
      &lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"token.actions.githubusercontent.com:sub"&lt;/span&gt;
      &lt;span class="n"&gt;values&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"repo:${var.github_repo}:ref:refs/heads/main"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The permission boundary.&lt;/strong&gt; The deploy role has to create an IAM role for the Lambda function. That's a classic privilege escalation path: a role that can create roles can create one with admin rights. So the deploy role may only create or change roles named &lt;code&gt;deploylog-lambda-*&lt;/code&gt;, and only if they carry this boundary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;sid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"LambdaRoleWithBoundary"&lt;/span&gt;
  &lt;span class="n"&gt;actions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"iam:CreateRole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"iam:PutRolePolicy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"iam:DeleteRolePolicy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"iam:AttachRolePolicy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"iam:DetachRolePolicy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;resources&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lambda_role&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;test&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"StringEquals"&lt;/span&gt;
    &lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"iam:PermissionsBoundary"&lt;/span&gt;
    &lt;span class="n"&gt;values&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;aws_iam_policy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lambda_boundary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;arn&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The boundary itself only allows &lt;code&gt;PutItem&lt;/code&gt; and &lt;code&gt;Query&lt;/code&gt; on the app's table, plus writing logs. Even if someone misused the pipeline, any Lambda role it creates can't do more than that.&lt;/p&gt;

&lt;p&gt;One &lt;code&gt;terraform apply&lt;/code&gt; created 8 resources. The outputs go into the GitHub repo settings: the role ARN and the state bucket name as secrets, and the lock table name as a variable. I keep the role ARN as a secret anyway, so the account ID never shows up in public logs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fem1ugid54rtfbuzzsi8q.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fem1ugid54rtfbuzzsi8q.webp" alt="Repository secrets: a role ARN and a bucket name, no AWS keys" width="800" height="575"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: the workflow
&lt;/h2&gt;

&lt;p&gt;The workflow runs on every push to &lt;code&gt;main&lt;/code&gt;. The part that matters for OIDC is small:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;   &lt;span class="c1"&gt;# lets the job request an OIDC token
&lt;/span&gt;  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v5&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;terraform_version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.14.8&lt;/span&gt;
          &lt;span class="na"&gt;terraform_wrapper&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Configure AWS credentials&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aws-actions/configure-aws-credentials@v6&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;role-to-assume&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AWS_ROLE_ARN }}&lt;/span&gt;
          &lt;span class="na"&gt;role-session-name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deploylog-${{ github.run_id }}&lt;/span&gt;
          &lt;span class="na"&gt;aws-region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;us-east-1&lt;/span&gt;
          &lt;span class="na"&gt;mask-aws-account-id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;mask-aws-account-id&lt;/code&gt; hides the account ID in the logs. My repo is public, so that matters.&lt;/p&gt;

&lt;p&gt;After that come &lt;code&gt;terraform init&lt;/code&gt;, &lt;code&gt;plan&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt; in the &lt;code&gt;infra/&lt;/code&gt; folder. The last step records the deployment. The &lt;code&gt;POST&lt;/code&gt; route uses IAM auth, so only signed requests get in. curl can sign the request itself with the session credentials the action just exported:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;api_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(terraform output -raw api_url)"&lt;/span&gt;
&lt;span class="nv"&gt;payload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'{"service":"deploylog","version":"%s","commit":"%s","environment":"prod","deployed_by":"%s"}'&lt;/span&gt; \
  &lt;span class="s2"&gt;"${GITHUB_SHA::7}"&lt;/span&gt; &lt;span class="s2"&gt;"$GITHUB_SHA"&lt;/span&gt; &lt;span class="s2"&gt;"$GITHUB_ACTOR"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

curl --fail-with-body -sS -X POST &lt;span class="s2"&gt;"$api_url/deployments"&lt;/span&gt; \
  --aws-sigv4 &lt;span class="s2"&gt;"aws:amz:${AWS_REGION}:execute-api"&lt;/span&gt; \
  --user &lt;span class="s2"&gt;"${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"x-amz-security-token: ${AWS_SESSION_TOKEN}"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"content-type: application/json"&lt;/span&gt; \
  -d &lt;span class="s2"&gt;"$payload"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the other side too: an unsigned &lt;code&gt;POST&lt;/code&gt; to the same URL gets &lt;code&gt;403 Forbidden&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: the first push, and AccessDenied
&lt;/h2&gt;

&lt;p&gt;I pushed to &lt;code&gt;main&lt;/code&gt;, and the first run failed at the credentials step, before Terraform even started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Could not assume role with OIDC: Not authorized to perform sts:AssumeRoleWithWebIdentity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffq4z88km57hk3nqkbu38.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffq4z88km57hk3nqkbu38.webp" alt="Run 1 failed at the credentials step" width="800" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This error tells you almost nothing. It means "the token didn't match the trust policy", but not which part. I went through the usual suspects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Audience:&lt;/strong&gt; the OIDC provider's client ID list had &lt;code&gt;sts.amazonaws.com&lt;/code&gt;. Fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trust policy:&lt;/strong&gt; &lt;code&gt;aud&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; conditions were there, repo and branch spelled correctly. Looked fine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permissions:&lt;/strong&gt; &lt;code&gt;id-token: write&lt;/code&gt; was set in the workflow. Fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything looked right, so I stopped guessing and asked AWS what it actually received. Every failed &lt;code&gt;AssumeRoleWithWebIdentity&lt;/code&gt; call is logged in CloudTrail, including the token's subject:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;aws cloudtrail lookup-events \
  --lookup-attributes &lt;span class="nv"&gt;AttributeKey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;EventName,AttributeValue=AssumeRoleWithWebIdentity \
  --max-results 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;userName&lt;/code&gt; field of the event is the exact &lt;code&gt;sub&lt;/code&gt; claim GitHub sent. It wasn't what my policy expected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Expected: repo:MuhammadAbraiz/deploylog-aws:ref:refs/heads/main
Received: repo:MuhammadAbraiz@98274826/deploylog-aws@1471642139:ref:refs/heads/main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GitHub had added a numeric ID after the owner and after the repo name.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: GitHub's immutable sub claim
&lt;/h2&gt;

&lt;p&gt;This isn't a bug. GitHub changed the default &lt;code&gt;sub&lt;/code&gt; format in 2026. According to &lt;a href="https://docs.github.com/en/actions/reference/security/oidc" rel="noopener noreferrer"&gt;GitHub's OIDC reference&lt;/a&gt;, repositories created after 15 July 2026 use a format that includes the owner ID and the repository ID. Older repos keep the old format unless you opt in at the organization or repository level. My repo was brand new, so it got the new one.&lt;/p&gt;

&lt;p&gt;The reason is a real attack. Names can be reused: if someone deletes or renames a repo, another account could create a repo with the old name and get a token with the same &lt;code&gt;sub&lt;/code&gt;. A trust policy that only checks names would happily trust it. The numeric IDs are assigned once and never reused, so a policy that checks them stays tied to the original repo.&lt;/p&gt;

&lt;p&gt;To fix it, you need two numbers. Both are public:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s https://api.github.com/repos/MuhammadAbraiz/deploylog-aws \
  &lt;span class="o"&gt;|&lt;/span&gt; jq &lt;span class="s1"&gt;'{owner_id: .owner.id, repo_id: .id}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I built the &lt;code&gt;sub&lt;/code&gt; from the names and IDs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"github_owner_id"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"98274826"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"github_repo_id"&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1471642139"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;repo_owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;github_repo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;repo_name&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;github_repo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;github_sub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"repo:${local.repo_owner}@${var.github_owner_id}/${local.repo_name}@${var.github_repo_id}:ref:refs/heads/main"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The condition now uses &lt;code&gt;values = [local.github_sub]&lt;/code&gt;. &lt;code&gt;terraform plan&lt;/code&gt; showed exactly one change, the &lt;code&gt;sub&lt;/code&gt; value in the trust policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ "token.actions.githubusercontent.com:sub" =
    "repo:MuhammadAbraiz/deploylog-aws:ref:refs/heads/main"
 -&amp;gt; "repo:MuhammadAbraiz@98274826/deploylog-aws@1471642139:ref:refs/heads/main"

Plan: 0 to add, 1 to change, 0 to destroy.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7bj995xj3fqa5yk107ad.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7bj995xj3fqa5yk107ad.webp" alt="The fixed trust policy with numeric IDs" width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have existing OIDC roles, check which format each repo sends before you rename or transfer anything. Per the same GitHub docs, renames and transfers after 15 July 2026 also move to the new format, which would break a name-only trust policy in exactly the way it broke mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  It works
&lt;/h2&gt;

&lt;p&gt;I applied the bootstrap change, pushed again, and run 2 went green in 1 minute 11 seconds. While I was in there I also bumped both actions to their Node 24 versions (&lt;code&gt;configure-aws-credentials@v6&lt;/code&gt; and &lt;code&gt;setup-terraform@v4&lt;/code&gt;), because run 1 had warned that Node 20 is deprecated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3yid51hdne7ne8kcksjv.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3yid51hdne7ne8kcksjv.webp" alt="Run 1 denied, run 2 deployed" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The credentials step now shows the job trading its GitHub token for an AWS session:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2fox86vvcbqesalljmgf.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2fox86vvcbqesalljmgf.webp" alt="Assuming role with OIDC" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Terraform created the table, the Lambda function and the API. Then the last step recorded the deployment:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsm9hvc6efghfkvpngy5x.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsm9hvc6efghfkvpngy5x.webp" alt="The pipeline records its own deployment" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the API has the record the pipeline wrote about itself:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz51hn3krka18qlbee656.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz51hn3krka18qlbee656.webp" alt="GET /deployments returns the record" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pipeline never stores or relies on long-lived AWS access keys. Admin credentials were used once, from my own machine, for the bootstrap. The only long-lived thing in GitHub is a role ARN that nothing outside &lt;code&gt;main&lt;/code&gt; of this one repo can use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;p&gt;If you're setting this up yourself, these are the things I'd check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Match both &lt;code&gt;aud&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; with &lt;code&gt;StringEquals&lt;/code&gt;.&lt;/strong&gt; A trust policy that only checks the audience trusts every GitHub repo in the world.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pin the branch&lt;/strong&gt; (or a GitHub environment) in the &lt;code&gt;sub&lt;/code&gt;, not just the repo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check which &lt;code&gt;sub&lt;/code&gt; format your repo sends.&lt;/strong&gt; New repos send the IDs. Older repos switch when renamed or transferred.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When you get AccessDenied, read CloudTrail.&lt;/strong&gt; The &lt;code&gt;userName&lt;/code&gt; of the &lt;code&gt;AssumeRoleWithWebIdentity&lt;/code&gt; event is the exact &lt;code&gt;sub&lt;/code&gt; GitHub sent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reuse the account's OIDC provider.&lt;/strong&gt; There can only be one per URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Put a permission boundary on any role your pipeline can create.&lt;/strong&gt; Otherwise the deploy role is one step away from admin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mask the account ID&lt;/strong&gt; with &lt;code&gt;mask-aws-account-id: true&lt;/code&gt; if your logs are public.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The pipeline still locks Terraform state with a DynamoDB table, the classic setup. Terraform can now lock state in S3 directly, so a later post in this series removes that table. Next week, though, is re:Invent, and I'll write about what's new for people who maintain pipelines.&lt;/p&gt;

&lt;p&gt;The full code is in &lt;a href="https://github.com/MuhammadAbraiz/deploylog-aws" rel="noopener noreferrer"&gt;deploylog-aws&lt;/a&gt; on GitHub, tag &lt;code&gt;step-01&lt;/code&gt;. If you hit a different OIDC error, leave a comment with what CloudTrail showed and I'll take a look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/actions/reference/security/oidc" rel="noopener noreferrer"&gt;GitHub Docs: OpenID Connect reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.blog/changelog/2026-04-23-immutable-subject-claims-for-github-actions-oidc-tokens" rel="noopener noreferrer"&gt;GitHub Changelog: Immutable subject claims for GitHub Actions OIDC tokens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/aws-actions/configure-aws-credentials" rel="noopener noreferrer"&gt;aws-actions/configure-aws-credentials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/hashicorp/setup-terraform" rel="noopener noreferrer"&gt;hashicorp/setup-terraform&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://builder.aws.com/content/3Mb4iNM61J1mM9R3s5bOJYllrbl/github-actions-to-aws-with-oidc-deploying-without-a-single-access-key" rel="noopener noreferrer"&gt;AWS Builder Center&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>githubactions</category>
      <category>terraform</category>
      <category>security</category>
    </item>
  </channel>
</rss>
