Sub topic 15
Credential lifetime and session duration
This chapter assumes you have a working OIDC deployment: an IAM OIDC provider, a role with a trust policy, and a workflow that uses aws-actions/configure-aws-credentials. It covers how long the credentials from that setup last and how to control that.
Two lifetimes, not one
Two separate tokens are involved, and they expire independently.
- The GitHub OIDC token is short-lived. AWS checks it once, when the workflow calls
AssumeRoleWithWebIdentity. After that call succeeds, the token's expiry no longer matters to the session. - The AWS session credentials (access key ID, secret key, and session token) last for the session duration. The role's settings and the request set this value.
A leaked credential is only useful until the session ends. This is the main security gain over stored access keys, which never expire on their own.
Setting the session duration
The role has a maximum session duration. The default is 1 hour, and you can set it from 1 hour to 12 hours. The action requests 1 hour (3600 seconds) unless you ask for more.
Raise the role's maximum first:
aws iam update-role \
--role-name github-deploy \
--max-session-duration 7200Then request the longer session in the workflow with role-duration-seconds:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
aws-region: us-east-1
role-duration-seconds: 7200If the request is longer than the role's maximum, the assume-role call fails with a validation error. The role's maximum is the ceiling, and the workflow can only ask for less.
Choosing a value
Match the duration to the longest job you expect to run, with some margin. A deployment that takes 10 minutes does not need 12 hours. A shorter session shrinks the window in which a stolen credential works.
A long job, such as a large infrastructure rollout or a slow data migration, can outlive the default hour. When a call fails partway through with an ExpiredToken error, the session ended before the job did. You have two options:
- Raise
role-duration-secondsand the role's maximum session duration. - Split the work into several jobs. Each job runs the action again and gets a fresh session.
Role chaining has a hard limit of one hour. This applies when the action uses one role's credentials to assume another. In that case the second session cannot exceed 1 hour, whatever the role's maximum says.
Summary of the controls
| Setting | Where | Effect |
|---|---|---|
| `--max-session-duration` | IAM role | Upper limit, 1 to 12 hours |
| `role-duration-seconds` | Workflow step | Requested length, default 3600 |
| Job boundaries | Workflow design | Each job gets its own session |
Exercise
A deployment job fails after 70 minutes with an ExpiredToken error. The role uses the default settings. Name two changes that would fix this.
Show answer
Raise the role's maximum session duration (for example to 7200 seconds) and set role-duration-seconds in the workflow to match. Alternatively, split the deployment into separate jobs so each one assumes the role again and gets a new one-hour session.
Exercise
You set role-duration-seconds to 14400 but leave the role's maximum session duration at its default. What happens, and why?
Show answer
The assume-role call fails with a validation error. The role's maximum session duration is the ceiling, and a request longer than that is rejected.