mirror of
https://github.com/aws-actions/configure-aws-credentials.git
synced 2026-09-04 06:15:07 +09:00
fix: Change role duration behavior (#513)
When a session token provided, use 1hr as role duration Otherwise, use the max duration of GitHub action (6hr)
This commit is contained in:
committed by
GitHub
parent
5a4b8f03d1
commit
5820660064
@@ -4,9 +4,10 @@ const assert = require('assert');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// The max time that a GitHub action is allowed to run is 6 hours.
|
// Use 1hr as role duration when using session token or OIDC
|
||||||
// That seems like a reasonable default to use if no role duration is defined.
|
// Otherwise, use the max duration of GitHub action (6hr)
|
||||||
const MAX_ACTION_RUNTIME = 6 * 3600;
|
const MAX_ACTION_RUNTIME = 6 * 3600;
|
||||||
|
const SESSION_ROLE_DURATION = 3600;
|
||||||
const DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES = 3600;
|
const DEFAULT_ROLE_DURATION_FOR_OIDC_ROLES = 3600;
|
||||||
const USER_AGENT = 'configure-aws-credentials-for-github-actions';
|
const USER_AGENT = 'configure-aws-credentials-for-github-actions';
|
||||||
const MAX_TAG_VALUE_LENGTH = 256;
|
const MAX_TAG_VALUE_LENGTH = 256;
|
||||||
@@ -270,7 +271,9 @@ async function run() {
|
|||||||
const maskAccountId = core.getInput('mask-aws-account-id', { required: false });
|
const maskAccountId = core.getInput('mask-aws-account-id', { required: false });
|
||||||
const roleToAssume = core.getInput('role-to-assume', {required: false});
|
const roleToAssume = core.getInput('role-to-assume', {required: false});
|
||||||
const roleExternalId = core.getInput('role-external-id', { required: false });
|
const roleExternalId = core.getInput('role-external-id', { required: false });
|
||||||
let roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || MAX_ACTION_RUNTIME;
|
let roleDurationSeconds = core.getInput('role-duration-seconds', {required: false})
|
||||||
|
|| (sessionToken && SESSION_ROLE_DURATION)
|
||||||
|
|| MAX_ACTION_RUNTIME;
|
||||||
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
|
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
|
||||||
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false })|| 'false';
|
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false })|| 'false';
|
||||||
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
|
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
|
||||||
|
|||||||
@@ -527,6 +527,50 @@ describe('Configure AWS Credentials', () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('sets durationSeconds to one hour when session token provided and no duration is provided', async () => {
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(mockGetInput({...ASSUME_ROLE_INPUTS, 'aws-session-token': FAKE_SESSION_TOKEN}));
|
||||||
|
|
||||||
|
await run();
|
||||||
|
expect(mockStsAssumeRole).toHaveBeenCalledWith({
|
||||||
|
RoleArn: ROLE_ARN,
|
||||||
|
RoleSessionName: 'GitHubActions',
|
||||||
|
DurationSeconds: 3600,
|
||||||
|
Tags: [
|
||||||
|
{Key: 'GitHub', Value: 'Actions'},
|
||||||
|
{Key: 'Repository', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REPOSITORY},
|
||||||
|
{Key: 'Workflow', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_WORKFLOW},
|
||||||
|
{Key: 'Action', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_ACTION},
|
||||||
|
{Key: 'Actor', Value: GITHUB_ACTOR_SANITIZED},
|
||||||
|
{Key: 'Commit', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_SHA},
|
||||||
|
{Key: 'Branch', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REF},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets durationSeconds to one 6 hours no session token or duration is provided', async () => {
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(mockGetInput({...ASSUME_ROLE_INPUTS}));
|
||||||
|
|
||||||
|
await run();
|
||||||
|
expect(mockStsAssumeRole).toHaveBeenCalledWith({
|
||||||
|
RoleArn: ROLE_ARN,
|
||||||
|
RoleSessionName: 'GitHubActions',
|
||||||
|
DurationSeconds: 6 * 3600,
|
||||||
|
Tags: [
|
||||||
|
{Key: 'GitHub', Value: 'Actions'},
|
||||||
|
{Key: 'Repository', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REPOSITORY},
|
||||||
|
{Key: 'Workflow', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_WORKFLOW},
|
||||||
|
{Key: 'Action', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_ACTION},
|
||||||
|
{Key: 'Actor', Value: GITHUB_ACTOR_SANITIZED},
|
||||||
|
{Key: 'Commit', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_SHA},
|
||||||
|
{Key: 'Branch', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REF},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
test('role name provided instead of ARN', async () => {
|
test('role name provided instead of ARN', async () => {
|
||||||
core.getInput = jest
|
core.getInput = jest
|
||||||
.fn()
|
.fn()
|
||||||
|
|||||||
Reference in New Issue
Block a user