OpenID Connect (OIDC) allows GitHub Actions workflows to access AWS resources securely. Previously, this required storing credentials as GitHub secrets, but OIDC offers a more dynamic and secure approach. In my case, I’m building a Terraform CI/CD pipeline to deploy AWS infrastructure using GitHub Actions.
Create IAM OIDC identity provider
- Go to AWS IAM -> Identity providers
- Click Add provider -> Provider type -> OpenID Connect
- Set the Provider URL and Audience
- For the provider URL: Use
https://token.actions.githubusercontent.com- For the Audience: Use
sts.amazonaws.comif you are using the official action.
- Click Add provider
Create IAM role
- Go to AWS IAM -> Roles
- Click Create role -> Trusted entity type -> Web Identity
- Select
token.actions.githubusercontent.comfor Identity provider- For the identity provider, select
token.actions.githubusercontent.com - For the audience, select
sts.amazonaws.com - Fill in GitHub organization, GitHub repository, and GitHub branch.
- For the identity provider, select
- Choose necessary policies to attach to the role.
- Fill in Role details and click Create role
Update GitHub Actions Workflow
Update workflow to assume the IAM role.
jobs:
plan:
name: Terraform Plan
runs-on: ubuntu-latest
permissions:
id-token: write
...
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::12345678:role/github-oidc-role
aws-region: ap-northeast-2
...