Skip to content

Commit b56b541

Browse files
Feat: Added the ability to enforce IDMSv2 on firewalls, firewall manager and autoscaling group for firewalls (#869)
* Added support for IMDSv2 option for firewalls autscaling group * Added support for IMDSv2 option for firewalls/firewall manager instance Modified the documentation/comments of the disableTermination custom construct. * Removed a configuration option that is not needed after all * Fixed a space issue with prettier * updated lock file * fixed lock file and linter errors Co-authored-by: hickeydh-aws <hickeydh@amazon.com>
1 parent d3df849 commit b56b541

File tree

18 files changed

+253
-11
lines changed

18 files changed

+253
-11
lines changed

pnpm-lock.yaml

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

src/deployments/cdk/src/deployments/firewall/cluster/step-3.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ async function createFirewallCluster(props: {
232232
'security-group': securityGroupName,
233233
'fw-instance-role': instanceRoleName,
234234
'image-id': imageId,
235+
'enforce-imdsv2': enforceImdsV2,
235236
'instance-sizes': instanceType,
236237
'block-device-mappings': blockDeviceMappings,
237238
'apply-tags': tags,
@@ -258,6 +259,7 @@ async function createFirewallCluster(props: {
258259
vpcCidrBlock: vpc.cidrBlock,
259260
additionalCidrBlocks: vpc.additionalCidrBlocks,
260261
imageId,
262+
enforceImdsV2,
261263
instanceType,
262264
instanceRole,
263265
instanceProfile,

src/deployments/cdk/src/deployments/firewall/cluster/step-4.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ async function createFirewallCluster(props: {
158158
const {
159159
name: firewallName,
160160
'security-group': securityGroupName,
161+
'enforce-imdsv2': enforceImdsv2,
161162
'fw-instance-role': instanceRoleName,
162163
'image-id': imageId,
163164
'instance-sizes': instanceType,
@@ -196,6 +197,7 @@ async function createFirewallCluster(props: {
196197
launchConfigurationName,
197198
associatePublicIpAddress,
198199
imageId,
200+
metadataOptions: enforceImdsv2 ? { httpEndpoint: 'enabled', httpTokens: 'required' } : undefined,
199201
securityGroups: [securityGroup.id],
200202
iamInstanceProfile: instanceRoleName ? createIamInstanceProfileName(instanceRoleName) : undefined,
201203
instanceType,

src/deployments/cdk/src/deployments/firewall/manager/step-1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ async function createFirewallManager(props: {
155155
}),
156156
configName: config.name,
157157
imageId: config['image-id'],
158+
enforceImdsV2: config['enforce-imdsv2'],
158159
instanceType: config['instance-sizes'],
159160
blockDeviceMappings,
160161
userData,

src/lib/cdk-constructs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@aws-accelerator/custom-resource-cfn-sleep": "workspace:*",
2121
"@aws-accelerator/custom-resource-elb-deletion-protection": "workspace:*",
2222
"@aws-accelerator/custom-resource-ec2-disable-api-termination": "workspace:*",
23+
"@aws-accelerator/custom-resource-ec2-modify-metadata-options": "workspace:*",
2324
"@aws-accelerator/custom-resource-r53-dns-endpoint-ips": "workspace:*",
2425
"@aws-accelerator/custom-resource-s3-put-bucket-replication": "workspace:*",
2526
"@aws-accelerator/custom-resource-s3-template": "workspace:*",

src/lib/cdk-constructs/src/autoscaling/launch-configuration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export type LaunchConfigurationProps = autoscaling.CfnLaunchConfigurationProps;
2323
interface LaunchConfigurationCustomProps extends LaunchConfigurationProps {
2424
centralBucketName?: string;
2525
logGroupName?: string;
26-
enforceIMDSv2?: boolean;
2726
}
2827

2928
/**

src/lib/cdk-constructs/src/firewall/cluster.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface FirewallClusterProps {
2424
vpcCidrBlock: string;
2525
additionalCidrBlocks: string[];
2626
imageId: string;
27+
enforceImdsV2: boolean;
2728
instanceType: string;
2829
instanceRole: iam.IRole;
2930
instanceProfile: IInstanceProfile;
@@ -68,6 +69,7 @@ export class FirewallCluster extends cdk.Construct {
6869
vpcCidrBlock: this.props.vpcCidrBlock,
6970
additionalCidrBlocks: this.props.additionalCidrBlocks,
7071
imageId: this.props.imageId,
72+
enforceImdsV2: this.props.enforceImdsV2,
7173
instanceType: this.props.instanceType,
7274
instanceProfile: this.props.instanceProfile,
7375
keyPairName: this.props.keyPairName,

src/lib/cdk-constructs/src/firewall/instance.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IInstanceProfile } from '../iam';
2020
import { Subnet, SecurityGroup } from '../vpc';
2121
import { CfnSleep } from '@aws-accelerator/custom-resource-cfn-sleep';
2222
import { EC2DisableApiTermination } from '@aws-accelerator/custom-resource-ec2-disable-api-termination';
23+
import { EC2ModifyMetadataOptions } from '@aws-accelerator/custom-resource-ec2-modify-metadata-options';
2324

2425
export interface FirewallVpnTunnelOptions {
2526
cgwTunnelInsideAddress1: string;
@@ -51,6 +52,7 @@ export interface FirewallInstanceProps {
5152
name: string;
5253
hostname: string;
5354
vpcCidrBlock: string;
55+
enforceImdsV2: boolean;
5456
additionalCidrBlocks: string[];
5557
licensePath?: string;
5658
licenseBucket?: s3.IBucket;
@@ -125,6 +127,13 @@ export class FirewallInstance extends cdk.Construct {
125127
this.resource.node.addDependency(this.template);
126128
}
127129

130+
new EC2ModifyMetadataOptions(this, `EC2${this.props.name}ModifyMetadataOptions`, {
131+
ec2Id: this.resource.ref,
132+
ec2Name: this.props.name,
133+
httpEndpoint: 'enabled',
134+
httpTokens: this.props.enforceImdsV2 ? 'required' : 'optional',
135+
});
136+
128137
new EC2DisableApiTermination(this, `EC2${this.props.name}DisableApiTermination`, {
129138
ec2Id: this.resource.ref,
130139
ec2Name: this.props.name,

src/lib/cdk-constructs/src/firewall/manager.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import * as ec2 from '@aws-cdk/aws-ec2';
1616
import { SecurityGroup, Subnet } from '../vpc';
1717
import { CfnSleep } from '@aws-accelerator/custom-resource-cfn-sleep';
1818
import { EC2DisableApiTermination } from '@aws-accelerator/custom-resource-ec2-disable-api-termination';
19+
import { EC2ModifyMetadataOptions } from '@aws-accelerator/custom-resource-ec2-modify-metadata-options';
1920

2021
export interface FirewallManagerProps {
2122
name: string;
@@ -24,6 +25,7 @@ export interface FirewallManagerProps {
2425
* Image ID of firewall.
2526
*/
2627
imageId: string;
28+
enforceImdsV2: boolean;
2729
instanceType: string;
2830
blockDeviceMappings: ec2.CfnInstance.BlockDeviceMappingProperty[];
2931
keyPairName?: string;
@@ -49,6 +51,13 @@ export class FirewallManager extends cdk.Construct {
4951
});
5052
cdk.Tags.of(this.resource).add('Name', this.props.name);
5153

54+
new EC2ModifyMetadataOptions(this, `EC2${this.props.configName}ModifyMetadataOptions`, {
55+
ec2Id: this.resource.ref,
56+
ec2Name: this.props.name,
57+
httpEndpoint: 'enabled',
58+
httpTokens: this.props.enforceImdsV2 ? 'required' : 'optional',
59+
});
60+
5261
new EC2DisableApiTermination(this, `EC2-FWMNG${this.props.configName}DisableApiTermination`, {
5362
ec2Id: this.resource.ref,
5463
ec2Name: this.props.name,

src/lib/config-i18n/src/en.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,10 @@ translate(c.FirewallEC2ConfigType, {
18781878
title: '',
18791879
description: 'AMI image ID',
18801880
},
1881+
'enforce-imdsv2': {
1882+
title: 'Enforce IMDSv2 on the EC instances launched for firewalls',
1883+
description: 'If set to true, IMDSv2 will be mandatory on the firewall instances. Default : false',
1884+
},
18811885
region: {
18821886
title: '',
18831887
description: 'Region to deploy the firewall',
@@ -2026,6 +2030,10 @@ translate(c.FirewallAutoScaleConfigType, {
20262030
title: '',
20272031
description: '',
20282032
},
2033+
'enforce-imdsv2': {
2034+
title: 'Enforce IMDSv2 on the EC instances launched for firewalls',
2035+
description: 'If set to true, IMDSv2 will be mandatory on the instances. Default : false',
2036+
},
20292037
'instance-sizes': {
20302038
title: '',
20312039
description: '',
@@ -2113,6 +2121,10 @@ translate(c.FirewallManagerConfigType, {
21132121
title: 'Image ID',
21142122
description: '',
21152123
},
2124+
'enforce-imdsv2': {
2125+
title: 'Enforce IMDSv2 on the EC instance launched for firewall manager',
2126+
description: 'If set to true, IMDSv2 will be mandatory on the instance. Default : false',
2127+
},
21162128
region: {
21172129
title: '',
21182130
description: '',

0 commit comments

Comments
 (0)