Skip to content

Commit 20ce4e5

Browse files
author
Richard H Boyd
authored
fix: Updated token retrieval to use new API (#270)
* feat: OIDC provider (with PR comments) * feat: OIDC provider (with PR comments) * updated OIDC based on new GH API
1 parent 0c8047f commit 20ce4e5

File tree

4 files changed

+44
-4238
lines changed

4 files changed

+44
-4238
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: [sigstore]
155+
ClientIdList: ['sts.amazonaws.com']
156156
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
157157
158158
Outputs:

Diff for: dist/index.js

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

Diff for: index.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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');
76

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

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-
203187
function loadCredentials() {
204188
// Force the SDK to re-resolve credentials with the default provider chain.
205189
//
@@ -303,7 +287,7 @@ async function run() {
303287
let sourceAccountId;
304288
let webIdentityToken;
305289
if(useGitHubOIDCProvider()) {
306-
webIdentityToken = await getWebIdentityToken();
290+
webIdentityToken = await core.getIDToken('sts.amazonaws.com');
307291
roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES;
308292
// We don't validate the credentials here because we don't have them yet when using OIDC.
309293
} else {

Diff for: index.test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ 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');
65

76
jest.mock('@actions/core');
8-
jest.mock("axios");
97

108
const FAKE_ACCESS_KEY_ID = 'MY-AWS-ACCESS-KEY-ID';
119
const FAKE_SECRET_ACCESS_KEY = 'MY-AWS-SECRET-ACCESS-KEY';
@@ -91,6 +89,12 @@ describe('Configure AWS Credentials', () => {
9189
.fn()
9290
.mockImplementation(mockGetInput(DEFAULT_INPUTS));
9391

92+
core.getIDToken = jest
93+
.fn()
94+
.mockImplementation(() => {
95+
return "testtoken"
96+
});
97+
9498
mockStsCallerIdentity.mockReset();
9599
mockStsCallerIdentity
96100
.mockReturnValueOnce({
@@ -571,7 +575,6 @@ describe('Configure AWS Credentials', () => {
571575
test('only role arn and region provided to use GH OIDC Token', async () => {
572576
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
573577
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
574-
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
575578
core.getInput = jest
576579
.fn()
577580
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION}));
@@ -592,7 +595,6 @@ describe('Configure AWS Credentials', () => {
592595
const CUSTOM_ROLE_DURATION = 1234;
593596
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
594597
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = 'https://www.example.com/token/endpoint';
595-
axios.get.mockImplementation(() => Promise.resolve({ data: {value: "testtoken"} }));
596598
core.getInput = jest
597599
.fn()
598600
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION, 'role-duration-seconds': CUSTOM_ROLE_DURATION}));

0 commit comments

Comments
 (0)