AWS Builder Center

Ditch Long-Lived AWS Keys: GitHub Actions OIDC Deployments

How to build a credential-free CI/CD authentication workflow using GitHub Actions, AWS IAM Identity Providers, and temporary security credentials.

1. Introduction

The traditional way to deploy to AWS from GitHub Actions is to create an IAM user, generate an access key pair, and paste both halves into repository secrets. It works, and it carries four problems.
Exposure. A static key is valid from every network until someone deactivates it. It can leak through a compromised workflow dependency, a debug step that dumps the environment, a malicious pull request that exfiltrates secrets, or a laptop where the key was first created. Secret masking in logs only catches the exact string, not a base64 or reversed copy.
Rotation. Rotation depends on humans remembering. In practice keys live for years and are copied across repositories, so nobody knows which workflows still use the old key. Rotating becomes risky, so it doesn't happen.
Excess permissions. The key belongs to an IAM user whose policy tends to grow ("just add S3 full access"). It is also usable from anywhere, not just from your pipeline. Nothing ties the credential to a specific repository, branch, or approval.
Weak attribution. Every action from every workflow looks like the same IAM user in CloudTrail. You can't tell which repository, ref, or run made a call.
OpenID Connect (OIDC) federation replaces the stored secret with a short-lived identity assertion. Each workflow run asks GitHub for a signed token describing the run: which repository, which ref or environment, which workflow. AWS verifies that token and exchanges it for temporary credentials, but only if the IAM role's trust policy matches the claims. Nothing long-lived is stored in GitHub, so there is nothing to rotate or leak.

2. Understanding the architecture

Figure 1: end-to-end flow
flowchart LR
subgraph GH["GitHub"]
R["Repository<br/>OWNER/REPO"] --> W["Actions workflow run<br/>job has id-token: write"]
W -- "1. request ID token<br/>(audience = sts.amazonaws.com)" --> P["GitHub OIDC provider<br/>token.actions.githubusercontent.com"]
P -- "2. signed JWT<br/>(iss, aud, sub, repository, ...)" --> W
end
subgraph AWS["AWS account"]
IDP["IAM OIDC identity provider<br/>(trusts GitHub as an issuer)"]
ROLE["IAM role<br/>trust policy: aud + sub conditions<br/>+ permissions policy"]
STS["AWS STS<br/>AssumeRoleWithWebIdentity"]
SVC["AWS service<br/>(for example Amazon S3)"]
end
W -- "3. AssumeRoleWithWebIdentity<br/>(role ARN + JWT)" --> STS
STS -- "verify signature using<br/>provider's published keys" --> IDP
STS -- "evaluate trust policy" --> ROLE
STS -- "4. temporary credentials<br/>(access key, secret, session token)" --> W
W -- "5. signed API calls<br/>with temporary credentials" --> SVC
If your publishing platform does not render Mermaid, export the diagram as an image (the Mermaid Live Editor does this) and upload the PNG.
Components
  • Repository and workflow run. The unit being authenticated is a job in a run, not a person or a repository in the abstract. Facts about that job (ref, environment, workflow file) become claims in the token.
  • GitHub OIDC provider. Issues a signed JWT with  iss  set to  https://token.actions.githubusercontent.com . A job can only request a token if it has  permissions: id-token: write . That permission only allows fetching a token and grants no access to repository contents.
  • Token claims that matter.  aud  (who the token is for),  sub  (who or what the job is), and supporting claims such as  repository ,  repository_id ,  repository_owner_id ,  ref ,  environment , and  job_workflow_ref .
  • IAM OIDC identity provider. A one-time registration in your AWS account that says "tokens from this issuer are acceptable inputs to  AssumeRoleWithWebIdentity ." There is one per issuer URL per account.
  • IAM role trust policy. The real gate. It names the identity provider as a federated principal and sets conditions on  aud  and  sub . The provider alone grants nothing, because any GitHub repository in the world can obtain a validly signed token.
  • AWS STS. Validates the token signature and expiry, checks the trust policy, and returns temporary credentials (access key ID, secret key, session token) scoped to the role's permissions policy.
  • Permissions policy. What the role can do once assumed. Trust answers "who may become this role" and permissions answer "what can the role do." Both need to be tight.
Flow in words. The  aws-actions/configure-aws-credentials  action requests a token from GitHub with audience  sts.amazonaws.com . It calls STS  AssumeRoleWithWebIdentity  with the role ARN and the token. STS validates the token and the trust policy and returns credentials. The action exports them as environment variables for later steps and masks them in logs.

