mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-08-24 04:25:05 +09:00
Compare commits
56 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f24d7193d9 | |||
| f6095d9dc4 | |||
| df1fa04984 | |||
| 1c397386a2 | |||
| 21e0c4b1ca | |||
| b0f2baf098 | |||
| 4320d1b180 | |||
| 5d1959cbc9 | |||
| 3ecfae8a2c | |||
| 2f26d75abd | |||
| 658557f884 | |||
| f157a6574f | |||
| 9e38641911 | |||
| 2c168adcae | |||
| 4d5f2395c0 | |||
| a4f326760c | |||
| 93edf43b3a | |||
| fe54dce1bb | |||
| 423f4e15fb | |||
| 11e58be8bc | |||
| 7f5e3139fe | |||
| 5a0cf0167f | |||
| adb43a2cd3 | |||
| e62ae06aa8 | |||
| 66d7591932 | |||
| 76dfa67953 | |||
| ab246ce5fb | |||
| ca537c9527 | |||
| 72a198126f | |||
| 203a39c651 | |||
| c401b8a98c | |||
| 27e906a655 | |||
| 483d6b517a | |||
| c7765366a4 | |||
| ececac1a45 | |||
| 16fec6080f | |||
| eb70354fb4 | |||
| 3478c15aa1 | |||
| a69d38c39d | |||
| 6b1d0f829d | |||
| f021516513 | |||
| 1c8dbbcc02 | |||
| ce290d67fe | |||
| 1780ebd97b | |||
| a02ef26683 | |||
| 5fbd2e409b | |||
| f0af89b102 | |||
| b9ee51dc60 | |||
| 66c00faf39 | |||
| 134d71efe0 | |||
| b8ef615781 | |||
| e5b9735585 | |||
| 79ebbb3141 | |||
| 7f029f3507 | |||
| 39fd91c08e | |||
| cf624fbdad |
@@ -9,10 +9,7 @@ jobs:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
id-token: write
|
||||
if: >-
|
||||
github.event.review.state == 'approved' &&
|
||||
github.event.repository == 'aws/configure-aws-credentials' &&
|
||||
(github.event.review.author_association == 'OWNER' || github.event.review.user.login == 'aws-sdk-osds')
|
||||
if: ${{ github.event.review.state == 'approved' && github.repository == 'aws-actions/configure-aws-credentials' && (github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'MEMBER' || github.event.review.user.login == 'aws-sdk-osds') }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Configure AWS credentials
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Test Configure AWS Credential
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
cawsc:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: CAWSC
|
||||
uses: aws-actions/configure-aws-credentials@main
|
||||
with:
|
||||
aws-region: us-west-2
|
||||
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
||||
role-duration-seconds: 900
|
||||
role-session-name: TestCAWSC
|
||||
- name: Whoami
|
||||
run: |
|
||||
aws sts get-caller-identity
|
||||
@@ -1,11 +1,16 @@
|
||||
name: Dependabot auto-approve
|
||||
on: pull_request
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
id-token: write
|
||||
contents: read
|
||||
jobs:
|
||||
dependabot:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'aws/configure-aws-credentials'
|
||||
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'aws-actions/configure-aws-credentials' }}
|
||||
steps:
|
||||
- name: Get Metadata
|
||||
id: dependabot-metadata
|
||||
@@ -16,9 +21,8 @@ jobs:
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-region: us-west-2
|
||||
role-to-assume: ${{ secrets.SECRETS_AWS_PACKAGING_ROLE_TO_ASSUME }}
|
||||
role-to-assume: arn:aws:iam::206735643321:role/ConfigureAwsCredentialsPackageRole
|
||||
role-duration-seconds: 900
|
||||
role-session-name: SecretsManagerFetch
|
||||
- name: Get bot user token
|
||||
uses: aws-actions/aws-secretsmanager-get-secrets@v2
|
||||
with:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
".release-please-manifest.json": "4.0.2",
|
||||
"package.json": "4.0.2",
|
||||
".": "4.0.3"
|
||||
".": "4.2.0"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,36 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## [4.2.0](https://github.com/aws-actions/configure-aws-credentials/compare/v4.1.0...v4.2.0) (2025-05-06)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add Expiration field to Outputs ([a4f3267](https://github.com/aws-actions/configure-aws-credentials/commit/a4f326760c1c1bf49ab86051c658d6501816b930))
|
||||
* Document role-duration-seconds range ([5a0cf01](https://github.com/aws-actions/configure-aws-credentials/commit/5a0cf0167f837dfa7af7d951ba6a78a38dc2b79e))
|
||||
* support action inputs as environment variables ([#1338](https://github.com/aws-actions/configure-aws-credentials/issues/1338)) ([2c168ad](https://github.com/aws-actions/configure-aws-credentials/commit/2c168adcae62d67531ba83842723c8f30695116a))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* make sure action builds, also fix dependabot autoapprove ([c401b8a](https://github.com/aws-actions/configure-aws-credentials/commit/c401b8a98c5067672f52e0387cdd87d54acfe1fd))
|
||||
* role chaning on mulitple runs ([#1340](https://github.com/aws-actions/configure-aws-credentials/issues/1340)) ([9e38641](https://github.com/aws-actions/configure-aws-credentials/commit/9e386419117a9edd458297e4f1822a5df7506a03))
|
||||
|
||||
## [4.1.0](https://github.com/aws-actions/configure-aws-credentials/compare/v4.0.3...v4.1.0) (2025-02-08)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* idempotent fetch ([#1289](https://github.com/aws-actions/configure-aws-credentials/issues/1289)) ([eb70354](https://github.com/aws-actions/configure-aws-credentials/commit/eb70354fb423a380b6e4ab4b9f15d2ee9ffae911))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* build failure due to tests ([#1283](https://github.com/aws-actions/configure-aws-credentials/issues/1283)) ([134d71e](https://github.com/aws-actions/configure-aws-credentials/commit/134d71efe0ecbe9ad6965f2f766c0cae63a7685f))
|
||||
* Dependabot autoapprove ([#1284](https://github.com/aws-actions/configure-aws-credentials/issues/1284)) ([b9ee51d](https://github.com/aws-actions/configure-aws-credentials/commit/b9ee51dc600fe38c892e24f60ca26476e0e0b6de))
|
||||
* Dependabot autoapprove id-token write permission ([#1285](https://github.com/aws-actions/configure-aws-credentials/issues/1285)) ([f0af89b](https://github.com/aws-actions/configure-aws-credentials/commit/f0af89b102390dcf10ce402195d74a98f24861f3))
|
||||
* typo ([#1281](https://github.com/aws-actions/configure-aws-credentials/issues/1281)) ([39fd91c](https://github.com/aws-actions/configure-aws-credentials/commit/39fd91c08ed8bf770034de4e62662503e8007d76))
|
||||
|
||||
## [4.0.3](https://github.com/aws-actions/configure-aws-credentials/compare/v4.0.2...v4.0.3) (2025-01-27)
|
||||
|
||||
|
||||
|
||||
@@ -105,17 +105,18 @@ See [action.yml](./action.yml) for more detail.
|
||||
| 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-duration-seconds | The assumed role duration in seconds, if assuming a role. Defaults to 1 hour (3600 seconds). Acceptable values range from 15 minutes (900 seconds) to 12 hours (43200 seconds). | 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 |
|
||||
| output-credentials | When set, outputs fetched credentials as action step output. (Outputs access-key-id, secret-access-key, session-token, and expiration). 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 |
|
||||
|
||||
#### Credential Lifetime
|
||||
The default session duration is **1 hour**.
|
||||
@@ -130,7 +131,13 @@ with the `role-external-id` input
|
||||
|
||||
#### Session tagging and name
|
||||
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
|
||||
the desired name in `role-session-name`.
|
||||
|
||||
_Note: you might find it helpful to set the `role-session-name` to `${{ github.run_id }}`
|
||||
so as to clarify in audit logs which AWS actions were performed by which workflow
|
||||
run._
|
||||
|
||||
The session will be tagged with the
|
||||
following tags: (Refer to [GitHub's documentation for `GITHUB_` environment
|
||||
variable definitions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables))
|
||||
|
||||
@@ -183,7 +190,7 @@ line like this:
|
||||
```
|
||||
Or we can have a nicely formatted JSON as well:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
inline-session-policy: >-
|
||||
{
|
||||
@@ -204,13 +211,13 @@ 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:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
managed-session-policies: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
||||
```
|
||||
And we can pass multiple managed policies likes this:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
managed-session-policies: |
|
||||
arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
|
||||
@@ -285,7 +292,7 @@ You can specify the audience through the `audience` input:
|
||||
|
||||
```yaml
|
||||
- name: Configure AWS Credentials for China region audience
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
audience: sts.amazonaws.com.cn
|
||||
aws-region: us-east-3
|
||||
@@ -420,7 +427,7 @@ You can use this action to simply configure the region and account ID in the
|
||||
environment, and then use the runner's credentials for all AWS API calls made by
|
||||
your Actions workflow:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
```
|
||||
@@ -430,7 +437,7 @@ APIs called by your Actions workflow.
|
||||
Or, you can use this action to assume a role, and then use the role credentials
|
||||
for all AWS API calls made by your Actions workflow:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: my-github-actions-role
|
||||
@@ -452,7 +459,7 @@ variable.
|
||||
|
||||
Manually configured proxy:
|
||||
```yaml
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: my-github-actions-role
|
||||
@@ -479,7 +486,7 @@ should include the AWS CLI by default.
|
||||
### AssumeRoleWithWebIdentity (recommended)
|
||||
```yaml
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||
@@ -493,13 +500,13 @@ environment variable and use it to assume the role
|
||||
### AssumeRole with role previously assumed by action in same workflow
|
||||
```yaml
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||
role-session-name: MySessionName
|
||||
- name: Configure other AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: arn:aws:iam::987654321000:role/my-second-role
|
||||
@@ -514,7 +521,7 @@ role, `arn:aws:iam::987654321000:role/my-second-role`.
|
||||
### AssumeRole with static IAM credentials in repository secrets
|
||||
```yaml
|
||||
- name: Configure AWS Credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
@@ -533,7 +540,7 @@ name, like `role-to-assume: my-github-actions-role`.
|
||||
```yaml
|
||||
- name: Configure AWS Credentials 1
|
||||
id: creds
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
|
||||
@@ -542,7 +549,7 @@ name, like `role-to-assume: my-github-actions-role`.
|
||||
run: |
|
||||
aws sts get-caller-identity
|
||||
- name: Configure AWS Credentials 2
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
uses: aws-actions/configure-aws-credentials@v4.1.0
|
||||
with:
|
||||
aws-region: us-east-2
|
||||
aws-access-key-id: ${{ steps.creds.outputs.aws-access-key-id }}
|
||||
|
||||
@@ -73,6 +73,8 @@ inputs:
|
||||
special-characters-workaround:
|
||||
description: Some environments do not support special characters in AWS_SECRET_ACCESS_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. This option is disabled by default
|
||||
required: false
|
||||
use-existing-credentials:
|
||||
description: When enabled, this option will check if there are already valid credentials in the environment. If there are, new credentials will not be fetched. If there are not, the action will run as normal.
|
||||
outputs:
|
||||
aws-account-id:
|
||||
description: The AWS account ID for the provided credentials
|
||||
|
||||
+5068
-6438
File diff suppressed because it is too large
Load Diff
-14
@@ -1,14 +0,0 @@
|
||||
import { STSClient } from '@aws-sdk/client-sts';
|
||||
export interface CredentialsClientProps {
|
||||
region?: string;
|
||||
proxyServer?: string;
|
||||
}
|
||||
export declare class CredentialsClient {
|
||||
region?: string;
|
||||
private _stsClient?;
|
||||
private readonly requestHandler?;
|
||||
constructor(props: CredentialsClientProps);
|
||||
get stsClient(): STSClient;
|
||||
validateCredentials(expectedAccessKeyId?: string, roleChaining?: boolean): Promise<void>;
|
||||
private loadCredentials;
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
import type { CredentialsClient } from './CredentialsClient';
|
||||
export interface assumeRoleParams {
|
||||
credentialsClient: CredentialsClient;
|
||||
roleToAssume: string;
|
||||
roleDuration: number;
|
||||
roleSessionName: string;
|
||||
roleSkipSessionTagging?: boolean;
|
||||
sourceAccountId?: string;
|
||||
roleExternalId?: string;
|
||||
webIdentityTokenFile?: string;
|
||||
webIdentityToken?: string;
|
||||
inlineSessionPolicy?: string;
|
||||
managedSessionPolicies?: {
|
||||
arn: string;
|
||||
}[];
|
||||
}
|
||||
export declare function assumeRole(params: assumeRoleParams): Promise<import("@aws-sdk/client-sts").AssumeRoleCommandOutput>;
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* When the GitHub Actions job is done, clean up any environment variables that
|
||||
* may have been set by the configure-aws-credentials steps in the job.
|
||||
*
|
||||
* Environment variables are not intended to be shared across different jobs in
|
||||
* the same GitHub Actions workflow: GitHub Actions documentation states that
|
||||
* each job runs in a fresh instance. However, doing our own cleanup will
|
||||
* give us additional assurance that these environment variables are not shared
|
||||
* with any other jobs.
|
||||
*/
|
||||
export declare function cleanup(): void;
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
import type { Credentials } from '@aws-sdk/client-sts';
|
||||
import type { CredentialsClient } from './CredentialsClient';
|
||||
export declare function exportCredentials(creds?: Partial<Credentials>, outputCredentials?: boolean): void;
|
||||
export declare function unsetCredentials(): void;
|
||||
export declare function exportRegion(region: string): void;
|
||||
export declare function exportAccountId(credentialsClient: CredentialsClient, maskAccountId?: boolean): Promise<string>;
|
||||
export declare function sanitizeGitHubVariables(name: string): string;
|
||||
export declare function defaultSleep(ms: number): Promise<unknown>;
|
||||
declare let sleep: typeof defaultSleep;
|
||||
export declare function withsleep(s: typeof sleep): void;
|
||||
export declare function reset(): void;
|
||||
export declare function verifyKeys(creds: Partial<Credentials> | undefined): boolean;
|
||||
export declare function retryAndBackoff<T>(fn: () => Promise<T>, isRetryable: boolean, maxRetries?: number, retries?: number, base?: number): Promise<T>;
|
||||
export declare function errorMessage(error: unknown): string;
|
||||
export declare function isDefined<T>(i: T | undefined | null): i is T;
|
||||
export {};
|
||||
-1
@@ -1 +0,0 @@
|
||||
export declare function run(): Promise<void>;
|
||||
-1
@@ -1 +0,0 @@
|
||||
export {};
|
||||
-1
@@ -1 +0,0 @@
|
||||
export {};
|
||||
-1
@@ -1 +0,0 @@
|
||||
export {};
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
import type * as core from '@actions/core';
|
||||
declare const _default: {
|
||||
readonly outputs: {
|
||||
STS_CREDENTIALS: {
|
||||
Credentials: {
|
||||
AccessKeyId: string;
|
||||
SecretAccessKey: string;
|
||||
SessionToken: string;
|
||||
Expiration: Date;
|
||||
};
|
||||
AssumedRoleUser: {
|
||||
Arn: string;
|
||||
AssumedRoleId: string;
|
||||
};
|
||||
};
|
||||
GET_CALLER_IDENTITY: {
|
||||
Account: string;
|
||||
Arn: string;
|
||||
};
|
||||
FAKE_STS_ACCESS_KEY_ID: string;
|
||||
FAKE_STS_SECRET_ACCESS_KEY: string;
|
||||
FAKE_STS_SESSION_TOKEN: string;
|
||||
ODD_CHARACTER_CREDENTIALS: {
|
||||
Credentials: {
|
||||
AccessKeyId: string;
|
||||
SecretAccessKey: string;
|
||||
SessionToken: string;
|
||||
Expiration: Date;
|
||||
};
|
||||
AssumedRoleUser: {
|
||||
Arn: string;
|
||||
AssumedRoleId: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
readonly envs: {
|
||||
GITHUB_REPOSITORY: string;
|
||||
GITHUB_WORKFLOW: string;
|
||||
GITHUB_ACTION: string;
|
||||
GITHUB_ACTOR: string;
|
||||
GITHUB_SHA: string;
|
||||
GITHUB_WORKSPACE: string;
|
||||
GITHUB_ACTIONS: string;
|
||||
};
|
||||
readonly GH_OIDC_INPUTS: {
|
||||
'role-to-assume': string;
|
||||
'aws-region': string;
|
||||
'special-characters-workaround': string;
|
||||
};
|
||||
readonly IAM_USER_INPUTS: {
|
||||
'aws-access-key-id': string;
|
||||
'aws-secret-access-key': string;
|
||||
'aws-region': string;
|
||||
};
|
||||
readonly IAM_ASSUMEROLE_INPUTS: {
|
||||
'aws-access-key-id': string;
|
||||
'aws-secret-access-key': string;
|
||||
'role-to-assume': string;
|
||||
'aws-region': string;
|
||||
};
|
||||
readonly WEBIDENTITY_TOKEN_FILE_INPUTS: {
|
||||
'web-identity-token-file': string;
|
||||
'role-to-assume': string;
|
||||
'aws-region': string;
|
||||
};
|
||||
readonly EXISTING_ROLE_INPUTS: {
|
||||
'role-to-assume': string;
|
||||
'role-chaining': string;
|
||||
'aws-region': string;
|
||||
};
|
||||
readonly getInput: (fakeEnv: Record<string, string>) => (name: string, options?: core.InputOptions) => string;
|
||||
readonly getMultilineInput: (fakeEnv: Record<string, string[]>) => (name: string, options?: core.InputOptions) => string[];
|
||||
};
|
||||
export default _default;
|
||||
+4495
-7141
File diff suppressed because it is too large
Load Diff
Generated
+1090
-1119
File diff suppressed because it is too large
Load Diff
+11
-11
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "configure-aws-credentials",
|
||||
"description": "A GitHub Action to configure AWS credentials",
|
||||
"version": "4.0.3",
|
||||
"version": "4.2.0",
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.build.json",
|
||||
"build": "tsc",
|
||||
"lint": "biome check --error-on-warnings ./src",
|
||||
"package": "npm run build && ncc build --license THIRD-PARTY -o dist && ncc build src/cleanup/index.ts -o dist/cleanup && cpy dist/THIRD-PARTY . && del-cli dist/THIRD-PARTY",
|
||||
"test": "npm run lint && vitest run"
|
||||
"test": "npm run lint && vitest run && npm run build"
|
||||
},
|
||||
"author": {
|
||||
"name": "Amazon.com, Inc. or its affiliates",
|
||||
@@ -16,22 +16,22 @@
|
||||
"devDependencies": {
|
||||
"@aws-sdk/credential-provider-env": "^3.515.0",
|
||||
"@biomejs/biome": "1.9.4",
|
||||
"@smithy/property-provider": "^3.1.7",
|
||||
"@types/node": "^22.9.0",
|
||||
"@vercel/ncc": "^0.38.2",
|
||||
"@vitest/coverage-v8": "^2.1.3",
|
||||
"@smithy/property-provider": "^4.0.1",
|
||||
"@types/node": "^22.15.11",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"@vitest/coverage-v8": "^3.1.2",
|
||||
"aws-sdk-client-mock": "^4.1.0",
|
||||
"cpy-cli": "^5.0.0",
|
||||
"del-cli": "^6.0.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"memfs": "^4.14.0",
|
||||
"memfs": "^4.17.1",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^5.6.3",
|
||||
"vitest": "^2.1.3"
|
||||
"typescript": "^5.8.3",
|
||||
"vitest": "^3.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@aws-sdk/client-sts": "^3.675.0",
|
||||
"@aws-sdk/client-sts": "^3.803.0",
|
||||
"@smithy/node-http-handler": "^4.0.1",
|
||||
"https-proxy-agent": "^5.0.1"
|
||||
},
|
||||
|
||||
@@ -7,6 +7,35 @@ const MAX_TAG_VALUE_LENGTH = 256;
|
||||
const SANITIZATION_CHARACTER = '_';
|
||||
const SPECIAL_CHARS_REGEX = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]+/;
|
||||
|
||||
export function translateEnvVariables() {
|
||||
const envVars = [
|
||||
'AWS_REGION',
|
||||
'ROLE_TO_ASSUME',
|
||||
'WEB_IDENTITY_TOKEN_FILE',
|
||||
'ROLE_CHAINING',
|
||||
'AUDIENCE',
|
||||
'HTTP_PROXY',
|
||||
'MASK_AWS_ACCOUNT_ID',
|
||||
'ROLE_DURATION_SECONDS',
|
||||
'ROLE_EXTERNAL_ID',
|
||||
'ROLE_SESSION_NAME',
|
||||
'ROLE_SKIP_SESSION_TAGGING',
|
||||
'INLINE_SESSION_POLICY',
|
||||
'MANAGED_SESSION_POLICIES',
|
||||
'OUTPUT_CREDENTIALS',
|
||||
'UNSET_CURRENT_CREDENTIALS',
|
||||
'DISABLE_RETRY',
|
||||
'RETRY_MAX_ATTEMPTS',
|
||||
'SPECIAL_CHARACTERS_WORKAROUND',
|
||||
'USE_EXISTING_CREDENTIALS',
|
||||
];
|
||||
for (const envVar of envVars) {
|
||||
if (process.env[envVar]) {
|
||||
process.env[`INPUT_${envVar.replace(/_/g, '-')}`] = process.env[envVar];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the AWS CLI and AWS SDKs using environment variables and set them as secrets.
|
||||
// Setting the credentials as secrets masks them in Github Actions logs
|
||||
export function exportCredentials(creds?: Partial<Credentials>, outputCredentials?: boolean) {
|
||||
@@ -38,6 +67,9 @@ export function exportCredentials(creds?: Partial<Credentials>, outputCredential
|
||||
if (creds?.SessionToken) {
|
||||
core.setOutput('aws-session-token', creds.SessionToken);
|
||||
}
|
||||
if (creds?.Expiration) {
|
||||
core.setOutput('aws-expiration', creds.Expiration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,3 +176,16 @@ export function isDefined<T>(i: T | undefined | null): i is T {
|
||||
return i !== undefined && i !== null;
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
|
||||
export async function areCredentialsValid(credentialsClient: CredentialsClient) {
|
||||
const client = credentialsClient.stsClient;
|
||||
try {
|
||||
const identity = await client.send(new GetCallerIdentityCommand({}));
|
||||
if (identity.Account) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ import type { AssumeRoleCommandOutput } from '@aws-sdk/client-sts';
|
||||
import { CredentialsClient } from './CredentialsClient';
|
||||
import { assumeRole } from './assumeRole';
|
||||
import {
|
||||
areCredentialsValid,
|
||||
errorMessage,
|
||||
exportAccountId,
|
||||
exportCredentials,
|
||||
exportRegion,
|
||||
retryAndBackoff,
|
||||
translateEnvVariables,
|
||||
unsetCredentials,
|
||||
verifyKeys,
|
||||
} from './helpers';
|
||||
@@ -18,6 +20,7 @@ const REGION_REGEX = /^[a-z0-9-]+$/g;
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
translateEnvVariables();
|
||||
// Get inputs
|
||||
const AccessKeyId = core.getInput('aws-access-key-id', { required: false });
|
||||
const SecretAccessKey = core.getInput('aws-secret-access-key', {
|
||||
@@ -60,6 +63,8 @@ export async function run() {
|
||||
const specialCharacterWorkaroundInput =
|
||||
core.getInput('special-characters-workaround', { required: false }) || 'false';
|
||||
const specialCharacterWorkaround = specialCharacterWorkaroundInput.toLowerCase() === 'true';
|
||||
const useExistingCredentialsInput = core.getInput('use-existing-credentials', { required: false }) || 'false';
|
||||
const useExistingCredentials = useExistingCredentialsInput.toLowerCase() === 'true';
|
||||
let maxRetries = Number.parseInt(core.getInput('retry-max-attempts', { required: false })) || 12;
|
||||
switch (true) {
|
||||
case specialCharacterWorkaround:
|
||||
@@ -116,6 +121,16 @@ export async function run() {
|
||||
let sourceAccountId: string;
|
||||
let webIdentityToken: string;
|
||||
|
||||
//if the user wants to attempt to use existing credentials, check if we have some already
|
||||
if (useExistingCredentials) {
|
||||
const validCredentials = await areCredentialsValid(credentialsClient);
|
||||
if (validCredentials) {
|
||||
core.notice('Pre-existing credentials are valid. No need to generate new ones.');
|
||||
return;
|
||||
}
|
||||
core.notice('No valid credentials exist. Running as normal.');
|
||||
}
|
||||
|
||||
// If OIDC is being used, generate token
|
||||
// Else, export credentials provided as input
|
||||
if (useGitHubOIDCProvider()) {
|
||||
|
||||
@@ -27,8 +27,8 @@ describe('Configure AWS Credentials helpers', {}, () => {
|
||||
vi.spyOn(core, 'setOutput').mockImplementation(() => {});
|
||||
vi.spyOn(core, 'setSecret').mockImplementation(() => {});
|
||||
vi.spyOn(core, 'exportVariable').mockImplementation(() => {});
|
||||
helpers.exportCredentials({ AccessKeyId: 'test', SecretAccessKey: 'test', SessionToken: 'test' }, true);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(3);
|
||||
helpers.exportCredentials({ AccessKeyId: 'test', SecretAccessKey: 'test', SessionToken: 'test', Expiration: new Date(8640000000000000) }, true);
|
||||
expect(core.setOutput).toHaveBeenCalledTimes(4);
|
||||
expect(core.setSecret).toHaveBeenCalledTimes(3);
|
||||
expect(core.exportVariable).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
@@ -27,6 +27,7 @@ describe('Configure AWS Credentials', {}, () => {
|
||||
vi.spyOn(core, 'setOutput').mockImplementation((_n, _v) => {});
|
||||
vi.spyOn(core, 'debug').mockImplementation((_m) => {});
|
||||
vi.spyOn(core, 'info').mockImplementation((_m) => {});
|
||||
vi.spyOn(core, 'notice').mockImplementation((_m) => {});
|
||||
// Remove any existing environment variables before each test to prevent the
|
||||
// SDK from picking them up
|
||||
process.env = { ...mocks.envs };
|
||||
@@ -299,5 +300,17 @@ describe('Configure AWS Credentials', {}, () => {
|
||||
await run();
|
||||
expect(core.setFailed).toHaveBeenCalled();
|
||||
});
|
||||
it('gets new creds if told to reuse existing but they\'re invalid', {}, async () => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation(mocks.getInput(mocks.USE_EXISTING_CREDENTIALS_INPUTS));
|
||||
mockedSTSClient.on(GetCallerIdentityCommand).rejects();
|
||||
await run();
|
||||
expect(core.notice).toHaveBeenCalledWith('No valid credentials exist. Running as normal.')
|
||||
});
|
||||
it('doesn\'t get new creds if there are already valid ones and we said use them', {}, async () => {
|
||||
vi.spyOn(core, 'getInput').mockImplementation(mocks.getInput(mocks.USE_EXISTING_CREDENTIALS_INPUTS));
|
||||
mockedSTSClient.on(GetCallerIdentityCommand).resolves(mocks.outputs.GET_CALLER_IDENTITY);
|
||||
await run();
|
||||
expect(core.setFailed).not.toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,6 +27,11 @@ const inputs = {
|
||||
'role-chaining': 'true',
|
||||
'aws-region': 'fake-region-1',
|
||||
},
|
||||
USE_EXISTING_CREDENTIALS_INPUTS: {
|
||||
'aws-region': 'fake-region-1',
|
||||
'use-existing-credentials': 'true',
|
||||
'role-to-assume': 'arn:aws:iam::111111111111:role/MY-ROLE',
|
||||
}
|
||||
};
|
||||
|
||||
const envs = {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": [
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "src"
|
||||
},
|
||||
}
|
||||
+7
-5
@@ -13,7 +13,7 @@
|
||||
"module": "CommonJS",
|
||||
"resolveJsonModule": true,
|
||||
"outDir": "build",
|
||||
"declaration": true,
|
||||
"declaration": false,
|
||||
"newLine": "lf",
|
||||
"noEmitOnError": true,
|
||||
"sourceMap": true,
|
||||
@@ -22,12 +22,14 @@
|
||||
"lib": [ "ES2020" ],
|
||||
"target": "ES2020",
|
||||
"noErrorTruncation": true,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"rootDir": "src",
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/*.test.ts"
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"exclude": [],
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": [
|
||||
"test/**/*.ts",
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./"
|
||||
},
|
||||
}
|
||||
@@ -5,5 +5,6 @@ export default defineConfig({
|
||||
passWithNoTests: true,
|
||||
include: ['test/**/*.test.ts'],
|
||||
coverage: { enabled: true },
|
||||
typecheck: { tsconfig: './tsconfig.test.json' },
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user