Skip to content

Commit

Permalink
fix: EC2 instances should use IMDSv2 (#1159)
Browse files Browse the repository at this point in the history
* fix!: EC2 instances should use IMDSv2

BREAKING CHANGE: If your application has dependencies which still rely on IDMSv1 you will need to update them before upgrading to this version of @guardian/cdk.

You should upgrade your CODE infrastructure and confirm that your application still deploys and functions as expected before deploying this to PROD.

For more details see: https://github.com/guardian/security-hq/blob/main/hq/markdown/guardduty-sechub-common-problems.md#ec2-instances-should-use-imdsv2.

* docs: mention IMDSv2 usage in GuAutoScalingGroup docs
  • Loading branch information
jacobwinch authored Mar 11, 2022
1 parent 7d711ba commit 65260d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/constructs/autoscaling/asg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface GuAutoScalingGroupProps
| "minCapacity"
| "maxCapacity"
| "desiredCapacity"
| "requireImdsv2"
| "securityGroup"
>,
AppIdentity,
Expand Down Expand Up @@ -54,6 +55,9 @@ export interface GuAutoScalingGroupProps
*
* If additional ingress or egress rules are required, define custom security groups and pass them in via the
* `additionalSecurityGroups` prop.
*
* All EC2 instances provisioned via this construct will use
* [IMDSv2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html).
*/
export class GuAutoScalingGroup extends GuStatefulMigratableConstruct(GuAppAwareConstruct(AutoScalingGroup)) {
constructor(scope: GuStack, id: string, props: GuAutoScalingGroupProps) {
Expand Down Expand Up @@ -83,6 +87,7 @@ export class GuAutoScalingGroup extends GuStatefulMigratableConstruct(GuAppAware
minCapacity: minimumInstances,
maxCapacity: maximumInstances ?? minimumInstances * 2,
role,
requireImdsv2: true,
machineImage: {
getImage: (): MachineImageConfig => {
return {
Expand Down
6 changes: 6 additions & 0 deletions src/patterns/ec2-app/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ Object {
"Ref": "AMITestguec2app",
},
"InstanceType": "t4g.medium",
"MetadataOptions": Object {
"HttpTokens": "required",
},
"SecurityGroups": Array [
Object {
"Fn::GetAtt": Array [
Expand Down Expand Up @@ -1056,6 +1059,9 @@ Object {
"Ref": "AMITestguec2app",
},
"InstanceType": "t4g.medium",
"MetadataOptions": Object {
"HttpTokens": "required",
},
"SecurityGroups": Array [
Object {
"Fn::GetAtt": Array [
Expand Down

0 comments on commit 65260d7

Please sign in to comment.