3. Prerequisites

  • AWS account where you can create IAM identity providers, roles, and an S3 bucket. For a first run use a sandbox account, not production.
  • IAM permissions for setup (human, one-time):  iam:CreateOpenIDConnectProvider ,  iam:CreateRole ,  iam:PutRolePolicy , and  s3:CreateBucket  and related bucket settings. Use your normal admin or platform role, ideally via IAM Identity Center rather than a long-lived user key.
  • AWS CLI v2, authenticated for setup.
  • GitHub repository where you can edit workflows, create environments, and set variables. Optional: the  gh  CLI for looking up IDs.
  • Region: pick one (placeholder  <AWS_REGION> ).
  • Cost. To the best of my knowledge, IAM identity providers, roles, and STS requests have no direct charge. Check the AWS pricing pages to confirm. The demo uses one small S3 bucket, so storage and request costs should be a few cents or less. GitHub Actions minutes depend on your plan and on whether the repo is public or private, so check GitHub's billing docs.

4. Implementation, step by step

Placeholders appear as  <LIKE_THIS> . Replace them all. Nothing here is a real account, ARN, or bucket.

Step 1: Create the IAM OIDC identity provider

First check whether your account already has one, since only one per issuer URL is allowed:
aws iam list-open-id-connect-providers
If  token.actions.githubusercontent.com  is not listed:
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com
  •  --url  is the token issuer. It must match the token's  iss  exactly.
  •  --client-id-list  registers the audience AWS will accept.  sts.amazonaws.com  is what the AWS action requests by default.
  • No thumbprint is needed for GitHub. If your CLI version insists on one, check  aws iam create-open-id-connect-provider help  and AWS's current guidance.

Step 2: Create the role and policies

