Skip to content

Commit 5f7848e

Browse files
Tarun Belanitarunb12
authored andcommitted
Addressed review comments
1 parent 37ac3a4 commit 5f7848e

9 files changed

+426
-57
lines changed

packages/@aws-cdk/aws-imagebuilder-alpha/lib/distribution-configuration.ts

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export interface AmiLaunchPermission {
6868
/**
6969
* Whether to make the AMI public. Block public access for AMIs must be disabled to make the AMI public.
7070
*
71+
* WARNING: Making an AMI public exposes it to any AWS account globally.
72+
* Ensure the AMI does not contain:
73+
* - Sensitive data or credentials
74+
* - Proprietary software or configurations
75+
* - Internal network information or security settings
76+
*
77+
* For more information on blocking public access for AMIs, see: [Understand block public access for AMIs](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-public-access-to-amis.html)
78+
*
79+
*
7180
* @default false
7281
*/
7382
readonly isPublicUserGroup?: boolean;
@@ -112,6 +121,10 @@ export interface LaunchTemplateConfiguration {
112121
/**
113122
* The launch template to apply the distributed AMI to. A new launch template version will be created for the
114123
* provided launch template with the distributed AMI applied.
124+
*
125+
* *Note:* The launch template should expose a `launchTemplateId`. Templates
126+
* imported by name only are not supported.
127+
*
115128
*/
116129
readonly launchTemplate: ec2.ILaunchTemplate;
117130

@@ -123,7 +136,9 @@ export interface LaunchTemplateConfiguration {
123136
readonly accountId?: string;
124137

125138
/**
126-
* Whether to set the new launch template version that is created as the default launch template version
139+
* Whether to set the new launch template version that is created as the default launch template version. After
140+
* creation of the launch template version containing the distributed AMI, it will be automatically set as the
141+
* default version for the launch template.
127142
*
128143
* @default false
129144
*/
@@ -153,13 +168,15 @@ export interface FastLaunchConfiguration {
153168
* The maximum number of parallel instances that are launched for creating resources
154169
*
155170
* @default A maximum of 6 instances are launched in parallel
171+
* @see https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableFastLaunch.html
156172
*/
157173
readonly maxParallelLaunches?: number;
158174

159175
/**
160176
* The number of pre-provisioned snapshots to keep on hand for a fast-launch enabled Windows AMI
161177
*
162178
* @default 10 snapshots are kept pre-provisioned
179+
* @see https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableFastLaunch.html
163180
*/
164181
readonly targetSnapshotCount?: number;
165182
}
@@ -519,7 +536,7 @@ export class DistributionConfiguration extends DistributionConfigurationBase {
519536
public addAmiDistributions(...amiDistributions: AmiDistribution[]): void {
520537
amiDistributions.forEach((amiDistribution) => {
521538
const region = amiDistribution.region ?? cdk.Stack.of(this).region;
522-
if (!cdk.Token.isUnresolved(region) && this.amiDistributionsByRegion[region]) {
539+
if (this.amiDistributionsByRegion[region]) {
523540
throw new cdk.ValidationError(
524541
`duplicate AMI distribution found for region "${region}"; only one AMI distribution per region is allowed`,
525542
this,
@@ -539,7 +556,10 @@ export class DistributionConfiguration extends DistributionConfigurationBase {
539556
containerDistributions.forEach((containerDistribution) => {
540557
const region = containerDistribution.region ?? cdk.Stack.of(this).region;
541558
if (this.containerDistributionsByRegion[region]) {
542-
throw new cdk.ValidationError('You may not specify multiple container distributions in the same region', this);
559+
throw new cdk.ValidationError(
560+
`duplicate Container distribution found for region "${region}"; only one Container distribution per region is allowed`,
561+
this,
562+
);
543563
}
544564

545565
this.containerDistributionsByRegion[region] = containerDistribution;
@@ -632,6 +652,14 @@ export class DistributionConfiguration extends DistributionConfigurationBase {
632652
}
633653

634654
private buildAmiLaunchPermissions(amiDistribution: AmiDistribution): object | undefined {
655+
if (amiDistribution.amiLaunchPermission?.isPublicUserGroup) {
656+
cdk.Annotations.of(this).addWarning(
657+
'AMI is configured for public access, making it available to any AWS account globally. ' +
658+
'Ensure no sensitive data, credentials, or proprietary configurations are included. ' +
659+
"Review your organization's security policies before deploying public AMIs.",
660+
);
661+
}
662+
635663
const launchPermissions = {
636664
...(amiDistribution.amiLaunchPermission?.organizationalUnitArns !== undefined && {
637665
OrganizationalUnitArns: amiDistribution.amiLaunchPermission?.organizationalUnitArns,
@@ -660,26 +688,30 @@ export class DistributionConfiguration extends DistributionConfigurationBase {
660688
!cdk.Token.isUnresolved(fastLaunchConfiguration.maxParallelLaunches) &&
661689
fastLaunchConfiguration.maxParallelLaunches < MIN_PARALLEL_LAUNCHES
662690
) {
663-
throw new cdk.ValidationError('You must specify a maximum parallel launch count of at least 6', this);
691+
throw new cdk.ValidationError(
692+
`you must specify a maximum parallel launch count of at least ${MIN_PARALLEL_LAUNCHES}`,
693+
this,
694+
);
664695
}
665696

666-
const useFastLaunchLaunchTemplateId = fastLaunchConfiguration.launchTemplate?.launchTemplateId !== undefined;
667-
const launchTemplate: CfnDistributionConfiguration.FastLaunchLaunchTemplateSpecificationProperty = {
697+
const launchTemplate = fastLaunchConfiguration.launchTemplate;
698+
const useFastLaunchLaunchTemplateId = launchTemplate?.launchTemplateId !== undefined;
699+
const fastLaunchLaunchTemplate: CfnDistributionConfiguration.FastLaunchLaunchTemplateSpecificationProperty = {
668700
...(useFastLaunchLaunchTemplateId && {
669-
launchTemplateId: fastLaunchConfiguration.launchTemplate?.launchTemplateId,
701+
launchTemplateId: launchTemplate?.launchTemplateId,
670702
}),
671703
...(!useFastLaunchLaunchTemplateId && {
672-
launchTemplateName: fastLaunchConfiguration.launchTemplate?.launchTemplateName,
704+
launchTemplateName: launchTemplate?.launchTemplateName,
673705
}),
674-
...(fastLaunchConfiguration.launchTemplate?.versionNumber !== undefined && {
675-
launchTemplateVersion: fastLaunchConfiguration.launchTemplate?.versionNumber,
706+
...(launchTemplate?.versionNumber !== undefined && {
707+
launchTemplateVersion: launchTemplate?.versionNumber,
676708
}),
677709
};
678710

679711
return {
680712
enabled: fastLaunchConfiguration.enabled,
681713
maxParallelLaunches: fastLaunchConfiguration.maxParallelLaunches,
682-
...(Object.keys(launchTemplate).length && { launchTemplate }),
714+
...(Object.keys(fastLaunchLaunchTemplate).length && { launchTemplate: fastLaunchLaunchTemplate }),
683715
...(fastLaunchConfiguration.targetSnapshotCount !== undefined && {
684716
snapshotConfiguration: { targetResourceCount: fastLaunchConfiguration.targetSnapshotCount },
685717
}),
@@ -714,11 +746,7 @@ export class DistributionConfiguration extends DistributionConfigurationBase {
714746
}
715747

716748
private buildLicenseConfigurationArns(amiDistribution: AmiDistribution): string[] | undefined {
717-
const licenseConfigurationArns = amiDistribution.licenseConfigurationArns?.map(
718-
(licenseConfigurationArn) => licenseConfigurationArn,
719-
);
720-
721-
return licenseConfigurationArns?.length ? licenseConfigurationArns : undefined;
749+
return amiDistribution.licenseConfigurationArns?.length ? amiDistribution.licenseConfigurationArns : undefined;
722750
}
723751

724752
private buildSsmParameterConfigurations(
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-imagebuilder-alpha/test/integ.all-parameters.distribution-configuration.js.snapshot/aws-cdk-imagebuilder-distribution-configuration-all-parameters.assets.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)