mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-03-12 18:07:10 -04:00
feat: added OIDC (#262)
* feat: OIDC provider (with PR comments) * chore: Bump jest from 27.2.1 to 27.2.2 (#267) Bumps [jest](https://github.com/facebook/jest) from 27.2.1 to 27.2.2. - [Release notes](https://github.com/facebook/jest/releases) - [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/facebook/jest/compare/v27.2.1...v27.2.2) --- updated-dependencies: - dependency-name: jest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: Bump ansi-regex from 5.0.0 to 5.0.1 (#269) Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 5.0.0 to 5.0.1. - [Release notes](https://github.com/chalk/ansi-regex/releases) - [Commits](https://github.com/chalk/ansi-regex/compare/v5.0.0...v5.0.1) --- updated-dependencies: - dependency-name: ansi-regex dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: Bump aws-sdk from 2.991.0 to 2.996.0 (#268) Bumps [aws-sdk](https://github.com/aws/aws-sdk-js) from 2.991.0 to 2.996.0. - [Release notes](https://github.com/aws/aws-sdk-js/releases) - [Changelog](https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-js/compare/v2.991.0...v2.996.0) --- updated-dependencies: - dependency-name: aws-sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * chore: Update dist * feat: OIDC provider (with PR comments) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions <runner@fv-az209-487.sst5i0nymnhu5a1lxus1lxbvub.xx.internal.cloudapp.net>
This commit is contained in:
136
README.md
136
README.md
@@ -9,8 +9,8 @@ Configure AWS credential and region environment variables for use in other GitHu
|
||||
- [Usage](#usage)
|
||||
- [Credentials](#credentials)
|
||||
- [Assuming a Role](#assuming-a-role)
|
||||
+ [Permissions for assuming a role](#permissions-for-assuming-a-role)
|
||||
+ [Session tagging](#session-tagging)
|
||||
+ [Sample IAM Role Permissions](#sample-iam-role-cloudformation-template)
|
||||
- [Self-Hosted Runners](#self-hosted-runners)
|
||||
- [License Summary](#license-summary)
|
||||
- [Security Disclosures](#security-disclosures)
|
||||
@@ -25,9 +25,7 @@ Add the following step to your workflow:
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
# aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} # if you have/need it
|
||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||
aws-region: us-east-2
|
||||
```
|
||||
|
||||
@@ -47,8 +45,7 @@ jobs:
|
||||
- name: Configure AWS credentials from Test account
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }}
|
||||
role-to-assume: arn:aws:iam::111111111111:role/my-github-actions-role-test
|
||||
aws-region: us-east-1
|
||||
|
||||
- name: Copy files to the test website with the AWS CLI
|
||||
@@ -58,8 +55,7 @@ jobs:
|
||||
- name: Configure AWS credentials from Production account
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
|
||||
role-to-assume: arn:aws:iam::222222222222:role/my-github-actions-role-prod
|
||||
aws-region: us-west-2
|
||||
|
||||
- name: Copy files to the production website with the AWS CLI
|
||||
@@ -72,19 +68,39 @@ See [action.yml](action.yml) for the full documentation for this action's inputs
|
||||
## Credentials
|
||||
|
||||
We recommend following [Amazon IAM best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html) for the AWS credentials used in GitHub Actions workflows, including:
|
||||
* Do not store credentials in your repository's code. You may use [GitHub Actions secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) to store credentials and redact credentials from GitHub Actions workflow logs.
|
||||
* [Create an individual IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#create-iam-users) with an access key for use in GitHub Actions workflows, preferably one per repository. Do not use the AWS account root user access key.
|
||||
* Do not store credentials in your repository's code.
|
||||
* [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#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.
|
||||
* [Rotate the credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#rotate-credentials) used in GitHub Actions workflows regularly.
|
||||
* [Monitor the activity](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#keep-a-log) of the credentials used in GitHub Actions workflows.
|
||||
|
||||
## Assuming a Role
|
||||
If you would like to use the static credentials you provide to this action to assume a role, you can do so by specifying the role ARN in `role-to-assume`.
|
||||
The role credentials will then be configured in the Actions environment instead of the static credentials you have provided.
|
||||
The default session duration is 6 hours, but if you would like to adjust this you can pass a duration to `role-duration-seconds`.
|
||||
We recommend using GitHub's OIDC provider to get short-lived credentials needed for your actions.
|
||||
Specifying `role-to-assume` without providing an `aws-access-key-id` or a `web-identity-token-file` will signal to the action that you wish to use the OIDC provider.
|
||||
The default session duration is 1 hour when using the OIDC provider to directly assume an IAM Role.
|
||||
The default session duration is 6 hours when using an IAM User to assume an IAM Role (by providing an `aws-access-key-id`, `aws-secret-access-key`, and a `role-to-assume`) .
|
||||
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.
|
||||
The default session name is GitHubActions, and you can modify it by specifying the desired name in `role-session-name`.
|
||||
|
||||
Example:
|
||||
The following table describes which identity is used based on which values are supplied to the Action:
|
||||
|
||||
| **Identity Used** | `aws-access-key-id` | `role-to-assume` | `web-identity-token-file` |
|
||||
|------------------------------------------------------------------|---------------------|------------------|---------------------------|
|
||||
| [✅ Recommended] Assume Role directly using GitHub OIDC provider | | ✔ | |
|
||||
| IAM User | ✔ | | |
|
||||
| Assume Role using IAM User credentials | ✔ | ✔ | |
|
||||
| Assume Role using WebIdentity Token File credentials | | ✔ | ✔ |
|
||||
|
||||
### Examples
|
||||
|
||||
```yaml
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||
role-session-name: MySessionName
|
||||
```
|
||||
In this example, the Action will load the OIDC token from the GitHub-provided environment variable and use it to assume the role `arn:aws:iam::123456789100:role/my-github-actions-role` with the session name `MySessionName`.
|
||||
|
||||
```yaml
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
@@ -99,48 +115,52 @@ Example:
|
||||
```
|
||||
In this example, the secret `AWS_ROLE_TO_ASSUME` contains a string like `arn:aws:iam::123456789100:role/my-github-actions-role`. To assume a role in the same account as the static credentials, you can simply specify the role name, like `role-to-assume: my-github-actions-role`.
|
||||
|
||||
### Permissions for assuming a role
|
||||
### Sample IAM Role CloudFormation Template
|
||||
```yaml
|
||||
Parameters:
|
||||
GitHubOrg:
|
||||
Type: String
|
||||
RepositoryName:
|
||||
Type: String
|
||||
OIDCProviderArn:
|
||||
Description: Arn for the GitHub OIDC Provider.
|
||||
Default: ""
|
||||
Type: String
|
||||
|
||||
In order to assume a role, the IAM user for the static credentials must have the following permissions:
|
||||
```json
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": [
|
||||
"sts:AssumeRole",
|
||||
"sts:TagSession"
|
||||
],
|
||||
"Resource": "arn:aws:iam::123456789012:role/my-github-actions-role",
|
||||
"Effect": "Allow"
|
||||
}
|
||||
]
|
||||
}
|
||||
Conditions:
|
||||
CreateOIDCProvider: !Equals
|
||||
- !Ref OIDCProviderArn
|
||||
- ""
|
||||
|
||||
Resources:
|
||||
Role:
|
||||
Type: AWS::IAM::Role
|
||||
Properties:
|
||||
RoleName: ExampleGithubRole
|
||||
AssumeRolePolicyDocument:
|
||||
Statement:
|
||||
- Effect: Allow
|
||||
Action: sts:AssumeRoleWithWebIdentity
|
||||
Principal:
|
||||
Federated: !Ref GithubOidc
|
||||
Condition:
|
||||
StringLike:
|
||||
vstoken.actions.githubusercontent.com:sub: !Sub repo:${GitHubOrg}/${RepositoryName}:*
|
||||
|
||||
GithubOidc:
|
||||
Type: AWS::IAM::OIDCProvider
|
||||
Condition: CreateOIDCProvider
|
||||
Properties:
|
||||
Url: https://vstoken.actions.githubusercontent.com
|
||||
ClientIdList: [sigstore]
|
||||
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
|
||||
|
||||
Outputs:
|
||||
Role:
|
||||
Value: !GetAtt Role.Arn
|
||||
```
|
||||
|
||||
The role's trust policy must allow the IAM user to assume the role:
|
||||
```json
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "AllowIamUserAssumeRole",
|
||||
"Effect": "Allow",
|
||||
"Action": "sts:AssumeRole",
|
||||
"Principal": {"AWS": "arn:aws:iam::123456789012:user/my-github-actions-user"},
|
||||
"Condition": {
|
||||
"StringEquals": {"sts:ExternalId": "Example987"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"Sid": "AllowPassSessionTags",
|
||||
"Effect": "Allow",
|
||||
"Action": "sts:TagSession",
|
||||
"Principal": {"AWS": "arn:aws:iam::123456789012:user/my-github-actions-user"}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
The GitHub OIDC Provider only needs to be created once per account (i.e. multiple IAM Roles that can be assumed by the GitHub's OIDC can share a single OIDC Provider)
|
||||
|
||||
### Session tagging
|
||||
The session will have the name "GitHubActions" and be tagged with the following tags:
|
||||
@@ -158,7 +178,10 @@ The session will have the name "GitHubActions" and be tagged with the following
|
||||
|
||||
_Note: all tag values must conform to [the requirements](https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html). 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. You can skip this session tagging by providing `role-skip-session-tagging` as true in the action's inputs:
|
||||
The action will use session tagging by default during role assumption.
|
||||
Note that 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 not set during the AssumeRoleWithWebIdentity API call within the Action.
|
||||
You can skip this session tagging by providing `role-skip-session-tagging` as true in the action's inputs:
|
||||
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
@@ -189,7 +212,8 @@ with:
|
||||
```
|
||||
In this case, your runner's credentials must have permissions to assume the role.
|
||||
|
||||
You can also assume a role using a web identity token file, such as if using [Amazon EKS IRSA](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts-technical-overview.html). Pods running in EKS worker nodes that do not run as root can use this file to assume a role with a web identity.
|
||||
You can also assume a role using a web identity token file, such as if using [Amazon EKS IRSA](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts-technical-overview.html).
|
||||
Pods running in EKS worker nodes that do not run as root can use this file to assume a role with a web identity.
|
||||
|
||||
You can configure your workflow as follows in order to use this file:
|
||||
```yaml
|
||||
|
||||
4218
dist/index.js
vendored
4218
dist/index.js
vendored
File diff suppressed because one or more lines are too long
74
index.js
74
index.js
@@ -3,10 +3,12 @@ const aws = require('aws-sdk');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const axios = require('axios');
|
||||
|
||||
// The max time that a GitHub action is allowed to run is 6 hours.
|
||||
// That seems like a reasonable default to use if no role duration is defined.
|
||||
const MAX_ACTION_RUNTIME = 6 * 3600;
|
||||
const DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES = 3600;
|
||||
const USER_AGENT = 'configure-aws-credentials-for-github-actions';
|
||||
const MAX_TAG_VALUE_LENGTH = 256;
|
||||
const SANITIZATION_CHARACTER = '_';
|
||||
@@ -25,10 +27,11 @@ async function assumeRole(params) {
|
||||
roleSessionName,
|
||||
region,
|
||||
roleSkipSessionTagging,
|
||||
webIdentityTokenFile
|
||||
webIdentityTokenFile,
|
||||
webIdentityToken
|
||||
} = params;
|
||||
assert(
|
||||
[sourceAccountId, roleToAssume, roleDurationSeconds, roleSessionName, region].every(isDefined),
|
||||
[roleToAssume, roleDurationSeconds, roleSessionName, region].every(isDefined),
|
||||
"Missing required input when assuming a Role."
|
||||
);
|
||||
|
||||
@@ -43,6 +46,10 @@ async function assumeRole(params) {
|
||||
let roleArn = roleToAssume;
|
||||
if (!roleArn.startsWith('arn:aws')) {
|
||||
// Supports only 'aws' partition. Customers in other partitions ('aws-cn') will need to provide full ARN
|
||||
assert(
|
||||
isDefined(sourceAccountId),
|
||||
"Source Account ID is needed if the Role Name is provided and not the Role Arn."
|
||||
);
|
||||
roleArn = `arn:aws:iam::${sourceAccountId}:role/${roleArn}`;
|
||||
}
|
||||
|
||||
@@ -80,8 +87,14 @@ async function assumeRole(params) {
|
||||
|
||||
let assumeFunction = sts.assumeRole.bind(sts);
|
||||
|
||||
if(isDefined(webIdentityTokenFile)) {
|
||||
core.debug("webIdentityTokenFile provided. Will call sts:AssumeRoleWithWebIdentity and take session tags from token contents.")
|
||||
// These are customizations needed for the GH OIDC Provider
|
||||
if(isDefined(webIdentityToken)) {
|
||||
delete assumeRoleRequest.Tags;
|
||||
|
||||
assumeRoleRequest.WebIdentityToken = webIdentityToken;
|
||||
assumeFunction = sts.assumeRoleWithWebIdentity.bind(sts);
|
||||
} else if(isDefined(webIdentityTokenFile)) {
|
||||
core.debug("webIdentityTokenFile provided. Will call sts:AssumeRoleWithWebIdentity and take session tags from token contents.");
|
||||
delete assumeRoleRequest.Tags;
|
||||
|
||||
const webIdentityTokenFilePath = path.isAbsolute(webIdentityTokenFile) ?
|
||||
@@ -172,6 +185,21 @@ async function exportAccountId(maskAccountId, region) {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
async function getWebIdentityToken() {
|
||||
const isDefined = i => !!i;
|
||||
const {ACTIONS_ID_TOKEN_REQUEST_URL, ACTIONS_ID_TOKEN_REQUEST_TOKEN} = process.env;
|
||||
|
||||
assert(
|
||||
[ACTIONS_ID_TOKEN_REQUEST_URL, ACTIONS_ID_TOKEN_REQUEST_TOKEN].every(isDefined),
|
||||
'Missing required environment value. Are you running in GitHub Actions?'
|
||||
);
|
||||
const { data } = await axios.get(`${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sigstore`, {
|
||||
headers: {"Authorization": `bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}`}
|
||||
}
|
||||
);
|
||||
return data.value;
|
||||
}
|
||||
|
||||
function loadCredentials() {
|
||||
// Force the SDK to re-resolve credentials with the default provider chain.
|
||||
//
|
||||
@@ -234,11 +262,11 @@ async function run() {
|
||||
const maskAccountId = core.getInput('mask-aws-account-id', { required: false });
|
||||
const roleToAssume = core.getInput('role-to-assume', {required: false});
|
||||
const roleExternalId = core.getInput('role-external-id', { required: false });
|
||||
const roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || MAX_ACTION_RUNTIME;
|
||||
let roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || MAX_ACTION_RUNTIME;
|
||||
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
|
||||
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false })|| 'false';
|
||||
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
|
||||
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false })
|
||||
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false });
|
||||
|
||||
if (!region.match(REGION_REGEX)) {
|
||||
throw new Error(`Region is not valid: ${region}`);
|
||||
@@ -246,6 +274,16 @@ async function run() {
|
||||
|
||||
exportRegion(region);
|
||||
|
||||
// This wraps the logic for deciding if we should rely on the GH OIDC provider since we may need to reference
|
||||
// the decision in a few differennt places. Consolidating it here makes the logic clearer elsewhere.
|
||||
const useGitHubOIDCProvider = () => {
|
||||
// The assumption here is that self-hosted runners won't be populating the `ACTIONS_ID_TOKEN_REQUEST_TOKEN`
|
||||
// environment variable and they won't be providing a web idenity token file or access key either.
|
||||
// V2 of the action might relax this a bit and create an explicit precedence for these so that customers
|
||||
// can provide as much info as they want and we will follow the established credential loading precedence.
|
||||
return roleToAssume && process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN && !accessKeyId && !webIdentityTokenFile
|
||||
}
|
||||
|
||||
// Always export the source credentials and account ID.
|
||||
// The STS client for calling AssumeRole pulls creds from the environment.
|
||||
// Plus, in the assume role case, if the AssumeRole call fails, we want
|
||||
@@ -259,6 +297,16 @@ async function run() {
|
||||
exportCredentials({accessKeyId, secretAccessKey, sessionToken});
|
||||
}
|
||||
|
||||
// Attempt to load credentials from the GitHub OIDC provider.
|
||||
// If a user provides an IAM Role Arn and DOESN'T provide an Access Key Id
|
||||
// The only way to assume the role is via GitHub's OIDC provider.
|
||||
let sourceAccountId;
|
||||
let webIdentityToken;
|
||||
if(useGitHubOIDCProvider()) {
|
||||
webIdentityToken = await getWebIdentityToken();
|
||||
roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES;
|
||||
// We don't validate the credentials here because we don't have them yet when using OIDC.
|
||||
} else {
|
||||
// Regardless of whether any source credentials were provided as inputs,
|
||||
// validate that the SDK can actually pick up credentials. This validates
|
||||
// cases where this action is on a self-hosted runner that doesn't have credentials
|
||||
@@ -266,7 +314,8 @@ async function run() {
|
||||
// credentials but the secrets inputs resolved to empty strings.
|
||||
await validateCredentials(accessKeyId);
|
||||
|
||||
const sourceAccountId = await exportAccountId(maskAccountId, region);
|
||||
sourceAccountId = await exportAccountId(maskAccountId, region);
|
||||
}
|
||||
|
||||
// Get role credentials if configured to do so
|
||||
if (roleToAssume) {
|
||||
@@ -278,10 +327,19 @@ async function run() {
|
||||
roleDurationSeconds,
|
||||
roleSessionName,
|
||||
roleSkipSessionTagging,
|
||||
webIdentityTokenFile
|
||||
webIdentityTokenFile,
|
||||
webIdentityToken
|
||||
});
|
||||
exportCredentials(roleCredentials);
|
||||
// I don't know a good workaround for this. I'm not sure why we're validating the credentials
|
||||
// so frequently inside the action. The approach I've taken here is that if the GH OIDC token
|
||||
// isn't set, then we're in a self-hosted runner and we need to validate the credentials for
|
||||
// some mysterious reason that wasn't explained by whoever wrote this aciton.
|
||||
//
|
||||
// It's gross but it works so ... ¯\_(ツ)_/¯
|
||||
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) {
|
||||
await validateCredentials(roleCredentials.accessKeyId);
|
||||
}
|
||||
await exportAccountId(maskAccountId, region);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ const core = require('@actions/core');
|
||||
const assert = require('assert');
|
||||
const aws = require('aws-sdk');
|
||||
const run = require('./index.js');
|
||||
const axios = require('axios');
|
||||
|
||||
jest.mock('@actions/core');
|
||||
jest.mock("axios");
|
||||
|
||||
const FAKE_ACCESS_KEY_ID = 'MY-AWS-ACCESS-KEY-ID';
|
||||
const FAKE_SECRET_ACCESS_KEY = 'MY-AWS-SECRET-ACCESS-KEY';
|
||||
@@ -71,6 +73,11 @@ jest.mock('fs', () => {
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
jest.mock('axios', () => ({
|
||||
get: jest.fn(() => Promise.resolve({ data: { value: "testtoken" }})),
|
||||
}));
|
||||
|
||||
describe('Configure AWS Credentials', () => {
|
||||
const OLD_ENV = process.env;
|
||||
|
||||
@@ -561,6 +568,47 @@ describe('Configure AWS Credentials', () => {
|
||||
})
|
||||
});
|
||||
|
||||
test('only role arn and region provided to use GH OIDC Token', async () => {
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
|
||||
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION}));
|
||||
|
||||
await run();
|
||||
expect(mockStsAssumeRoleWithWebIdentity).toHaveBeenCalledWith({
|
||||
RoleArn: 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||
RoleSessionName: 'GitHubActions',
|
||||
DurationSeconds: 3600,
|
||||
WebIdentityToken: 'testtoken'
|
||||
});
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(1, FAKE_STS_ACCESS_KEY_ID);
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(2, FAKE_STS_SECRET_ACCESS_KEY);
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(3, FAKE_STS_SESSION_TOKEN);
|
||||
});
|
||||
|
||||
test('GH OIDC With custom role duration', async () => {
|
||||
const CUSTOM_ROLE_DURATION = 1234;
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
|
||||
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION, 'role-duration-seconds': CUSTOM_ROLE_DURATION}));
|
||||
|
||||
await run();
|
||||
expect(mockStsAssumeRoleWithWebIdentity).toHaveBeenCalledWith({
|
||||
RoleArn: 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||
RoleSessionName: 'GitHubActions',
|
||||
DurationSeconds: CUSTOM_ROLE_DURATION,
|
||||
WebIdentityToken: 'testtoken'
|
||||
});
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(1, FAKE_STS_ACCESS_KEY_ID);
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(2, FAKE_STS_SECRET_ACCESS_KEY);
|
||||
expect(core.setSecret).toHaveBeenNthCalledWith(3, FAKE_STS_SESSION_TOKEN);
|
||||
});
|
||||
|
||||
test('role external ID provided', async () => {
|
||||
core.getInput = jest
|
||||
.fn()
|
||||
|
||||
13
package-lock.json
generated
13
package-lock.json
generated
@@ -948,6 +948,14 @@
|
||||
"xml2js": "0.4.19"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.14.0"
|
||||
}
|
||||
},
|
||||
"babel-jest": {
|
||||
"version": "27.2.2",
|
||||
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-27.2.2.tgz",
|
||||
@@ -1774,6 +1782,11 @@
|
||||
"integrity": "sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==",
|
||||
"dev": true
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.14.4",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz",
|
||||
"integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g=="
|
||||
},
|
||||
"form-data": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
"homepage": "https://github.com/aws-actions/configure-aws-credentials#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.5.0",
|
||||
"aws-sdk": "^2.996.0"
|
||||
"aws-sdk": "^2.988.0",
|
||||
"axios": "^0.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
|
||||
Reference in New Issue
Block a user