Look up the IDs you need for the trust policy. They are used in the immutable  sub  format:
gh api repos/<GITHUB_OWNER>/<REPO_NAME> --jq '{repo_id: .id, owner_id: .owner.id}'
# Preview the exact subject prefix GitHub will use for this repository:
gh api repos/<GITHUB_OWNER>/<REPO_NAME>/actions/oidc/customization/sub
Use the  sub_claim_prefix  value from the second call rather than hand-assembling the subject.
 iam/trust-policy.json 
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowGitHubActionsProductionEnvironmentOnly",
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<AWS_ACCOUNT_ID>:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:<GITHUB_OWNER>@<GITHUB_OWNER_ID>/<REPO_NAME>@<REPO_ID>:environment:production"
}
}
}
]
}
 iam/permissions-policy.json  (deploys to one bucket and nothing else)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListTheSiteBucket",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<BUCKET_NAME>"
},
{
"Sid": "WriteObjectsToTheSiteBucket",
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::<BUCKET_NAME>/*"
}
]
}
Create the bucket (private) and the role:
# Bucket. In us-east-1 omit --create-bucket-configuration.
aws s3api create-bucket --bucket <BUCKET_NAME> --region <AWS_REGION> \
--create-bucket-configuration LocationConstraint=<AWS_REGION>
aws s3api put-public-access-block --bucket <BUCKET_NAME> \
--public-access-block-configuration \
BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

# Role
aws iam create-role --role-name github-actions-oidc-s3-deploy \
--assume-role-policy-document file://iam/trust-policy.json \
--max-session-duration 3600
aws iam put-role-policy --role-name github-actions-oidc-s3-deploy \
--policy-name s3-deploy-single-bucket \
--policy-document file://iam/permissions-policy.json
The bucket stays private on purpose. Serving it publicly is a separate concern, and S3 website endpoints require a public bucket. For a real site, put CloudFront with Origin Access Control in front of a private bucket.

Step 3: The trust policy, line by line

  •  "Effect": "Allow"  +  "Action": "sts:AssumeRoleWithWebIdentity" : the only action this role can be assumed with. It is the web-identity variant of AssumeRole, which is the API the AWS action calls.
  •  "Principal": {"Federated": ".../oidc-provider/token.actions.githubusercontent.com"} : restricts who is asking to tokens issued by the provider you registered in Step 1. Without further conditions this still means any GitHub repository.
  •  StringEquals  on  :aud : requires the token's audience to be exactly  sts.amazonaws.com . This prevents a token minted for a different relying party from being replayed against AWS. Use  StringEquals , not  StringLike , so there is no wildcard room.
  •  StringEquals  on  :sub : the claim that makes the policy useful. It pins the token to one owner ID, one repository ID, and one deployment context. This is where most OIDC mistakes happen.
The two  sub  formats
GitHub changed its default subject format. Use exactly the format your repository emits.
Repo state
 sub  for a job using the  production  environment
Created before 15 Jul 2026, not opted in
 repo:OWNER/REPO:environment:production 
Created after 15 Jul 2026, renamed or transferred after that date, or opted in
 repo:OWNER@OWNER_ID/REPO@REPO_ID:environment:production 
The immutable format exists to prevent name-recycling attacks: if an org is deleted and its name is claimed by someone else, a name-only subject would match the new owner. Do not list both formats in one policy, because that keeps the weaker name-based match alive. Confirm the exact subject with the debug workflow in section 8 before relying on it.
Branch vs environment restrictions. GitHub builds the  sub  from the job context, and:
  • a job with an environment gets  ...:environment:NAME  and no branch component;
  • a job without an environment, running on a branch push, gets  ...:ref:refs/heads/BRANCH ;
  • a  pull_request  job without an environment gets  ...:pull_request .
If you write a trust policy for  ref:refs/heads/main  but your job declares  environment: production , the token's  sub  will not match and assumption fails. Choose one model:
  • Environment model (used here, recommended): trust  environment:production  and restrict which branches can deploy to that environment in GitHub's environment settings (deployment branch rules).
  • Branch model: no environment on the job, trust  ...:ref:refs/heads/main .
Least privilege. The permissions policy names one bucket and three actions. Resist  s3:*  and  Resource: "*" . If  aws s3 sync  fails on a missing permission, add only what the error names.

Step 4: Configure the workflow for authentication only

permissions:
id-token: write # allow the job to request an OIDC token from GitHub
contents: read # allow actions/checkout to read the repo

steps:
- uses: aws-actions/configure-aws-credentials@<FULL_COMMIT_SHA> # v6.2.3
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- run: aws sts get-caller-identity --query Arn --output text
  •  id-token: write  is mandatory for OIDC and only allows fetching the token.
  •  role-to-assume  selects OIDC mode, since no static keys are provided.
  •  aws sts get-caller-identity  is a safe verification call. It needs no IAM permissions and prints the role session ARN. Only  Arn  is printed, because the action masks the account ID by default.
Do not enable the action's  output-credentials  option and do not  printenv .

Step 5: Deploy logic, kept separate

The full workflow in section 5 splits the work into two jobs.  verify-auth  proves the identity and the permission boundary and does nothing else.  deploy  runs only after that succeeds and contains the  aws s3 sync . A deployment failure is then never confused with an authentication failure.

5. Complete workflow

 .github/workflows/deploy.yml 
Resolve the SHAs yourself with  git ls-remote https://github.com/aws-actions/configure-aws-credentials refs/tags/v6.2.3  (if the tag is annotated, use the  ^{}  line, which is the commit). Do the same for  actions/checkout . Pick current stable versions.
name: Deploy static site to S3 (OIDC)

on:
push:
branches: [main]
paths: ["app/**", ".github/workflows/deploy.yml"]
workflow_dispatch:

# Deny everything by default; each job opts in to what it needs.
permissions: {}

# One deployment at a time. Do not cancel an in-flight deploy.
concurrency:
group: deploy-production
cancel-in-progress: false

jobs:
# ---------------------------------------------------------------
# PART A: AUTHENTICATION DEMONSTRATION (no deployment logic here)
# ---------------------------------------------------------------
verify-auth:
name: Verify OIDC authentication
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # deployment condition (1 of 2)
environment: production # deployment condition (2 of 2): branch rules live on this environment
permissions:
id-token: write # request the OIDC token; nothing else needed here
steps:
- name: Assume AWS role via OIDC
uses: aws-actions/configure-aws-credentials@<FULL_COMMIT_SHA_FOR_V6_2_3> # v6.2.3
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }} # non-secret config, stored as an environment variable
aws-region: ${{ vars.AWS_REGION }}
role-session-name: gha-verify-${{ github.run_id }}

- name: Show assumed identity (role ARN only)
run: aws sts get-caller-identity --query Arn --output text

- name: Confirm the role can reach the site bucket
env:
S3_BUCKET: ${{ vars.S3_BUCKET }}
run: aws s3 ls "s3://${S3_BUCKET}/" > /dev/null && echo "Bucket reachable"

- name: Confirm the role is NOT over-privileged
run: |
if aws iam list-roles --max-items 1 > /dev/null 2>&1; then
echo "UNEXPECTED: role can call iam:ListRoles" >&2
exit 1
fi
echo "iam:ListRoles denied, as intended"

# ---------------------------------------------------------------
# PART B: DEPLOYMENT LOGIC
# ---------------------------------------------------------------
deploy:
name: Deploy site to S3
needs: verify-auth
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
permissions:
id-token: write # OIDC token request
contents: read # actions/checkout
steps:
- name: Check out repository
uses: actions/checkout@<FULL_COMMIT_SHA_FOR_CHECKOUT> # vX.Y.Z
with:
persist-credentials: false # do not leave a GitHub token in .git/config

- name: Assume AWS role via OIDC
uses: aws-actions/configure-aws-credentials@<FULL_COMMIT_SHA_FOR_V6_2_3> # v6.2.3
with:
role-to-assume: ${{ vars.AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
role-session-name: gha-deploy-${{ github.run_id }}

- name: Sync app/ to S3
env:
S3_BUCKET: ${{ vars.S3_BUCKET }} # passed via env, never interpolated into the script
run: |
# --delete removes objects not present in app/. Use a bucket dedicated to this site.
aws s3 sync app/ "s3://${S3_BUCKET}/" --delete --only-show-errors
Notes on the design:
  • Variables, not secrets. Role ARN, region, and bucket name are not secret. Put them in the  production  environment's Variables. If they are missing,  role-to-assume  is empty and the action errors out instead of falling back to anything.
  •  permissions: {}  at top level removes default  GITHUB_TOKEN  scopes, and each job grants itself only what it uses.  verify-auth  does not check out code, so it gets no  contents: read .
  • No  pull_request  trigger. Pull requests, especially from forks, never receive AWS access. If you want CI checks on PRs, create a separate workflow with no  id-token  permission.
  • Credentials stay out of logs. The action masks the keys and the workflow never echoes them.

6. Security deep dive

Why OIDC is safer. There is no stored secret. The credential that reaches AWS is minted per job, is valid for a limited time (the AWS action's default session is one hour, adjustable with  role-duration-seconds  up to the role's maximum), and is tied to claims that describe the run.
How the trust policy stops unauthorized assumption. Signature validation proves "GitHub issued this." It does not prove "this is my repo." That is the trust policy's job. Any repository on GitHub can get a validly signed token with audience  sts.amazonaws.com . If your role trusts the provider without a tight  sub  condition, every one of them can try to assume it.
Why wildcards are dangerous.
Condition
What it allows
 "sub": "repo:my-org/*" 
Every current and future repository in the org, including repos created by anyone with that right
 "sub": "repo:my-org/app:*" 
Every branch, tag, pull request, and environment of the app, including a feature branch you forgot about
No  sub  condition
Every repository on GitHub
 StringLike  on  aud  with  * 
Tokens minted for any audience
Wildcards are sometimes defensible (a platform team role trusted by all repos in an org), but only with compensating controls such as custom subject claims that require a reusable workflow via  job_workflow_ref , and org-level repo creation policies.
Restricting branches and environments. Use the environment model from section 4: trust only  environment:production , then in GitHub restrict the environment to protected branches, require reviewers, and block admin bypass if your policy demands it. The  sub  for environment jobs carries no branch, so the environment's deployment branch policy is the only branch control in that model.
Why least privilege still matters. Trust policies can be misconfigured and workflows can be compromised. When that happens, the permissions policy defines the blast radius. A role limited to one bucket is a contained incident. A role with admin is a breach.
Common mistakes
  1. Writing  ref:refs/heads/main  in the trust policy while the job declares an environment.
  1. Using the old name-based  sub  on a repo that now emits immutable subjects (new repos, renamed or transferred repos, opted-in repos).
  1. Using  StringLike  with a wildcard when an exact match would do.
  1. Copying a trust policy from a blog post (including  repo:* ) without reading it.
  1. Using one role for dev and prod.
  1. Forgetting  id-token: write , or granting it at workflow level when only one job needs it.
  1. Setting a custom  audience  in the action and not updating the IAM provider and trust policy to match.
  1. Leaving old IAM user keys active after migrating. Delete them.
Comparison
Feature
Long-lived access keys
OIDC
Credential lifetime
Until manually rotated or deleted (often years)
Temporary; the session expires (default one hour in the AWS action)
Rotation requirements
Manual, and error-prone
None; credentials are minted per run
Exposure risk
High: a leaked key works anywhere until revoked
Lower: the credential is short-lived, and assumption is bound to repo/ref/environment claims
Authentication model
Shared secret stored in GitHub
Federated identity: signed token verified by AWS against a trust policy
Recommended use
Legacy systems that cannot do federation; avoid in new pipelines
Default for GitHub Actions to AWS

7. Troubleshooting

Exact error text varies by action and CLI version. Use the symptoms below as a guide and check the full log (and enable debug logging if needed).
 Not authorized to perform sts:AssumeRoleWithWebIdentity  The generic failure: STS evaluated the trust policy and said no. Check, in order: (1) the role ARN in  AWS_ROLE_ARN ; (2) the  :aud  condition; (3) the  :sub  condition against the actual  sub  (decode it with the debug workflow in section 8); (4) that the  Principal  provider ARN matches the provider in this account.
Subject mismatch (the most common cause) Same error as above. Compare the token's  sub  with the trust policy character for character. Typical differences: environment vs branch form,  pull_request  form, the immutable  @ID  segments, or a typo in owner or repository case.
Immutable subject mismatch after a rename, transfer, or new repo A policy written for  repo:OWNER/REPO:...  stops matching once the repository emits  repo:OWNER@ID/REPO@ID:... . Update the trust policy to the new format, and test before rolling out to other repos.
Incorrect audience STS returns an  InvalidIdentityToken -type error referencing the audience. Make sure the token audience (default  sts.amazonaws.com  from the AWS action), the IAM provider's client ID list, and the  :aud  condition all say the same thing. If you set a custom  audience  input in the action, update IAM to match.
Missing  id-token: write  The action fails before calling AWS, with a message about not being able to get an ID token or about the  ACTIONS_ID_TOKEN_REQUEST_URL  variable being missing. Add the permission at the job (or workflow) level. A job-level  permissions  block replaces, not merges with, the workflow-level one.
No OpenID Connect provider found You skipped Step 1, created the provider in a different account, or the URL has a typo or trailing-slash difference. Run  aws iam list-open-id-connect-providers  in the target account.
Incorrect role ARN Usually looks like an access denied or "role not found" error. Check the 12-digit account, the role name, and that the variable is set on the environment the job uses (an environment variable is invisible to jobs without that environment).
 AccessDenied  on S3 after a successful assume Authentication worked and authorization did not. Read the denied action in the message and compare it with the permissions policy. For  sync , you need  ListBucket  on the bucket and  PutObject  and  DeleteObject  on objects. If a call such as  HeadObject  is denied, add  s3:GetObject  for that bucket's objects, and nothing broader.
Environment job waiting forever Required reviewers on the environment hold the job until approved. That is expected. Approve it, or remove the rule for the demo.

8. Verification and testing

8.1 Did GitHub issue an OIDC token?

Run this manual workflow once. It prints selected claims and never the token itself.
name: OIDC debug (manual)
on: workflow_dispatch
permissions: {}
jobs:
claims:
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write
steps:
- name: Print selected token claims
run: |
jwt=$(curl -sSf -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=sts.amazonaws.com" | jq -r .value)
echo "::add-mask::$jwt"
payload=$(cut -d. -f2 <<<"$jwt" | tr '_-' '/+')
while [ $(( ${#payload} % 4 )) -ne 0 ]; do payload="${payload}="; done
echo "$payload" | base64 -d | jq '{iss, aud, sub, repository, repository_id, repository_owner_id, ref, environment}'
GitHub also maintains an official  github/actions-oidc-debugger  action for this. Use the printed  sub  as the source of truth for the trust policy. Delete this workflow when finished.

8.2 Did STS issue temporary credentials?

The  verify-auth  job's  get-caller-identity  step should print an ARN like  arn:aws:sts::<account>:assumed-role/github-actions-oidc-s3-deploy/gha-verify-<run_id> . An  assumed-role  ARN means you hold temporary credentials, not an IAM user key.

8.3 Does the role have only the intended permissions?

The negative check in  verify-auth  expects  iam:ListRoles  to be denied. For a deeper check, run the IAM policy simulator against the role, or try one action outside the policy and confirm  AccessDenied .

8.4 Does the deployment work?

Push a change to  app/index.html  on  main . Confirm that both jobs succeed, then verify the object exists and matches:
aws s3 ls s3://<BUCKET_NAME>/
aws s3 cp s3://<BUCKET_NAME>/index.html - | head
Never print credentials or tokens at any step. If a log ever shows one, treat it as compromised and review the run and the role's trust policy.

9. Production considerations

  • Environments and approvals. Create  production  (and  staging ). Restrict deployment branches to protected branches, add required reviewers for production, and consider disabling admin bypass.
  • Separate roles per environment. A  staging  role trusted only by  environment:staging , and a  production  role trusted only by  environment:production , ideally in separate AWS accounts. One role for everything defeats the point.
  • Branch protection. Require PR review and status checks on  main , since anyone who can push to  main  can trigger production deploys.
  • Workflow protection. Use CODEOWNERS on  .github/workflows/  so changes to deployment logic need review. For org-wide enforcement, consider trusting only a reusable workflow via a customized subject that includes  job_workflow_ref .
  • Audit logging. CloudTrail records  AssumeRoleWithWebIdentity  calls. Alert on assumptions of the production role from unexpected contexts, and check in your own trail which fields carry the session name and subject.
  • Credential lifecycle. Sessions expire on their own. Keep  max-session-duration  and  role-duration-seconds  as short as the job needs, and delete any old IAM user keys.
  • Policy maintenance. Review the permissions policy periodically against IAM Access Analyzer findings, and re-check trust policies after repository renames, transfers, or org changes, given the subject format change.
  • Dependency hygiene. Pin actions to full SHAs, and use Dependabot or Renovate to propose bumps so the pins don't rot.

10. Conclusion

OIDC turns "someone has a secret" into "this specific job, on this specific repository and environment, is asking now." The security gain is real: there is nothing in GitHub to steal or rotate, credentials expire quickly, and access is tied to claims you control. The gain depends on a tight trust policy. A provider with a loose or wildcard  sub  is not much better than a shared key. Prefer OIDC for any GitHub-to-AWS pipeline that can use it, and keep static keys only for systems that cannot federate.

Appendix A: Security review checklist

  • [ ] Trust policy has  aud  ( StringEquals ,  sts.amazonaws.com ) and an exact  sub 
  • [ ]  sub  uses the format this repository actually emits (immutable or legacy), and only one format
  • [ ] No  *  in  sub , unless there are documented compensating controls
  • [ ] Permissions policy names specific actions and resources
  • [ ] Separate roles for staging and production
  • [ ]  id-token: write  granted per job, with workflow-level  permissions: {} 
  • [ ] Environment has deployment-branch rules (and reviewers for production)
  • [ ] Branch protection on  main , and CODEOWNERS on  .github/workflows/ 
  • [ ] Third-party actions pinned to full SHAs, with update automation
  • [ ] No  pull_request  or  pull_request_target  path to the AWS role
  • [ ] No credentials or tokens printed in any step
  • [ ] Old IAM user access keys deactivated and deleted
  • [ ] CloudTrail enabled, with alerting on production role assumption
  • [ ] Trust policies re-reviewed after repo renames, transfers, or org changes

Appendix B: Testing checklist

  • [ ] Debug workflow shows  iss  =  https://token.actions.githubusercontent.com  and  aud  =  sts.amazonaws.com 
  • [ ] Printed  sub  matches the trust policy exactly
  • [ ]  get-caller-identity  returns an  assumed-role  ARN with the expected role and session name
  • [ ]  iam:ListRoles  is denied (permission boundary confirmed)
  • [ ]  aws s3 ls  on the bucket works
  • [ ] Push to  main  deploys, and the object content matches  app/ 
  • [ ] A run from a non- main  branch or another environment is denied
  • [ ] Removing  id-token: write  causes the expected failure
  • [ ] A wrong  aud  in the trust policy causes the expected failure, and restoring it recovers
  • [ ] CloudTrail shows the  AssumeRoleWithWebIdentity  event
  • [ ] Cleanup (delete role, policy, bucket, provider if unused) leaves nothing behind

Appendix C: Cleanup

aws s3 rm s3://<BUCKET_NAME> --recursive
aws s3api delete-bucket --bucket <BUCKET_NAME>
aws iam delete-role-policy --role-name github-actions-oidc-s3-deploy \
--policy-name s3-deploy-single-bucket
aws iam delete-role --role-name github-actions-oidc-s3-deploy
# Only if no other workload in this account uses the provider:
aws iam delete-open-id-connect-provider \
--open-id-connect-provider-arn arn:aws:iam::<AWS_ACCOUNT_ID>:oidc-provider/token.actions.githubusercontent.com

References

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article