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

Enable IMDSv2 on all instances #49

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
this file be licensed under the Apache-2.0 license or a
compatible open source license. */

import {
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
CfnOutput, RemovalPolicy, Stack, StackProps, Tags,
} from 'aws-cdk-lib';
import {
AutoScalingGroup, BlockDeviceVolume, EbsDeviceVolumeType, Signals,
} from 'aws-cdk-lib/aws-autoscaling';
import {
AmazonLinuxCpuType,
AmazonLinuxGeneration,
CloudFormationInit,
ISecurityGroup,
IVpc,
InitCommand,
InitElement,
InitPackage,
Instance,
InstanceClass,
InstanceSize,
InstanceType,
ISecurityGroup,
IVpc,
MachineImage,
SubnetType,
} from 'aws-cdk-lib/aws-ec2';
import { NetworkListener, NetworkLoadBalancer, Protocol } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { InstanceTarget } from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
import { ManagedPolicy, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import {
AutoScalingGroup, BlockDeviceVolume, EbsDeviceVolumeType, Signals,
} from 'aws-cdk-lib/aws-autoscaling';
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
import {
CfnOutput, RemovalPolicy, Stack, StackProps, Tags,
} from 'aws-cdk-lib';
import { NetworkListener, NetworkLoadBalancer, Protocol } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { join } from 'path';
import { readFileSync } from 'fs';
import { dump, load } from 'js-yaml';
import { InstanceTarget } from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
import { join } from 'path';
import { CloudwatchAgent } from '../cloudwatch/cloudwatch-agent';
import { nodeConfig } from '../opensearch-config/node-config';
import { RemoteStoreResources } from './remote-store-resources';
Expand Down Expand Up @@ -132,7 +132,7 @@
}

if (props.singleNodeCluster) {
console.log('Single node value is true, creating single node configurations');

Check warning on line 135 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
singleNodeInstance = new Instance(this, 'single-node-instance', {
vpc: props.vpc,
instanceType: singleNodeInstanceType,
Expand All @@ -153,6 +153,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
});
Tags.of(singleNodeInstance).add('role', 'client');

Expand Down Expand Up @@ -204,6 +205,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
signals: Signals.waitForAll(),
});
Tags.of(managerNodeAsg).add('role', 'manager');
Expand Down Expand Up @@ -237,6 +239,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
signals: Signals.waitForAll(),
});
Tags.of(seedNodeAsg).add('role', 'manager');
Expand Down Expand Up @@ -264,6 +267,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
signals: Signals.waitForAll(),
});
Tags.of(dataNodeAsg).add('role', 'data');
Expand Down Expand Up @@ -294,6 +298,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
signals: Signals.waitForAll(),
});
Tags.of(clientNodeAsg).add('cluster', scope.stackName);
Expand Down Expand Up @@ -325,6 +330,7 @@
initOptions: {
ignoreFailures: false,
},
requireImdsv2: true,
signals: Signals.waitForAll(),
});

Expand Down Expand Up @@ -429,7 +435,7 @@

fileContent['cluster.name'] = `${scope.stackName}-${scope.account}-${scope.region}`;

console.log(dump(fileContent).toString());

Check warning on line 438 in lib/infra/infra-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
opensearchConfig = dump(fileContent).toString();
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;cd opensearch; echo "${opensearchConfig}" > config/opensearch.yml`,
{
Expand Down
15 changes: 15 additions & 0 deletions test/os-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ test('Test Resources with security disabled multi-node default instance types',
Ref: 'managerNodeAsgInstanceProfile1415C2CF',
},
});
infraTemplate.hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', {
MetadataOptions: {
HttpTokens: 'required',
peterzhuamazon marked this conversation as resolved.
Show resolved Hide resolved
},
});
});

test('Test Resources with security enabled multi-node with existing Vpc with user provided data and ml instance types', () => {
Expand Down Expand Up @@ -144,6 +149,11 @@ test('Test Resources with security enabled multi-node with existing Vpc with use
Ref: 'mlNodeAsgInstanceProfileFF393D8C',
},
});
infraTemplate.hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', {
MetadataOptions: {
HttpTokens: 'required',
},
});
});

test('Test Resources with security enabled single-node cluster', () => {
Expand Down Expand Up @@ -307,6 +317,11 @@ test('Test multi-node cluster with only data-nodes', () => {
},
],
});
infraTemplate.hasResourceProperties('AWS::AutoScaling::LaunchConfiguration', {
MetadataOptions: {
HttpTokens: 'required',
},
});
});

test('Test multi-node cluster with remote-store enabled', () => {
Expand Down
Loading