
Keyless Deployments on AWS: Securing CI/CD with OpenID Connect (OIDC)
A practical guide to securing CI/CD pipelines on AWS using OpenID Connect (OIDC): configure IAM Identity Providers, construct scoped trust policies, and implement keyless deployments in GitHub Actions.
For years, automating cloud deployments from continuous integration platforms (such as GitHub Actions, GitLab CI, or CircleCI) required generating long-lived IAM access keys (
AKIA... ) and storing them as repository secrets.This model introduces substantial security liabilities: static keys do not expire automatically, are frequently neglected during credential rotation schedules, and present an immediate risk of exfiltration if secrets are exposed through build logs or misconfigured runner permissions.
By configuring OpenID Connect (OIDC) identity federation, teams eliminate persistent AWS credentials entirely. Pipelines exchange short-lived cryptographic identity tokens for temporary AWS Identity and Access Management (IAM) credentials valid only for the duration of the build step.
1. How OIDC Federation Works
Rather than verifying a static shared secret, AWS Security Token Service (STS) validates cryptographically signed JSON Web Tokens (JWTs) issued directly by your CI/CD provider:
[CI/CD Runner (e.g., GitHub Actions)] │ │ 1. Requests OIDC JWT token from CI provider ▼[CI/CD OIDC Identity Provider] │ │ 2. Issues signed JWT containing job metadata (repo, branch, commit) ▼[CI/CD Runner] │ │ 3. Invokes sts:AssumeRoleWithWebIdentity (passes JWT & Role ARN) ▼[AWS STS (Security Token Service)] │ ├── Validates JWT signature against configured IAM OIDC Provider ├── Evaluates IAM Role Trust Policy (Subject and Audience claims) ▼[AWS STS] ──► Returns temporary session credentials (AccessKey, SecretKey, SessionToken) │[CI/CD Runner] ──► Deploys infrastructure/code via AWS APIsThe returned credentials expire automatically (typically within 15 to 60 minutes) and require zero manual key rotation.
2. Configuring the IAM Role and Trust Policy
To establish trust between your AWS account and an external provider like GitHub Actions, create an IAM OpenID Connect identity provider referencing
[https://token.actions.githubusercontent.com](https://token.actions.githubusercontent.com) .Next, create an IAM deployment role with a trust policy that strictly validates the token claims to prevent unauthorized repositories from assuming your role:
JSON
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" }, "StringLike": { "token.actions.githubusercontent.com:sub": "repo:my-organization/payment-service:ref:refs/heads/main" } } } ]}Critical Claim Validations
-
aud(Audience): Must matchsts.amazonaws.com, verifying that the token was explicitly generated for AWS API consumption.
-
sub(Subject): Specifies the repository, environment, or Git reference authorized to assume the role. Restricting the subject claim prevents cross-repository token spoofing across your organization or external tenants.
3. Implementing the Workflow
In your CI/CD workflow configuration, request the OIDC token by granting the
id-token: write permission to the job, then leverage the official AWS credential helper to execute the token exchange:YAML
name: Deploy Production Infrastructure
on: push: branches: - main
permissions: id-token: write # Required to request the OIDC JWT token contents: read # Required to check out repository code
jobs: deploy: runs-step: ubuntu-latest steps: - name: Checkout Source uses: actions/checkout@v4
- name: Authenticate to AWS via OIDC uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/GitHubDeployProductionRole aws-region: us-east-1 role-session-name: GitHubActions-${{ github.run_id }} role-duration-seconds: 1200
- name: Run Terraform Deploy run: | terraform init terraform apply -auto-approve4. Hardening and Isolation Best Practices
Control | Implementation Strategy | Impact |
|---|---|---|
Branch & Environment Scoping | Bind trust policies to specific Git branches or CI environments (e.g., repo:org/app:environment:production ). | Prevents pull requests and staging feature branches from assuming production deployment permissions. |
Least Privilege Permissions | Attach scoped IAM permission policies tailored strictly to the resources modified by that pipeline. | Restricts blast radius if a dependency in the pipeline is compromised. |
Session Tracking | Set role-session-name to include ${{ github.actor }} or ${{ github.run_id }} . | Provides unambiguous CloudTrail audit logs connecting specific AWS API mutations back to the initiating commit and author. |
Auditing Identity Providers | Periodically audit IAM Identity Providers via AWS IAM Access Analyzer or AWS CLI. | Ensures retired providers or legacy third-party CI systems are promptly decommissioned. |
Eliminating static access keys closes one of the most critical identity gaps in modern continuous delivery pipelines. By marrying native OpenID Connect claims with tight AWS IAM trust boundaries, platform teams enforce ephemeral, least-privilege access across automated deployment systems without impeding developer velocity.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article