Skip to content

Commit e65c3ee

Browse files
committed
Merge branch 'master' into make_github_ref_env_var_optional
* master: chore: Update dist fix: Make tagging optional (#92) chore: Bump eslint from 7.3.1 to 7.4.0 (#94) chore: Update dist chore: Bump aws-sdk from 2.707.0 to 2.708.0 (#90) chore: update dependabot schedule (#89) chore(release): 1.4.2 chore: Update dist chore: Bump aws-sdk from 2.706.0 to 2.707.0 (#88) chore: Switch to GitHub-native Dependabot chore: Update dist chore: Bump aws-sdk from 2.704.0 to 2.706.0 chore: Update dist fix: add comma to set of special characters (#78) chore: Bump jest from 26.0.1 to 26.1.0 chore: Update dist chore: Bump aws-sdk from 2.692.0 to 2.704.0 chore: Bump eslint from 7.2.0 to 7.3.1
2 parents 04fd455 + 740d8a4 commit e65c3ee

11 files changed

+896
-932
lines changed

.dependabot/config.yml

-9
This file was deleted.

.github/dependabot.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
day: tuesday
8+
open-pull-requests-limit: 10

.mergify.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@ pull_request_rules:
1212
- -merged
1313
- -closed
1414
- author!=dependabot[bot]
15-
- author!=dependabot-preview[bot]
1615
actions:
1716
merge:
1817
method: squash
1918
strict: smart
2019
strict_method: merge
2120

22-
- name: Automatically approve Dependabot PRs
21+
- name: Automatically approve and merge Dependabot PRs
2322
conditions:
2423
- base=master
25-
- author~=^dependabot(|-preview)\[bot\]$
24+
- author=dependabot[bot]
25+
- status-success=Run Unit Tests
26+
- status-success=Semantic Pull Request
2627
- -title~=(WIP|wip)
2728
- -label~=(blocked|do-not-merge)
2829
- -merged
2930
- -closed
3031
actions:
3132
review:
3233
type: APPROVE
34+
merge:
35+
method: squash
36+
strict: smart+fasttrack
37+
strict_method: merge

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [1.4.2](https://github.com/aws-actions/configure-aws-credentials/compare/v1.4.1...v1.4.2) (2020-06-30)
6+
7+
8+
### Bug Fixes
9+
10+
* add comma to set of special characters ([#78](https://github.com/aws-actions/configure-aws-credentials/issues/78)) ([f04843b](https://github.com/aws-actions/configure-aws-credentials/commit/f04843b510a6c8adf77eed907a616cf00a99970d))
11+
512
### [1.4.1](https://github.com/aws-actions/configure-aws-credentials/compare/v1.4.0...v1.4.1) (2020-06-09)
613

714
## [1.4.0](https://github.com/aws-actions/configure-aws-credentials/compare/v1.3.5...v1.4.0) (2020-06-03)

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ The session will have the name "GitHubActions" and be tagged with the following
157157

158158
_Note: all tag values must conform to [the requirements](https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html). Particularly, `GITHUB_WORKFLOW` will be truncated if it's too long. If `GITHUB_ACTOR` or `GITHUB_WORKFLOW` contain invalid charcters, the characters will be replaced with an '*'._
159159

160+
The action will use session tagging by default during role assumption. You can skip this session tagging by providing `role-skip-session-tagging` as true in the action's inputs:
161+
162+
```yaml
163+
uses: aws-actions/configure-aws-credentials@v1
164+
with:
165+
role-skip-session-tagging: true
166+
```
167+
160168
## Self-Hosted Runners
161169

162170
If you run your GitHub Actions in a [self-hosted runner](https://help.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) that already has access to AWS credentials, such as an EC2 instance, then you do not need to provide IAM user access key credentials to this action.

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ inputs:
4343
role-external-id:
4444
description: 'The external ID of the role to assume'
4545
required: false
46+
role-skip-session-tagging:
47+
description: 'Skip session tagging during role assumption'
48+
required: false
4649
outputs:
4750
aws-account-id:
4851
description: 'The AWS account ID for the provided credentials'

dist/index.js

+171-69
Large diffs are not rendered by default.

index.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async function assumeRole(params) {
2222
roleDurationSeconds,
2323
roleSessionName,
2424
region,
25+
roleSkipSessionTagging
2526
} = params;
2627
assert(
2728
[sourceAccountId, roleToAssume, roleDurationSeconds, roleSessionName, region].every(isDefined),
@@ -41,19 +42,23 @@ async function assumeRole(params) {
4142
// Supports only 'aws' partition. Customers in other partitions ('aws-cn') will need to provide full ARN
4243
roleArn = `arn:aws:iam::${sourceAccountId}:role/${roleArn}`;
4344
}
45+
const tagArray = [
46+
{Key: 'GitHub', Value: 'Actions'},
47+
{Key: 'Repository', Value: GITHUB_REPOSITORY},
48+
{Key: 'Workflow', Value: sanitizeGithubWorkflowName(GITHUB_WORKFLOW)},
49+
{Key: 'Action', Value: GITHUB_ACTION},
50+
{Key: 'Actor', Value: sanitizeGithubActor(GITHUB_ACTOR)},
51+
{Key: 'Branch', Value: GITHUB_REF},
52+
{Key: 'Commit', Value: GITHUB_SHA},
53+
];
54+
55+
const roleSessionTags = roleSkipSessionTagging ? undefined : tagArray;
4456

4557
const assumeRoleRequest = {
4658
RoleArn: roleArn,
4759
RoleSessionName: roleSessionName,
4860
DurationSeconds: roleDurationSeconds,
49-
Tags: [
50-
{Key: 'GitHub', Value: 'Actions'},
51-
{Key: 'Repository', Value: GITHUB_REPOSITORY},
52-
{Key: 'Workflow', Value: sanitizeGithubWorkflowName(GITHUB_WORKFLOW)},
53-
{Key: 'Action', Value: GITHUB_ACTION},
54-
{Key: 'Actor', Value: sanitizeGithubActor(GITHUB_ACTOR)},
55-
{Key: 'Commit', Value: GITHUB_SHA},
56-
]
61+
Tags: roleSessionTags
5762
};
5863

5964
if (isDefined(process.env.GITHUB_REF)) {
@@ -85,7 +90,7 @@ function sanitizeGithubWorkflowName(name) {
8590
// Workflow names can be almost any valid UTF-8 string, but tags are more restrictive.
8691
// This replaces anything not conforming to the tag restrictions by inverting the regular expression.
8792
// See the AWS documentation for constraint specifics https://docs.aws.amazon.com/STS/latest/APIReference/API_Tag.html.
88-
const nameWithoutSpecialCharacters = name.replace(/[^\p{L}\p{Z}\p{N}_.:/=+-@]/gu, SANITIZATION_CHARACTER);
93+
const nameWithoutSpecialCharacters = name.replace(/[^\p{L}\p{Z}\p{N}_:/=+.-@-]/gu, SANITIZATION_CHARACTER);
8994
const nameTruncated = nameWithoutSpecialCharacters.slice(0, MAX_TAG_VALUE_LENGTH)
9095
return nameTruncated
9196
}
@@ -199,7 +204,8 @@ async function run() {
199204
const roleExternalId = core.getInput('role-external-id', { required: false });
200205
const roleDurationSeconds = core.getInput('role-duration-seconds', {required: false}) || MAX_ACTION_RUNTIME;
201206
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
202-
207+
const roleSkipSessionTagging = core.getInput('role-skip-session-tagging', { required: false });
208+
203209
if (!region.match(REGION_REGEX)) {
204210
throw new Error(`Region is not valid: ${region}`);
205211
}
@@ -236,7 +242,8 @@ async function run() {
236242
roleToAssume,
237243
roleExternalId,
238244
roleDurationSeconds,
239-
roleSessionName
245+
roleSessionName,
246+
roleSkipSessionTagging
240247
});
241248
exportCredentials(roleCredentials);
242249
await validateCredentials(roleCredentials.accessKeyId);

index.test.js

+72-1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ describe('Configure AWS Credentials', () => {
296296
expect(core.setFailed).toHaveBeenCalledWith('Region is not valid: $AWS_REGION');
297297
});
298298

299+
test('throws error if access key id exists but missing secret access key', async () => {
300+
process.env.SHOW_STACK_TRACE = 'false';
301+
const inputsWIthoutSecretKey = {...ASSUME_ROLE_INPUTS}
302+
inputsWIthoutSecretKey["aws-secret-access-key"] = undefined
303+
core.getInput = jest
304+
.fn()
305+
.mockImplementation(mockGetInput(inputsWIthoutSecretKey));
306+
307+
await run();
308+
expect(core.setFailed).toHaveBeenCalledWith("'aws-secret-access-key' must be provided if 'aws-access-key-id' is provided");
309+
310+
});
311+
299312
test('can opt out of masking account ID', async () => {
300313
const mockInputs = {...CREDS_INPUTS, 'aws-region': 'us-east-1', 'mask-aws-account-id': 'false'};
301314
core.getInput = jest
@@ -524,7 +537,7 @@ describe('Configure AWS Credentials', () => {
524537

525538
process.env = {...process.env, GITHUB_WORKFLOW: 'Workflow!"#$%&\'()*+, -./:;<=>?@[]^_`{|}~🙂💥🍌1yFvMOeD3ZHYsHrGjCceOboMYzBPo0CRNFdcsVRG6UgR3A912a8KfcBtEVvkAS7kRBq80umGff8mux5IN1y55HQWPNBNyaruuVr4islFXte4FDQZexGJRUSMyHQpxJ8OmZnET84oDmbvmIjgxI6IBrdihX9PHMapT4gQvRYnLqNiKb18rEMWDNoZRy51UPX5sWK2GKPipgKSO9kqLckZai9D2AN2RlWCxtMqChNtxuxjqeqhoQZo0oaq39sjcRZgAAAAAAA'};
526539

527-
const sanitizedWorkflowName = 'Workflow__________+, -./:;<=>?@____________1yFvMOeD3ZHYsHrGjCceOboMYzBPo0CRNFdcsVRG6UgR3A912a8KfcBtEVvkAS7kRBq80umGff8mux5IN1y55HQWPNBNyaruuVr4islFXte4FDQZexGJRUSMyHQpxJ8OmZnET84oDmbvmIjgxI6IBrdihX9PHMapT4gQvRYnLqNiKb18rEMWDNoZRy51UPX5sWK2GKPipgKSO9kqLckZa'
540+
const sanitizedWorkflowName = 'Workflow__________+_ -./:;<=>?@____________1yFvMOeD3ZHYsHrGjCceOboMYzBPo0CRNFdcsVRG6UgR3A912a8KfcBtEVvkAS7kRBq80umGff8mux5IN1y55HQWPNBNyaruuVr4islFXte4FDQZexGJRUSMyHQpxJ8OmZnET84oDmbvmIjgxI6IBrdihX9PHMapT4gQvRYnLqNiKb18rEMWDNoZRy51UPX5sWK2GKPipgKSO9kqLckZa'
528541

529542
await run();
530543
expect(mockStsAssumeRole).toHaveBeenCalledWith({
@@ -543,4 +556,62 @@ describe('Configure AWS Credentials', () => {
543556
})
544557
});
545558

559+
test('skip tagging provided as true', async () => {
560+
core.getInput = jest
561+
.fn()
562+
.mockImplementation(mockGetInput({...ASSUME_ROLE_INPUTS, 'role-skip-session-tagging': true}));
563+
564+
await run();
565+
expect(mockStsAssumeRole).toHaveBeenCalledWith({
566+
RoleArn: ROLE_ARN,
567+
RoleSessionName: 'GitHubActions',
568+
DurationSeconds: 21600,
569+
Tags: undefined
570+
})
571+
});
572+
573+
test('skip tagging provided as false', async () => {
574+
core.getInput = jest
575+
.fn()
576+
.mockImplementation(mockGetInput({...ASSUME_ROLE_INPUTS, 'role-skip-session-tagging': false}));
577+
578+
await run();
579+
expect(mockStsAssumeRole).toHaveBeenCalledWith({
580+
RoleArn: ROLE_ARN,
581+
RoleSessionName: 'GitHubActions',
582+
DurationSeconds: 21600,
583+
Tags: [
584+
{Key: 'GitHub', Value: 'Actions'},
585+
{Key: 'Repository', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REPOSITORY},
586+
{Key: 'Workflow', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_WORKFLOW},
587+
{Key: 'Action', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_ACTION},
588+
{Key: 'Actor', Value: GITHUB_ACTOR_SANITIZED},
589+
{Key: 'Branch', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REF},
590+
{Key: 'Commit', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_SHA},
591+
]
592+
})
593+
});
594+
595+
test('skip tagging not provided', async () => {
596+
core.getInput = jest
597+
.fn()
598+
.mockImplementation(mockGetInput({...ASSUME_ROLE_INPUTS}));
599+
600+
await run();
601+
expect(mockStsAssumeRole).toHaveBeenCalledWith({
602+
RoleArn: ROLE_ARN,
603+
RoleSessionName: 'GitHubActions',
604+
DurationSeconds: 21600,
605+
Tags: [
606+
{Key: 'GitHub', Value: 'Actions'},
607+
{Key: 'Repository', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REPOSITORY},
608+
{Key: 'Workflow', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_WORKFLOW},
609+
{Key: 'Action', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_ACTION},
610+
{Key: 'Actor', Value: GITHUB_ACTOR_SANITIZED},
611+
{Key: 'Branch', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_REF},
612+
{Key: 'Commit', Value: ENVIRONMENT_VARIABLE_OVERRIDES.GITHUB_SHA},
613+
]
614+
})
615+
});
616+
546617
});

0 commit comments

Comments
 (0)