Skip to content

Commit a78fcb0

Browse files
author
Richard H Boyd
authored
fix: reverting update to use new API (#274)
* Revert "chore: Update dist" This reverts commit 9815921. * Revert "fix: Updated token retrieval to use new API (#270)" This reverts commit 20ce4e5.
1 parent 9815921 commit a78fcb0

File tree

4 files changed

+4083
-9
lines changed

4 files changed

+4083
-9
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Resources:
152152
Condition: CreateOIDCProvider
153153
Properties:
154154
Url: https://vstoken.actions.githubusercontent.com
155-
ClientIdList: ['sts.amazonaws.com']
155+
ClientIdList: [sigstore]
156156
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
157157
158158
Outputs:

Diff for: dist/index.js

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

Diff for: index.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const aws = require('aws-sdk');
33
const assert = require('assert');
44
const fs = require('fs');
55
const path = require('path');
6+
const axios = require('axios');
67

78
// The max time that a GitHub action is allowed to run is 6 hours.
89
// That seems like a reasonable default to use if no role duration is defined.
@@ -184,6 +185,21 @@ async function exportAccountId(maskAccountId, region) {
184185
return accountId;
185186
}
186187

188+
async function getWebIdentityToken() {
189+
const isDefined = i => !!i;
190+
const {ACTIONS_ID_TOKEN_REQUEST_URL, ACTIONS_ID_TOKEN_REQUEST_TOKEN} = process.env;
191+
192+
assert(
193+
[ACTIONS_ID_TOKEN_REQUEST_URL, ACTIONS_ID_TOKEN_REQUEST_TOKEN].every(isDefined),
194+
'Missing required environment value. Are you running in GitHub Actions?'
195+
);
196+
const { data } = await axios.get(`${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sigstore`, {
197+
headers: {"Authorization": `bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}`}
198+
}
199+
);
200+
return data.value;
201+
}
202+
187203
function loadCredentials() {
188204
// Force the SDK to re-resolve credentials with the default provider chain.
189205
//
@@ -287,7 +303,7 @@ async function run() {
287303
let sourceAccountId;
288304
let webIdentityToken;
289305
if(useGitHubOIDCProvider()) {
290-
webIdentityToken = await core.getIDToken('sts.amazonaws.com');
306+
webIdentityToken = await getWebIdentityToken();
291307
roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES;
292308
// We don't validate the credentials here because we don't have them yet when using OIDC.
293309
} else {

Diff for: index.test.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const core = require('@actions/core');
22
const assert = require('assert');
33
const aws = require('aws-sdk');
44
const run = require('./index.js');
5+
const axios = require('axios');
56

67
jest.mock('@actions/core');
8+
jest.mock("axios");
79

810
const FAKE_ACCESS_KEY_ID = 'MY-AWS-ACCESS-KEY-ID';
911
const FAKE_SECRET_ACCESS_KEY = 'MY-AWS-SECRET-ACCESS-KEY';
@@ -89,12 +91,6 @@ describe('Configure AWS Credentials', () => {
8991
.fn()
9092
.mockImplementation(mockGetInput(DEFAULT_INPUTS));
9193

92-
core.getIDToken = jest
93-
.fn()
94-
.mockImplementation(() => {
95-
return "testtoken"
96-
});
97-
9894
mockStsCallerIdentity.mockReset();
9995
mockStsCallerIdentity
10096
.mockReturnValueOnce({
@@ -575,6 +571,7 @@ describe('Configure AWS Credentials', () => {
575571
test('only role arn and region provided to use GH OIDC Token', async () => {
576572
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
577573
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
574+
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
578575
core.getInput = jest
579576
.fn()
580577
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION}));
@@ -595,6 +592,7 @@ describe('Configure AWS Credentials', () => {
595592
const CUSTOM_ROLE_DURATION = 1234;
596593
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
597594
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
595+
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
598596
core.getInput = jest
599597
.fn()
600598
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION, 'role-duration-seconds': CUSTOM_ROLE_DURATION}));

0 commit comments

Comments
 (0)