Skip to content

Commit a86f57e

Browse files
committed
feat: Allow audience to be explicitly specified
The default audience for the GitHub OIDC uses sts.amazonaws.com, but there are situations when it would be desirable to allow different audience names to be used instead. Allow this to be specified as an argument to the action.
1 parent 8d9fac2 commit a86f57e

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ The following table describes which identity is used based on which values are s
101101
aws-region: us-east-2
102102
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
103103
role-session-name: MySessionName
104+
audience: sts.amazonaws.com
104105
```
105106
In this example, the Action will load the OIDC token from the GitHub-provided environment variable and use it to assume the role `arn:aws:iam::123456789100:role/my-github-actions-role` with the session name `MySessionName`.
106107

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ inputs:
2222
aws-region:
2323
description: 'AWS Region, e.g. us-east-2'
2424
required: true
25+
audience:
26+
description: 'The audience to use for the OIDC provider'
27+
required: false
2528
mask-aws-account-id:
2629
description: >-
2730
Whether to set the AWS account ID for these credentials as a secret value,

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ const MAX_TAG_VALUE_LENGTH = 256;
1313
const SANITIZATION_CHARACTER = '_';
1414
const ROLE_SESSION_NAME = 'GitHubActions';
1515
const REGION_REGEX = /^[a-z0-9-]+$/g;
16+
const DEFAULT_AUDIENCE = 'sts.amazonaws.com';
1617

1718
async function assumeRole(params) {
1819
// Assume a role to get short-lived credentials using longer-lived credentials.
1920
const isDefined = i => !!i;
2021

2122
const {
23+
audience,
2224
sourceAccountId,
2325
roleToAssume,
2426
roleExternalId,
@@ -240,6 +242,7 @@ async function run() {
240242
try {
241243
// Get inputs
242244
const accessKeyId = core.getInput('aws-access-key-id', { required: false });
245+
const audience = core.getInput('audience', { required: false }) || DEFAULT_AUDIENCE;
243246
const secretAccessKey = core.getInput('aws-secret-access-key', { required: false });
244247
const region = core.getInput('aws-region', { required: true });
245248
const sessionToken = core.getInput('aws-session-token', { required: false });
@@ -287,7 +290,7 @@ async function run() {
287290
let sourceAccountId;
288291
let webIdentityToken;
289292
if(useGitHubOIDCProvider()) {
290-
webIdentityToken = await core.getIDToken('sts.amazonaws.com');
293+
webIdentityToken = await core.getIDToken(audience);
291294
roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES;
292295
// We don't validate the credentials here because we don't have them yet when using OIDC.
293296
} else {

0 commit comments

Comments
 (0)