Sub topic 14
Automation and CI: when not to use Identity Center sign-in
This chapter assumes you can run aws sso login, you know what a profile is, and you understand IAM roles and trust policies. It covers where Identity Center sign-in stops being the right tool and what to use instead.
Why interactive sign-in does not fit automation
aws sso login opens a browser and waits for a person to approve the request. A CI job, a cron task, or a server has no person to do that. The cached sign-in token also expires, so a pipeline that worked today fails when the session ends and nobody is there to sign in again.
Copying a developer's cached token into a pipeline is not a fix. It ties the pipeline to one person's identity and permissions, and it moves a credential from a protected workstation into a place where many people can read it. Using an IAM user access key instead brings back the long-term key risks from the start of this tutorial.
The better approach is to let the workload prove its identity to AWS and receive temporary credentials directly.
Choosing an alternative
| Where the code runs | Use | Credential source |
|---|---|---|
| GitHub Actions or another OIDC-capable CI service | OIDC federation into an IAM role | A short-lived token from the CI provider, exchanged with `AssumeRoleWithWebIdentity` |
| EC2, ECS, EKS, Lambda | The attached role (instance profile, task role, execution role) | Provided by the compute service. The SDK and CLI find it automatically. |
| On-premises servers | IAM Roles Anywhere | An X.509 certificate you issue, exchanged for temporary credentials |
| A developer laptop running a tool without SSO support | `aws configure export-credentials` | Your own Identity Center session (covered in the previous chapter) |
Example: GitHub Actions with OIDC
No secret is stored in the repository. GitHub issues a signed token for each workflow run, and AWS trusts that token because you registered GitHub as an identity provider in IAM.
The role's trust policy restricts which repository and branch can assume it. The account ID and repository name are placeholders.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111122223333: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:example-org/example-repo:ref:refs/heads/main"
}
}
}
]
}The workflow requests the token and exchanges it for credentials:
name: deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::111122223333:role/ci-deploy
aws-region: us-west-2
- run: aws sts get-caller-identityThe id-token: write permission is required. Without it, the workflow cannot request the OIDC token and the credentials step fails.
Common mistakes
- Using
export-credentialsin CI. It reads your local Identity Center session, so it needs a prior interactive sign-in. It is a bridge for local tools, not a pipeline credential. - Giving the CI role the same permissions as an administrator. Scope the role to what the job does, such as deploying one stack or writing to one bucket.
- Leaving an old access key in CI after switching. Delete the key from the IAM user and the CI secret store, or the risk remains.
- Expecting profiles to be needed. On compute with an attached role, or in a job that has already assumed a role, the CLI uses the credential chain automatically. Do not set
AWS_PROFILEto a profile that does not exist on that machine.
Exercise
A teammate proposes running aws sso login on their laptop and copying the cached token files into your CI system's secret store so nightly jobs can run. Give two reasons this is a poor design and name a better option for a pipeline on GitHub Actions.
Show answer
The cached token belongs to one person, so the jobs run with that person's permissions and stop when that person leaves or the session expires, and the token would be readable by anyone with access to the secret store. A better option is OIDC federation: register GitHub as an IAM OIDC identity provider, create a role whose trust policy limits the repository and branch, and have the workflow assume it with aws-actions/configure-aws-credentials and the id-token: write permission.