Skip to content

Commit 4e715b8

Browse files
authored
refactor: gate access to environment SDK behind new class (#31904)
Previously there were methods on the `Deployments` class that made it possible to directly get an SDK from the `SdkProvider` for a particular environment. Calling these methods made it possible to get an SDK without thinking of assuming roles to go into a different account. This PR introduces a new class, `EnvironmentAccess`, with a couple of public methods that are the only ones allowed to obtain SDKs with credentials. It has the methods: - accessStackForStackOperations(stack) - accessStackForLookup(stack) - accessStackForReading(stack) These will always respect the role information on the stack. Ideally there would have been similar methods for assets as well, but the `cdk-assets` library is entirely handling asset roles itself, and it's not in the scope of this PR to change that. That keeps on using a plain `SdkProvider`. Hotswap deployments will also just use CLI credentials and not assume role, so that also keeps on using an `SdkProvider`. All other uses have moved to `EnvironmentAccess`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0fb6106 commit 4e715b8

File tree

11 files changed

+473
-305
lines changed

11 files changed

+473
-305
lines changed

packages/aws-cdk/lib/api/bootstrap/bootstrap-props.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tag } from '../../cdk-toolkit';
2+
import { StringWithoutPlaceholders } from '../util/placeholders';
23

34
export const BUCKET_NAME_OUTPUT = 'BucketName';
45
export const REPOSITORY_NAME_OUTPUT = 'ImageRepositoryName';
@@ -17,7 +18,7 @@ export const DEFAULT_BOOTSTRAP_VARIANT = 'AWS CDK: Default Resources';
1718
*/
1819
export interface BootstrapEnvironmentOptions {
1920
readonly toolkitStackName?: string;
20-
readonly roleArn?: string;
21+
readonly roleArn?: StringWithoutPlaceholders;
2122
readonly parameters?: BootstrappingParameters;
2223
readonly force?: boolean;
2324

packages/aws-cdk/lib/api/deploy-stack.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { TemplateBodyParameter, makeBodyParameter } from './util/template-body-p
1919
import { AssetManifestBuilder } from '../util/asset-manifest-builder';
2020
import { determineAllowCrossAccountAssetPublishing } from './util/checks';
2121
import { publishAssets } from '../util/asset-publishing';
22+
import { StringWithoutPlaceholders } from './util/placeholders';
2223

2324
export interface DeployStackResult {
2425
readonly noOp: boolean;
@@ -51,14 +52,13 @@ export interface DeployStackOptions {
5152
/**
5253
* SDK provider (seeded with default credentials)
5354
*
54-
* Will exclusively be used to assume publishing credentials (which must
55-
* start out from current credentials regardless of whether we've assumed an
56-
* action role to touch the stack or not).
55+
* Will be used to:
5756
*
58-
* Used for the following purposes:
59-
*
60-
* - Publish legacy assets.
61-
* - Upload large CloudFormation templates to the staging bucket.
57+
* - Publish assets, either legacy assets or large CFN templates
58+
* that aren't themselves assets from a manifest. (Needs an SDK
59+
* Provider because the file publishing role is declared as part
60+
* of the asset).
61+
* - Hotswap
6262
*/
6363
readonly sdkProvider: SdkProvider;
6464

@@ -70,9 +70,13 @@ export interface DeployStackOptions {
7070
/**
7171
* Role to pass to CloudFormation to execute the change set
7272
*
73-
* @default - Role specified on stack, otherwise current
73+
* To obtain a `StringWithoutPlaceholders`, run a regular
74+
* string though `TargetEnvironment.replacePlaceholders`.
75+
*
76+
* @default - No execution role; CloudFormation either uses the role currently associated with
77+
* the stack, or otherwise uses current AWS credentials.
7478
*/
75-
readonly roleArn?: string;
79+
readonly roleArn?: StringWithoutPlaceholders;
7680

7781
/**
7882
* Notification ARNs to pass to CloudFormation to notify when the change set has completed

0 commit comments

Comments
 (0)