Sub topic 3
Putting It Together: A Deployment Workflow
Assume you know GitHub Actions jobs and steps, basic IAM roles and policies, JSON, YAML, and the AWS CLI. The workflow below requests a GitHub OIDC token and exchanges it for temporary AWS credentials.
A complete deployment workflow
name: deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
aws-region: us-east-1
- run: aws sts get-caller-identity
- run: aws s3 sync ./site s3://my-example-bucket --deleteThe IAM role needs a permissions policy containing only the deployment actions, such as the required S3 operations. Its trust policy should check both aud (sts.amazonaws.com) and sub, which identifies the repository and branch or environment.
flowchart TD
A[GitHub job] --> B[OIDC token]
B --> C[AWS STS]
C --> D[Temporary role credentials]
D --> E[AWS deployment]Production gates and reusable workflows
A GitHub environment named production can require approvals, restrict branches, and protect environment secrets before the job starts. The trust policy can require this subject:
repo:my-org/my-repo:environment:production
For a reusable workflow, inspect the OIDC subject and other supported claims before writing conditions. Do not assume that the calling workflow's branch claim has the same value as a direct workflow. Use GitHub's documented custom-claim format and test the resulting token.
> [!note] > A broad subject such as repo:my-org/my-repo:* allows every branch and environment in the repository. Use it only when that scope is intentional.
Diagnose role assumption failures
Check these items in order:
- The workflow has
id-token: write. - The IAM provider URL is exactly
https://token.actions.githubusercontent.com. - The audience is
sts.amazonaws.com. - The trust policy's
submatches the job's repository, ref, or environment. - The role ARN and AWS account are correct.
- The role's permissions policy allows the requested AWS operation.
aws sts get-caller-identity confirms which temporary identity the job received.
Credential lifetime and infrastructure as code
STS credentials expire. Set role-duration-seconds only within the role's allowed session duration, and keep sessions no longer than the deployment requires. Define the OIDC provider, trust policy, role, and permissions policy in CloudFormation or another infrastructure-as-code system. This makes changes reviewable and repeatable.
CloudTrail records AssumeRoleWithWebIdentity and later AWS API calls. Use the role session data and request time to connect a deployment to its GitHub run.
For multiple AWS accounts, create one narrowly scoped role per account. The workflow can assume the appropriate role for each deployment stage, while each account keeps its own permissions boundary.
Exercise
A job receives AccessDenied when calling STS. What should you inspect first?
Show answer
Confirm id-token: write, the provider and audience, and whether the trust policy's sub exactly matches the job.