Skip to main content
Intermediate Architecture & Engineering 10 min read GitHub Actions + AWS STS OIDC (DOP-C02)

GitHub Actions CI/CD with Keyless AWS OIDC Authentication

Replace risky static cloud secrets inside CI workflows using short-lived OIDC JWT tokens scoped strictly to your main branch.

Written by Ravi Shankar Mishra (Founder & Lead Systems Architect, MockAttempt Academy) Reviewed by MockAttempt Engineering Editorial Desk
Last updated: Verification Policy

Learning Objectives

  • Explain the OpenID Connect handshake between GitHub Actions `id-token: write` and AWS STS `AssumeRoleWithWebIdentity`.
  • Scope AWS IAM trust conditions (`sub: repo:org/name:ref:refs/heads/main`) to prevent forked PR credential theft.

Prerequisites

  • GitHub repository workflows basics and AWS IAM Roles familiarity

Why Static Cloud Keys in CI Settings Are Risky

Traditional CI tutorials paste permanent AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY credentials into repository secrets. If a token leaks or goes unrotated for months, attackers gain continuous API access across environments.

With OpenID Connect (OIDC), GitHub’s runner requests a short-lived signed JWT claiming exact repository, branch, and environment claims. AWS STS verifies the signature and mints temporary credentials expiring automatically once the job finishes.

Pair keyless CI/CD with Multi-Stage Docker Builds and our AWS Certified DevOps Engineer (DOP-C02) Program.

Practical Programming Examples

Keyless GitHub Actions Test + OIDC Cloud Role Workflow

Verify tests pass first, then request an OIDC token scoped only to main deployments without static cloud keys.

GitHub Actions + AWS STS OIDC
name: ci-deploy
on:
  push:
    branches: [main]

permissions:
  id-token: write
  contents: read

jobs:
  verify-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/github-oidc-deploy
          aws-region: ap-south-1
      - run: aws sts get-caller-identity
Expected Output
STS returns temporary assumed-role ARN (`github-oidc-deploy`) valid only for that job run.
Step-by-Step Execution
  1. `permissions: id-token: write` authorizes the runner to mint a scoped OIDC token.
  2. `configure-aws-credentials@v4` exchanges that JWT via AWS STS without needing `aws-access-key-id` secrets.

Common Mistakes to Avoid

  • Leaving trust-policy `sub` condition wildcarded (`repo:my-org/*`) — lets unrelated repos or PR branches assume deploy roles.

Production Best Practices

  • Lock IAM trust policy `StringEquals` strictly to `repo:ORG/REPO:ref:refs/heads/main` or dedicated protected environments.

Technical Interview Relevance

Standard DevOps/DOP-C02 security architecture design question.

Practice & Self-Check Questions

Which permission must a GitHub Actions workflow declare to exchange an OIDC token with AWS STS?

It must grant `id-token: write` (alongside `contents: read` for checkout).

Optional Next Step

Have Questions About Learning DevOps Structured Cohorts?

Request the AWS-SAA-C03 syllabus & weekend batch schedule from an Academic Counselor.

View AWS-SAA-C03 Details →
Learn. Practise. Prove. Get Career-Ready.

Ready to Build Your IT Career?

Explore industry-led programmes and develop practical skills through training, assessments and interview preparation.