feat(cli): allow customizing role session name via CDK_ROLE_SESSION_NAME#1672
Conversation
…ON_NAME When the CLI assumes a role (e.g. cdk-hnb659fds-deploy-role) it hard-codes the session name to `aws-cdk-<username>`, which makes CloudTrail attribution unhelpful when deployments run from a shared CI/CD pipeline. Honor an optional `AWS_CDK_ROLE_SESSION_NAME` environment variable to override it, falling back to the existing default when unset. Closes aws#1120
mrgrain
left a comment
There was a problem hiding this comment.
CDK env vars must start with CDK_.
What is the reason to use an env var over a cli flag? Or both? (You might be right, but I would like to see weighing up the options here.)
Align with the CDK_ env var naming convention per maintainer review.
Head branch was pushed to by a user without write access
|
Thanks for the review @mrgrain. Naming: Renamed Env var vs CLI flag: A few reasons I leaned to an env var here, though I'm happy to add a flag too if you'd prefer:
A CLI flag would be the better fit for per-invocation overrides. If you'd like both, I'm glad to add |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1672 +/- ##
==========================================
- Coverage 89.14% 89.13% -0.02%
==========================================
Files 77 77
Lines 11539 11539
Branches 1605 1606 +1
==========================================
- Hits 10287 10285 -2
- Misses 1221 1223 +2
Partials 31 31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #1120
When the CDK CLI assumes a role (e.g.
cdk-hnb659fds-deploy-role), it currently hard-codes the STS role session name toaws-cdk-<username>. When deployments run from a shared CI/CD pipeline this makes CloudTrail attribution unhelpful, since every deployment shows the same machine user.This adds an opt-in
CDK_ROLE_SESSION_NAMEenvironment variable that overrides the session name when set, falling back to the existingaws-cdk-<username>default when unset. The variable name follows theCDK_env var naming convention.Notes
toolkit-lib'''sSdkProvider.withAssumedRole; reading an env var here is consistent with the surroundingawscli-compatible.ts, which already readsAWS_PROFILE,AWS_REGION, etc.Testing
CDK_ROLE_SESSION_NAMEoverrides the default session name, alongside the existing default/sanitization tests.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.