Skip to content

Commit d78f55b

Browse files
fix: validation logic throwing unwanted errors (#818)
* fix: throws error even when valid credentials are present * fix: throws error when invalid credentials are present despite not wanting to use them
1 parent 6c962b9 commit d78f55b

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

Diff for: .github/workflows/tests-integ.yml

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run tests
1+
name: Run Integ tests
22

33
on:
44
workflow_dispatch:
@@ -27,6 +27,33 @@ jobs:
2727
role-duration-seconds: 900
2828
role-session-name: IntegOidcAssumeRole
2929
role-external-id: ${{ secrets.SECRETS_OIDC_AWS_ROLE_EXTERNAL_ID }}
30+
integ-oidc-env:
31+
permissions:
32+
contents: read
33+
id-token: write
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
os: [[self-hosted, linux-fargate], windows-latest, ubuntu-latest, macos-latest]
38+
node: [14, 16, 18]
39+
name: Run OIDC integ tests with existing invalid env vars
40+
runs-on: ${{ matrix.os }}
41+
env:
42+
AWS_ACCESS_KEY_ID: dummyaccesskeyid
43+
AWS_SECRET_ACCESS_KEY: dummysecretkey
44+
AWS_SESSION_TOKEN: dummytoken
45+
timeout-minutes: 30
46+
steps:
47+
- name: "Checkout repository"
48+
uses: actions/checkout@v3
49+
- name: Integ test for OIDC
50+
uses: ./
51+
with:
52+
aws-region: us-west-2
53+
role-to-assume: ${{ secrets.SECRETS_OIDC_AWS_ROLE_TO_ASSUME }}
54+
role-duration-seconds: 900
55+
role-session-name: IntegOidcAssumeRole
56+
role-external-id: ${{ secrets.SECRETS_OIDC_AWS_ROLE_EXTERNAL_ID }}
3057
integ-access-keys:
3158
strategy:
3259
fail-fast: false

Diff for: dist/index.js

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

Diff for: src/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,13 @@ export async function run() {
128128
// the source credentials to already be masked as secrets
129129
// in any error messages.
130130
exportCredentials({ AccessKeyId, SecretAccessKey, SessionToken });
131-
} else if (
132-
!webIdentityTokenFile &&
133-
!roleChaining &&
134-
!(process.env['AWS_ACCESS_KEY_ID'] && process.env['AWS_SECRET_ACCESS_KEY'])
135-
) {
136-
throw new Error('Could not determine how to assume credentials. Please check your inputs and try again.');
131+
} else if (!webIdentityTokenFile && !roleChaining) {
132+
// Proceed only if credentials can be picked up
133+
await credentialsClient.validateCredentials();
134+
sourceAccountId = await exportAccountId(credentialsClient, maskAccountId);
137135
}
138136

139-
if (AccessKeyId || roleChaining || (process.env['AWS_ACCESS_KEY_ID'] && process.env['AWS_SECRET_ACCESS_KEY'])) {
137+
if (AccessKeyId || roleChaining) {
140138
// Validate that the SDK can actually pick up credentials.
141139
// This validates cases where this action is using existing environment credentials,
142140
// and cases where the user intended to provide input credentials but the secrets inputs resolved to empty strings.

Diff for: test/index.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ describe('Configure AWS Credentials', () => {
202202
await run();
203203

204204
expect(core.setFailed).toHaveBeenCalledWith(
205-
'Could not determine how to assume credentials. Please check your inputs and try again.'
205+
'Credentials could not be loaded, please check your action inputs: Could not load credentials from any providers'
206206
);
207207
});
208208

@@ -217,7 +217,7 @@ describe('Configure AWS Credentials', () => {
217217
await run();
218218

219219
expect(core.setFailed).toHaveBeenCalledWith(
220-
'Could not determine how to assume credentials. Please check your inputs and try again.'
220+
'Credentials could not be loaded, please check your action inputs: Access key ID empty after loading credentials'
221221
);
222222
});
223223

@@ -508,6 +508,7 @@ describe('Configure AWS Credentials', () => {
508508
});
509509

510510
test('GH OIDC check fails if token is not set', async () => {
511+
(fromEnv as jest.Mock).mockReset();
511512
process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'] = undefined;
512513
process.env['GITHUB_ACTIONS'] = 'true';
513514
jest.spyOn(core, 'getInput').mockImplementation(
@@ -524,7 +525,7 @@ describe('Configure AWS Credentials', () => {
524525
' If you are not trying to authenticate with OIDC and the action is working successfully, you can ignore this message.'
525526
);
526527
expect(core.setFailed).toHaveBeenCalledWith(
527-
'Could not determine how to assume credentials. Please check your inputs and try again.'
528+
'Credentials could not be loaded, please check your action inputs: provider is not a function'
528529
);
529530
});
530531

0 commit comments

Comments
 (0)