Skip to content

Commit 232435c

Browse files
committed
feat: add support to define transitive tag keys
1 parent ececac1 commit 232435c

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

.github/workflows/tests-integ.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
role-to-assume: ${{ secrets.SECRETS_AWS_ROLE_TO_ASSUME }}
7373
role-session-name: IntegAccessKeysAssumeRole
7474
role-external-id: ${{ secrets.SECRETS_AWS_ROLE_EXTERNAL_ID }}
75+
transitive-tag-keys:
76+
Actor
77+
Repository
7578
integ-access-keys-env:
7679
strategy:
7780
fail-fast: false
@@ -93,6 +96,7 @@ jobs:
9396
role-to-assume: ${{ secrets.SECRETS_AWS_ROLE_TO_ASSUME }}
9497
role-session-name: IntegAccessKeysAssumeRole
9598
role-external-id: ${{ secrets.SECRETS_AWS_ROLE_EXTERNAL_ID }}
99+
transitive-tag-keys: Repository
96100
integ-iam-user:
97101
strategy:
98102
fail-fast: false

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ See [action.yml](./action.yml) for more detail.
109109
| role-external-id | The external ID of the role to assume. Only needed if your role requires it. | No |
110110
| role-session-name | Defaults to "GitHubActions", but may be changed if required. | No |
111111
| role-skip-session-tagging | Skips session tagging if set. | No |
112+
| transitive-tag-keys | Define a list of transitive tag keys to pass when assuming a role. | No |
112113
| inline-session-policy | You may further restrict the assumed role policy by defining an inline policy here. | No |
113114
| managed-session-policies | You may further restrict the assumed role policy by specifying a managed policy here. | No |
114115
| output-credentials | When set, outputs fetched credentials as action step output. Defaults to false. | No |
@@ -167,6 +168,18 @@ You can skip this session tagging by providing
167168
role-skip-session-tagging: true
168169
```
169170
171+
To forward session tags to subsequent sessions in a role chain, you can use the
172+
`transitive-tag-keys` input to specify the keys of the tags to be passed. Eg.
173+
```yaml
174+
uses: aws-actions/configure-aws-credentials@v4
175+
with:
176+
transitive-tag-keys:
177+
Repository
178+
Workflow
179+
Action
180+
Actor
181+
```
182+
170183
### Session policies
171184
Session policies are not required, but they allow you to limit the scope of the
172185
fetched credentials without making changes to IAM roles. You can specify inline

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ inputs:
5252
role-skip-session-tagging:
5353
description: Skip session tagging during role assumption
5454
required: false
55+
transitive-tag-keys:
56+
description: Define a list of transitive tag keys to pass when assuming a role
57+
required: false
5558
inline-session-policy:
5659
description: Define an inline session policy to use when assuming a role
5760
required: false

src/assumeRole.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface assumeRoleParams {
7070
roleDuration: number;
7171
roleSessionName: string;
7272
roleSkipSessionTagging?: boolean;
73+
transitiveTagKeys?: string[];
7374
sourceAccountId?: string;
7475
roleExternalId?: string;
7576
webIdentityTokenFile?: string;
@@ -87,6 +88,7 @@ export async function assumeRole(params: assumeRoleParams) {
8788
roleDuration,
8889
roleSessionName,
8990
roleSkipSessionTagging,
91+
transitiveTagKeys,
9092
webIdentityTokenFile,
9193
webIdentityToken,
9294
inlineSessionPolicy,
@@ -121,6 +123,8 @@ export async function assumeRole(params: assumeRoleParams) {
121123
core.debug(`${tags.length} role session tags are being used.`);
122124
}
123125

126+
const transitiveTagKeysArray = transitiveTagKeys?.filter((key) => tags?.some((tag) => tag.Key === key));
127+
124128
// Calculate role ARN from name and account ID (currently only supports `aws` partition)
125129
let roleArn = roleToAssume;
126130
if (!roleArn.startsWith('arn:aws')) {
@@ -137,6 +141,7 @@ export async function assumeRole(params: assumeRoleParams) {
137141
RoleSessionName: roleSessionName,
138142
DurationSeconds: roleDuration,
139143
Tags: tags ? tags : undefined,
144+
TransitiveTagKeys: transitiveTagKeysArray,
140145
ExternalId: roleExternalId ? roleExternalId : undefined,
141146
Policy: inlineSessionPolicy ? inlineSessionPolicy : undefined,
142147
PolicyArns: managedSessionPolicies?.length ? managedSessionPolicies : undefined,

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function run() {
4444
const roleSessionName = core.getInput('role-session-name', { required: false }) || ROLE_SESSION_NAME;
4545
const roleSkipSessionTaggingInput = core.getInput('role-skip-session-tagging', { required: false }) || 'false';
4646
const roleSkipSessionTagging = roleSkipSessionTaggingInput.toLowerCase() === 'true';
47+
const transitiveTagKeys = core.getMultilineInput('transitive-tag-keys', { required: false });
4748
const proxyServer = core.getInput('http-proxy', { required: false });
4849
const inlineSessionPolicy = core.getInput('inline-session-policy', {
4950
required: false,
@@ -180,6 +181,7 @@ export async function run() {
180181
roleDuration,
181182
roleSessionName,
182183
roleSkipSessionTagging,
184+
transitiveTagKeys,
183185
webIdentityTokenFile,
184186
webIdentityToken,
185187
inlineSessionPolicy,

0 commit comments

Comments
 (0)