Configure your AWS credentials and region environment variables for use in other GitHub Actions.
This action implements the AWS JavaScript SDK credential resolution chain and exports session environment variables for your other Actions to use. Environment variable exports are detected by both the AWS SDKs and the AWS CLI for AWS API calls.
API calls to AWS need to be signed with credential information, so when you use one of the AWS SDKs or an AWS tool, you must provide it with AWS credentials and and AWS region. One way to do that in GitHub Actions is to use a repository secret with IAM credentials, but this doesn't follow AWS security guidelines on using long term credentials. Instead, we recommend that you use a long term credential or JWT to fetch a temporary credential, and use that with your tools instead. This GitHub Action facilitates just that.
AWS SDKs and Tools look for your credentials in standardized environment variables. In essence, this Action runs through the standard credential resolution flow, and at the end, exports environment variables for you to use later.
We support five methods for fetching credentials from AWS, but we recommend that you use GitHub's OIDC provider in conjunction with a configured AWS IAM Identity Provider endpoint.
For more information on how to do that, read on.
Some of this documentation may be inaccurate if you are using GHES (GitHub Enterprise Server), please take note to review the GitHub documentation when relevant.
For example, the URL that the OIDC JWT is issued from is different than the
usual token.actions.githubusercontent.com, and will be unique to your
enterprise server. As a result, you will need to configure this differently when
you create the Identity Provider.
We do not presently have a GHES testing environment to validate this action. If you are running in GHES and encounter problems, please let us know.
We recommend following Amazon IAM best practices for the AWS credentials used in GitHub Actions workflows, including:
- Do not store credentials in your repository's code.
- Grant least privilege to the credentials used in GitHub Actions workflows. Grant only the permissions required to perform the actions in your GitHub Actions workflows. Do not assume overly permissive roles, even for testing.
- Monitor the activity of the credentials used in GitHub Actions workflows.
- Use temporary credentials when possible.
- Periodically rotate any long-term credentials you use.
There are five different supported ways to retrieve credentials:
- Using GitHub's OIDC provider (
AssumeRoleWithWebIdentity) - Proceeding as an IAM user (No STS call is made)
- Using access keys as action input (
AssumeRole) - Using a WebIdentity Token File (
AssumeRoleWithWebIdentity) - Using existing credentials in your runner (
AssumeRole)
Because we use the AWS JavaScript SDK, we always will use the credential resolution flow for Node.js. Depending on your inputs, the action might override parts of this flow.
We recommend using the first option above: GitHub's OIDC provider. This method uses OIDC to get short-lived credentials needed for your actions. See OIDC for more information on how to setup your AWS account to assume a role with OIDC.
The following table describes which method we'll use to get your credentials based on which values are supplied to the Action:
| Identity Used | aws-access-key-id |
role-to-assume |
web-identity-token-file |
role-chaining |
id-token permission |
|---|---|---|---|---|---|
| [âś… Recommended] Assume Role directly using GitHub OIDC provider | âś” | âś” | |||
| IAM User | âś” | ||||
| Assume Role using IAM User credentials | âś” | âś” | |||
| Assume Role using WebIdentity Token File credentials | âś” | âś” | |||
| Assume Role using existing credentials | âś” | âś” |
Note: role-chaining is not always necessary to use existing credentials.
If you're getting a "Credentials loaded by the SDK do not match" error,
try enabling this option.
See action.yml for more detail.
| Option | Description | Required |
|---|---|---|
| aws-region | Which AWS region to use | Yes |
| role-to-assume | Role for which to fetch credentials. Only required for some authentication types. | No |
| aws-access-key-id | AWS access key to use. Only required for some authentication types. | No |
| aws-secret-access-key | AWS secret key to use. Only required for some authentication types. | No |
| aws-session-token | AWS session token to use. Used in uncommon authentication scenarios. | No |
| role-chaining | Use existing credentials from the environment to assume a new role. | No |
| audience | The JWT audience when using OIDC. Used in non-default AWS partitions, like China regions. | No |
| http-proxy | An HTTP proxy to use for API calls. | No |
| mask-aws-account-id | AWS account IDs are not considered secret. Setting this will hide account IDs from output anyway. | No |
| role-duration-seconds | The assumed role duration in seconds, if assuming a role. Defaults to 1 hour. | No |
| role-external-id | The external ID of the role to assume. Only needed if your role requires it. | No |
| role-session-name | Defaults to "GitHubActions", but may be changed if required. | No |
| role-skip-session-tagging | Skips session tagging if set. | No |
| inline-session-policy | You may further restrict the assumed role policy by defining an inline policy here. | No |
| managed-session-policies | You may further restrict the assumed role policy by specifying a managed policy here. | No |
| output-credentials | When set, outputs fetched credentials as action step output. Defaults to false. | No |
| unset-current-credentials | When set, attempts to unset any existing credentials in your action runner. | No |
| disable-retry | Disabled retry/backoff logic for assume role calls. By default, retries are enabled. | No |
| retry-max-attempts | Limits the number of retry attempts before giving up. Defaults to 12. | No |
| special-characters-workaround | Uncommonly, some environments cannot tolerate special characters in a secret key. This option will retry fetching credentials until the secret access key does not contain special characters. This option overrides disable-retry and retry-max-attempts. | No |
| use-existing-credentials | When set, the action will check if existing credentials are valid and exit if they are. Defaults to false. | No |
The default session duration is 1 hour.
If you would like to adjust this you can pass a duration to
role-duration-seconds, but the duration cannot exceed the maximum that was
defined when the IAM Role was created.
If your role requires an external ID to assume, you can provide the external ID
with the role-external-id input
The default session name is "GitHubActions", and you can modify it by specifying
the desired name in role-session-name. The session will be tagged with the
following tags: (Refer to GitHub's documentation for GITHUB_ environment
variable definitions)
| Key | Value |
|---|---|
| GitHub | "Actions" |
| Repository | GITHUB_REPOSITORY |
| Workflow | GITHUB_WORKFLOW |
| Action | GITHUB_ACTION |
| Actor | GITHUB_ACTOR |
| Branch | GITHUB_REF |
| Commit | GITHUB_SHA |
Note: all tag values must conform to
the tag requirements.
Particularly, GITHUB_WORKFLOW will be truncated if it's too long. If
GITHUB_ACTOR or GITHUB_WORKFLOW contain invalid characters, the characters
will be replaced with an '*'.
The action will use session tagging by default during role assumption, unless you follow our recommendation and are assuming a role with a WebIdentity. For WebIdentity role assumption, the session tags have to be included in the encoded WebIdentity token. This means that tags can only be supplied by the OIDC provider, and they cannot set during the AssumeRoleWithWebIdentity API call within the Action. See #419 for more information.
You can skip this session tagging by providing
role-skip-session-tagging as true in the action's inputs:
uses: aws-actions/configure-aws-credentials@v4
with:
role-skip-session-tagging: trueSession policies are not required, but they allow you to limit the scope of the fetched credentials without making changes to IAM roles. You can specify inline session policies right in your workflow file, or refer to an existing managed session policy by its ARN.
An IAM policy in stringified JSON format that you want to use as an inline session policy. Depending on preferences, the JSON could be written on a single line like this:
uses: aws-actions/configure-aws-credentials@v4
with:
inline-session-policy: '{"Version":"2012-10-17","Statement":[{"Sid":"Stmt1","Effect":"Allow","Action":"s3:List*","Resource":"*"}]}'Or we can have a nicely formatted JSON as well:
uses: aws-actions/configure-aws-credentials@v4
with:
inline-session-policy: >-
{
"Version": "2012-10-17",
"Statement": [
{
"Sid":"Stmt1",
"Effect":"Allow",
"Action":"s3:List*",
"Resource":"*"
}
]
}The Amazon Resource Names (ARNs) of the IAM managed policies that you want to use as managed session policies. The policies must exist in the same account as the role. You can pass a single managed policy like this:
uses: aws-actions/configure-aws-credentials@v4
with:
managed-session-policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccessAnd we can pass multiple managed policies likes this:
uses: aws-actions/configure-aws-credentials@v4
with:
managed-session-policies: |
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
arn:aws:iam::aws:policy/AmazonS3OutpostsReadOnlyAccessYou can now configure retry settings for when the STS call fails. By default, we
retry with exponential backoff 12 times. You can disable this behavior
altogether by setting the disable-retry input to true, or you can configure
the number of times it retries with the retry-max-attempts input.
Your account ID is not masked by default in workflow logs since it's not
considered sensitive information. However, you can set the mask-aws-account-id
input to true to mask your account ID in workflow logs if desired.