Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 1.4 KB

File metadata and controls

60 lines (48 loc) · 1.4 KB

GitHub Actions OIDC with AWS

Deploy to AWS without long-lived access keys. GitHub Actions authenticates via OIDC.

Steps

1. Create an OIDC identity provider in AWS

aws iam create-open-id-connect-provider \
  --url https://token.actions.githubusercontent.com \
  --client-id-list sts.amazonaws.com \
  --thumbprint-list 6938fd4d98bab03faadb97b34396831e3780aea1

2. Create an IAM role

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {
      "Federated": "arn:aws:iam::YOUR_ACCOUNT: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:your-org/your-repo:*"
      }
    }
  }]
}

3. Add to your workflow

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: ${{ vars.AWS_ROLE_ARN }}
          aws-region: us-east-1

4. Store the role ARN

Go to your repo → Settings → Environments → Add AWS_ROLE_ARN variable.

No AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY needed. Credentials are ephemeral and scoped to each workflow run.