Skip to content

Commit 91d9dfc

Browse files
authored
Merge branch 'main' into contri
2 parents f5f46df + 76997ec commit 91d9dfc

File tree

10 files changed

+217
-116
lines changed

10 files changed

+217
-116
lines changed

.github/workflows/tests-integ.yml

+22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ jobs:
4848
role-to-assume: ${{ secrets.SECRETS_AWS_ROLE_TO_ASSUME }}
4949
role-session-name: IntegAccessKeysAssumeRole
5050
role-external-id: ${{ secrets.SECRETS_AWS_ROLE_EXTERNAL_ID }}
51+
integ-access-keys-env:
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
os: [[self-hosted, linux-fargate], windows-latest, ubuntu-latest, macos-latest]
56+
node: [14, 16, 18]
57+
name: Run access key from env integ tests
58+
runs-on: ${{ matrix.os }}
59+
timeout-minutes: 30
60+
steps:
61+
- name: "Checkout repository"
62+
uses: actions/checkout@v3
63+
- name: Integ test for access keys
64+
uses: ./
65+
env:
66+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
67+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68+
with:
69+
aws-region: us-west-2
70+
role-to-assume: ${{ secrets.SECRETS_AWS_ROLE_TO_ASSUME }}
71+
role-session-name: IntegAccessKeysAssumeRole
72+
role-external-id: ${{ secrets.SECRETS_AWS_ROLE_EXTERNAL_ID }}
5173
integ-iam-user:
5274
strategy:
5375
fail-fast: false

README.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,15 @@ We recommend using [GitHub's OIDC provider](https://docs.github.com/en/actions/d
161161

162162
The following table describes which method is used based on which values are supplied to the Action:
163163

164-
| **Identity Used** | `aws-access-key-id` | `role-to-assume` | `web-identity-token-file` | `role-chaining` |
165-
| --------------------------------------------------------------- | ------------------- | ---------------- | ------------------------- | - |
166-
| [✅ Recommended] Assume Role directly using GitHub OIDC provider | | ✔ | | |
167-
| IAM User | ✔ | | | |
168-
| Assume Role using IAM User credentials | ✔ | ✔ | | |
169-
| Assume Role using WebIdentity Token File credentials | | ✔ | ✔ | |
170-
| Assume Role using existing credentials | | ✔ | | ✔ |
164+
| **Identity Used** | `aws-access-key-id` | `role-to-assume` | `web-identity-token-file` | `role-chaining` | `id-token` permission
165+
| --------------------------------------------------------------- | ------------------- | ---------------- | ------------------------- | - | - |
166+
| [✅ Recommended] Assume Role directly using GitHub OIDC provider | | ✔ | | | ✔ |
167+
| IAM User | ✔ | | | | |
168+
| Assume Role using IAM User credentials | ✔ | ✔ | | | |
169+
| Assume Role using WebIdentity Token File credentials | | ✔ | ✔ | | |
170+
| Assume Role using existing credentials | | ✔ | | ✔ | |
171+
172+
*Note: `role-chaining` is not necessary to use existing credentials in every use case. If you're getting a "Credentials loaded by the SDK do not match" error, try enabling this prop.
171173

172174
### Credential Lifetime
173175
The default session duration is **1 hour**.
@@ -268,6 +270,15 @@ Your account ID is not masked by default in workflow logs since it's not conside
268270
#### Unset current credentials
269271
Sometimes, existing credentials in your runner can get in the way of the intended outcome, and the recommended solution is to include another step in your workflow which unsets the environment variables set by this action. Now if you set the `unset-current-credentials` input to `true`, the workaround is made eaiser
270272

273+
#### Special characters in AWS_SECRET_ACCESS_KEY
274+
Some edge cases are unable to properly parse an `AWS_SECRET_ACCESS_KEY` if it
275+
contains special characters. For more information, please see the
276+
[AWS CLI documentation](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-troubleshooting.html#tshoot-signature-does-not-match).
277+
If you set the `special-characters-workaround` option, this action will
278+
continually retry fetching credentials until we get one that does not have
279+
special characters. This option overrides the `disable-retry` and
280+
`retry-max-attempts` options.
281+
271282
## OIDC
272283

273284
We recommend using [GitHub's OIDC provider](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) to get short-lived AWS credentials needed for your actions. When using OIDC, this action will create a JWT unique to the workflow run, and it will use this JWT to assume the role. For this action to create the JWT, it is required for your workflow to have the `id-token: write` permission:

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ inputs:
7070
retry-max-attempts:
7171
description: The maximum number of attempts it will attempt to retry the assume role call. By default it will retry 12 times
7272
required: false
73+
special-characters-workaround:
74+
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
75+
required: false
7376
outputs:
7477
aws-account-id:
7578
description: The AWS account ID for the provided credentials

dist/cleanup/index.js

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cleanup/src/helpers.d.ts

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

+45-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assumeRole.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as core from '@actions/core';
55
import type { AssumeRoleCommandInput, STSClient, Tag } from '@aws-sdk/client-sts';
66
import { AssumeRoleCommand, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts';
77
import type { CredentialsClient } from './CredentialsClient';
8-
import { errorMessage, isDefined, sanitizeGitHubVariables, verifyKeys } from './helpers';
8+
import { errorMessage, isDefined, sanitizeGitHubVariables } from './helpers';
99

1010
async function assumeRoleWithOIDC(params: AssumeRoleCommandInput, client: STSClient, webIdentityToken: string) {
1111
delete params.Tags;
@@ -17,7 +17,6 @@ async function assumeRoleWithOIDC(params: AssumeRoleCommandInput, client: STSCli
1717
WebIdentityToken: webIdentityToken,
1818
})
1919
);
20-
verifyKeys(creds.Credentials);
2120
return creds;
2221
} catch (error) {
2322
throw new Error(`Could not assume role with OIDC: ${errorMessage(error)}`);
@@ -49,7 +48,6 @@ async function assumeRoleWithWebIdentityTokenFile(
4948
WebIdentityToken: webIdentityToken,
5049
})
5150
);
52-
verifyKeys(creds.Credentials);
5351
return creds;
5452
} catch (error) {
5553
throw new Error(`Could not assume role with web identity token file: ${errorMessage(error)}`);
@@ -60,7 +58,6 @@ async function assumeRoleWithCredentials(params: AssumeRoleCommandInput, client:
6058
core.info('Assuming role with user credentials');
6159
try {
6260
const creds = await client.send(new AssumeRoleCommand({ ...params }));
63-
verifyKeys(creds.Credentials);
6461
return creds;
6562
} catch (error) {
6663
throw new Error(`Could not assume role with user credentials: ${errorMessage(error)}`);

src/helpers.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,21 @@ export function reset() {
9393

9494
export function verifyKeys(creds: Partial<Credentials> | undefined) {
9595
if (!creds) {
96-
return;
96+
return false;
9797
}
9898
if (creds.AccessKeyId) {
9999
if (SPECIAL_CHARS_REGEX.test(creds.AccessKeyId)) {
100-
throw new Error('AccessKeyId contains special characters.');
100+
core.debug('AccessKeyId contains special characters.');
101+
return false;
101102
}
102103
}
103104
if (creds.SecretAccessKey) {
104105
if (SPECIAL_CHARS_REGEX.test(creds.SecretAccessKey)) {
105-
throw new Error('SecretAccessKey contains special characters.');
106+
core.debug('SecretAccessKey contains special characters.');
107+
return false;
106108
}
107109
}
110+
return true;
108111
}
109112

110113
// Retries the promise with exponential backoff if the error isRetryable up to maxRetries time.

0 commit comments

Comments
 (0)