Skip to content

Commit d4dc8e7

Browse files
Allow to pass inline session policy as a parameter
Update the action file Regenerate the dist/ content Add test
1 parent 5727f24 commit d4dc8e7

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ inputs:
6161
role-chaining:
6262
description: 'Use existing credentials from the environment to assume a new role'
6363
required: false
64+
inline-session-policy:
65+
description: 'Inline session policy'
66+
required: false
6467
outputs:
6568
aws-account-id:
6669
description: 'The AWS account ID for the provided credentials'

dist/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -49145,7 +49145,8 @@ async function assumeRole(params) {
4914549145
region,
4914649146
roleSkipSessionTagging,
4914749147
webIdentityTokenFile,
49148-
webIdentityToken
49148+
webIdentityToken,
49149+
inlineSessionPolicy
4914949150
} = params;
4915049151
assert(
4915149152
[roleToAssume, roleDurationSeconds, roleSessionName, region].every(isDefined),
@@ -49209,6 +49210,9 @@ async function assumeRole(params) {
4920949210
delete assumeRoleRequest.Tags;
4921049211

4921149212
assumeRoleRequest.WebIdentityToken = webIdentityToken;
49213+
if(isDefined(inlineSessionPolicy)) {
49214+
assumeRoleRequest.Policy = inlineSessionPolicy;
49215+
}
4921249216
assumeFunction = sts.assumeRoleWithWebIdentity.bind(sts);
4921349217
} else if(isDefined(webIdentityTokenFile)) {
4921449218
core.debug("webIdentityTokenFile provided. Will call sts:AssumeRoleWithWebIdentity and take session tags from token contents.");
@@ -49421,6 +49425,7 @@ async function run() {
4942149425
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
4942249426
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false });
4942349427
const proxyServer = core.getInput('http-proxy', { required: false });
49428+
const inlineSessionPolicy = core.getInput('inline-session-policy', { required: false });
4942449429

4942549430
if (!region.match(REGION_REGEX)) {
4942649431
throw new Error(`Region is not valid: ${region}`);
@@ -49487,7 +49492,8 @@ async function run() {
4948749492
roleSessionName,
4948849493
roleSkipSessionTagging,
4948949494
webIdentityTokenFile,
49490-
webIdentityToken
49495+
webIdentityToken,
49496+
inlineSessionPolicy
4949149497
}) }, true);
4949249498
exportCredentials(roleCredentials);
4949349499
// We need to validate the credentials in 2 of our use-cases

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ async function assumeRole(params) {
2929
region,
3030
roleSkipSessionTagging,
3131
webIdentityTokenFile,
32-
webIdentityToken
32+
webIdentityToken,
33+
inlineSessionPolicy
3334
} = params;
3435
assert(
3536
[roleToAssume, roleDurationSeconds, roleSessionName, region].every(isDefined),
@@ -93,6 +94,9 @@ async function assumeRole(params) {
9394
delete assumeRoleRequest.Tags;
9495

9596
assumeRoleRequest.WebIdentityToken = webIdentityToken;
97+
if(isDefined(inlineSessionPolicy)) {
98+
assumeRoleRequest.Policy = inlineSessionPolicy;
99+
}
96100
assumeFunction = sts.assumeRoleWithWebIdentity.bind(sts);
97101
} else if(isDefined(webIdentityTokenFile)) {
98102
core.debug("webIdentityTokenFile provided. Will call sts:AssumeRoleWithWebIdentity and take session tags from token contents.");
@@ -305,6 +309,7 @@ async function run() {
305309
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
306310
const webIdentityTokenFile = core.getInput('web-identity-token-file', { required: false });
307311
const proxyServer = core.getInput('http-proxy', { required: false });
312+
const inlineSessionPolicy = core.getInput('inline-session-policy', { required: false });
308313

309314
if (!region.match(REGION_REGEX)) {
310315
throw new Error(`Region is not valid: ${region}`);
@@ -371,7 +376,8 @@ async function run() {
371376
roleSessionName,
372377
roleSkipSessionTagging,
373378
webIdentityTokenFile,
374-
webIdentityToken
379+
webIdentityToken,
380+
inlineSessionPolicy
375381
}) }, true);
376382
exportCredentials(roleCredentials);
377383
// We need to validate the credentials in 2 of our use-cases

index.test.js

+21
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,27 @@ describe('Configure AWS Credentials', () => {
664664
expect(core.setSecret).toHaveBeenNthCalledWith(3, FAKE_STS_SESSION_TOKEN);
665665
});
666666

667+
test('GH OIDC With custom session policy', async () => {
668+
const CUSTOM_SESSION_POLICY = "{ super_secure_policy }";
669+
process.env.GITHUB_ACTIONS = 'true';
670+
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';
671+
core.getInput = jest
672+
.fn()
673+
.mockImplementation(mockGetInput({'role-to-assume': ROLE_ARN, 'aws-region': FAKE_REGION, 'inline-session-policy': CUSTOM_SESSION_POLICY}));
674+
675+
await run();
676+
expect(mockStsAssumeRoleWithWebIdentity).toHaveBeenCalledWith({
677+
RoleArn: 'arn:aws:iam::111111111111:role/MY-ROLE',
678+
RoleSessionName: 'GitHubActions',
679+
DurationSeconds: 3600,
680+
Policy: CUSTOM_SESSION_POLICY,
681+
WebIdentityToken: 'testtoken'
682+
});
683+
expect(core.setSecret).toHaveBeenNthCalledWith(1, FAKE_STS_ACCESS_KEY_ID);
684+
expect(core.setSecret).toHaveBeenNthCalledWith(2, FAKE_STS_SECRET_ACCESS_KEY);
685+
expect(core.setSecret).toHaveBeenNthCalledWith(3, FAKE_STS_SESSION_TOKEN);
686+
});
687+
667688
test('role assumption fails after maximun trials using OIDC Provider', async () => {
668689
process.env.GITHUB_ACTIONS = 'true';
669690
process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN = 'test-token';

0 commit comments

Comments
 (0)