Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: automatic cross account integration tests #32085

Open
2 tasks
Tracked by #31929
iliapolo opened this issue Nov 11, 2024 · 0 comments
Open
2 tasks
Tracked by #31929

cli: automatic cross account integration tests #32085

iliapolo opened this issue Nov 11, 2024 · 0 comments
Assignees
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI

Comments

@iliapolo
Copy link
Contributor

Describe the feature

When running integration tests, invoke the CLI with credentials to a different account than the target account.

Use Case

A fairly common setup for deploying CDK apps is providing the CLI with credentials to a role in centralized account (Account S) to perform the deployments to a target account (Account T).

This differs from the "standard" scenario where the CLI is executed with credentials to the target account. To make this setup work, the customer needs to setup trust relationships between both accounts, creating one variation of a cross-account auth setup.

In such a case, the CLI needs to take special care when invoking any AWS APIs because it must make sure its doing so with the appropriate assumed role. Running tests with this setup will automatically catch bugs that fail to do so.

For example: #31845

Proposed Solution

We already control CLI invocation inside our tests via the TestFixture (FLW: its probably ok to assume all tests use it). This means our fixture can assume a role in Account S, and invoke the CLI with its credentials, leaving Account T as is.

public async cdk(args: string[], options: CdkCliOptions = {}) {
const verbose = options.verbose ?? true;
await this.packages.makeCliAvailable();
return this.shell(['cdk', ...(verbose ? ['-v'] : []), ...args], {
...options,
modEnv: {
AWS_REGION: this.aws.region,
AWS_DEFAULT_REGION: this.aws.region,
STACK_NAME_PREFIX: this.stackNamePrefix,
PACKAGE_LAYOUT_VERSION: this.packages.majorVersion(),
...options.modEnv,
},
});
}

The only thing left to unpack here is where will the fixture get 2 accounts from? Currently, our framework only provides different regions in the same account.

_regionPool = ResourcePool.withResources('aws_regions', REGIONS);

So, we need to first implement the test environment allocation service to make this work.

Other Information

Some peripheral considerations:

  • We need to provide a way for tests to opt out of this behavior (there may be good reasons for it).
  • Do we add this as a permutation of the test? or instead?

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

ALL

Environment details (OS name and version, etc.)

ALL

@iliapolo iliapolo added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 11, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Nov 11, 2024
@iliapolo iliapolo self-assigned this Nov 11, 2024
@pahud pahud added p1 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Nov 11, 2024
@iliapolo iliapolo modified the milestone: CLI Testing Posture | Phase 1 Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

2 participants