Skip to content

Commit 78170f7

Browse files
committed
Update the sslPolicy from default to recommended TLS
Signed-off-by: Sayali Gaikawad <[email protected]>
1 parent b4c314d commit 78170f7

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

lib/infra/infra-stack.ts

+41-41
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ import {
1414
import { Unit } from 'aws-cdk-lib/aws-cloudwatch';
1515
import {
1616
AmazonLinuxCpuType,
17-
AmazonLinuxGeneration,
1817
CloudFormationInit,
1918
ISecurityGroup,
2019
IVpc,
2120
InitCommand,
2221
InitElement,
23-
InitPackage,
2422
Instance,
2523
InstanceClass,
2624
InstanceSize,
@@ -40,6 +38,7 @@ import {
4038
BaseNetworkListenerProps,
4139
ListenerCertificate,
4240
NetworkListener, NetworkLoadBalancer, Protocol,
41+
SslPolicy,
4342
} from 'aws-cdk-lib/aws-elasticloadbalancingv2';
4443
import { InstanceTarget } from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
4544
import {
@@ -59,9 +58,9 @@ import {
5958
} from '../opensearch-config/node-config';
6059
import { RemoteStoreResources } from './remote-store-resources';
6160

62-
enum cpuArchEnum{
63-
X64='x64',
64-
ARM64='arm64'
61+
enum cpuArchEnum {
62+
X64 = 'x64',
63+
ARM64 = 'arm64'
6564
}
6665

6766
export enum LoadBalancerType {
@@ -142,11 +141,11 @@ export interface InfraProps extends StackProps {
142141
/** Whether to enable monioring with alarms */
143142
readonly enableMonitoring?: boolean,
144143
/** Certificate ARN to attach to the listener */
145-
readonly certificateArn ?: string
144+
readonly certificateArn?: string
146145
/** Map opensearch port on load balancer to */
147-
readonly mapOpensearchPortTo ?: number
146+
readonly mapOpensearchPortTo?: number
148147
/** Map opensearch-dashboards port on load balancer to */
149-
readonly mapOpensearchDashboardsPortTo ?: number
148+
readonly mapOpensearchDashboardsPortTo?: number
150149
/** Type of load balancer to use (e.g., 'nlb' or 'alb') */
151150
readonly loadBalancerType?: LoadBalancerType
152151
/** Use instance based storage (if supported) on ec2 instance */
@@ -470,7 +469,7 @@ export class InfraStack extends Stack {
470469

471470
if (this.opensearchPortMapping === this.opensearchDashboardsPortMapping) {
472471
throw new Error('OpenSearch and OpenSearch-Dashboards cannot be mapped to the same port! Please provide different port numbers.'
473-
+ ` Current mapping is OpenSearch:${this.opensearchPortMapping} OpenSearch-Dashboards:${this.opensearchDashboardsPortMapping}`);
472+
+ ` Current mapping is OpenSearch:${this.opensearchPortMapping} OpenSearch-Dashboards:${this.opensearchDashboardsPortMapping}`);
474473
}
475474

476475
const useSSLOpensearchListener = !this.securityDisabled && !this.minDistribution && this.opensearchPortMapping === 443 && certificateArn !== 'undefined';
@@ -485,7 +484,7 @@ export class InfraStack extends Stack {
485484
let dashboardsListener: NetworkListener | ApplicationListener;
486485
if (this.dashboardsUrl !== 'undefined') {
487486
const useSSLDashboardsListener = !this.securityDisabled && !this.minDistribution
488-
&& this.opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined';
487+
&& this.opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined';
489488
dashboardsListener = InfraStack.createListener(
490489
this.elb,
491490
this.elbType,
@@ -537,12 +536,12 @@ export class InfraStack extends Stack {
537536

538537
if (this.dashboardsUrl !== 'undefined') {
539538
InfraStack.addTargetsToListener(
540-
dashboardsListener!,
541-
this.elbType,
542-
'single-node-osd-target',
543-
5601,
544-
new InstanceTarget(singleNodeInstance),
545-
false,
539+
dashboardsListener!,
540+
this.elbType,
541+
'single-node-osd-target',
542+
5601,
543+
new InstanceTarget(singleNodeInstance),
544+
false,
546545
);
547546
}
548547
new CfnOutput(this, 'private-ip', {
@@ -761,12 +760,12 @@ export class InfraStack extends Stack {
761760

762761
if (this.dashboardsUrl !== 'undefined') {
763762
InfraStack.addTargetsToListener(
764-
dashboardsListener!,
765-
this.elbType,
766-
'dashboardsTarget',
767-
5601,
768-
clientNodeAsg,
769-
false,
763+
dashboardsListener!,
764+
this.elbType,
765+
'dashboardsTarget',
766+
5601,
767+
clientNodeAsg,
768+
false,
770769
);
771770
}
772771
}
@@ -804,7 +803,7 @@ export class InfraStack extends Stack {
804803

805804
if ((nodeType === 'data' || nodeType === 'single-node') && this.useInstanceBasedStorage) {
806805
cfnInitConfig.push(InitCommand.shellCommand('set -ex; sudo mkfs -t xfs /dev/nvme1n1; '
807-
+ 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data',
806+
+ 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data',
808807
{
809808
ignoreErrors: false,
810809
}));
@@ -813,11 +812,11 @@ export class InfraStack extends Stack {
813812

814813
const cwInit = [
815814
InitCommand.shellCommand('MAX_RETRIES=5; RETRY_DELAY=10; for i in $(seq 1 $MAX_RETRIES); '
816-
+ 'do sudo yum install -y amazon-cloudwatch-agent && break || '
817-
+ '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done'),
815+
+ 'do sudo yum install -y amazon-cloudwatch-agent && break || '
816+
+ '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done'),
818817
InitCommand.shellCommand('arc=$(arch); if [ "$arc" == "aarch64" ]; then dist="arm64"; else dist="amd64"; fi; '
819-
+ 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
820-
+ '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq'),
818+
+ 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
819+
+ '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq'),
821820
CloudwatchAgent.asInitFile('/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json',
822821
{
823822
agent: {
@@ -900,7 +899,7 @@ export class InfraStack extends Stack {
900899
InitCommand.shellCommand('set -ex;/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s'),
901900
InitCommand.shellCommand('set -ex; sudo echo "vm.max_map_count=262144" >> /etc/sysctl.conf;sudo sysctl -p'),
902901
InitCommand.shellCommand(`set -ex;mkdir opensearch; curl -L ${this.distributionUrl} -o opensearch.tar.gz;`
903-
+ 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;', {
902+
+ 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;', {
904903
cwd: currentWorkDir,
905904
ignoreErrors: false,
906905
}),
@@ -950,8 +949,8 @@ export class InfraStack extends Stack {
950949
}));
951950
} else {
952951
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
953-
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
954-
+ `/tar/builds/opensearch/core-plugins/discovery-ec2-${this.distVersion}.zip --batch`, {
952+
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
953+
+ `/tar/builds/opensearch/core-plugins/discovery-ec2-${this.distVersion}.zip --batch`, {
955954
cwd: currentWorkDir,
956955
ignoreErrors: false,
957956
}));
@@ -997,8 +996,8 @@ export class InfraStack extends Stack {
997996
}));
998997
} else {
999998
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
1000-
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
1001-
+ `/tar/builds/opensearch/core-plugins/repository-s3-${this.distVersion}.zip --batch`, {
999+
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
1000+
+ `/tar/builds/opensearch/core-plugins/repository-s3-${this.distVersion}.zip --batch`, {
10021001
cwd: currentWorkDir,
10031002
ignoreErrors: false,
10041003
}));
@@ -1017,7 +1016,7 @@ export class InfraStack extends Stack {
10171016
// Check if there are any jvm properties being passed
10181017
if (this.jvmSysProps.toString() !== 'undefined') {
10191018
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch; jvmSysPropsList=$(echo "${this.jvmSysProps.toString()}" | tr ',' '\\n');`
1020-
+ 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done',
1019+
+ 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done',
10211020
{
10221021
cwd: currentWorkDir,
10231022
ignoreErrors: false,
@@ -1039,7 +1038,7 @@ export class InfraStack extends Stack {
10391038

10401039
if (this.additionalConfig.toString() !== 'undefined') {
10411040
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch/config; echo "${this.additionalConfig}">additionalConfig.yml; `
1042-
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P',
1041+
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P',
10431042
{
10441043
cwd: currentWorkDir,
10451044
ignoreErrors: false,
@@ -1072,7 +1071,7 @@ export class InfraStack extends Stack {
10721071
}));
10731072
} else {
10741073
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch; '
1075-
+ `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${this.adminPassword} ./opensearch-tar-install.sh >> install.log 2>&1 &`,
1074+
+ `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${this.adminPassword} ./opensearch-tar-install.sh >> install.log 2>&1 &`,
10761075
{
10771076
cwd: currentWorkDir,
10781077
ignoreErrors: false,
@@ -1082,7 +1081,7 @@ export class InfraStack extends Stack {
10821081
// If OpenSearch-Dashboards URL is present
10831082
if (this.dashboardsUrl !== 'undefined') {
10841083
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;mkdir opensearch-dashboards; curl -L ${this.dashboardsUrl} -o opensearch-dashboards.tar.gz;`
1085-
+ 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;', {
1084+
+ 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;', {
10861085
cwd: currentWorkDir,
10871086
ignoreErrors: false,
10881087
}));
@@ -1095,9 +1094,9 @@ export class InfraStack extends Stack {
10951094

10961095
if (this.securityDisabled && !this.minDistribution) {
10971096
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch-dashboards;'
1098-
+ './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
1099-
+ 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
1100-
+ 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml',
1097+
+ './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
1098+
+ 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
1099+
+ 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml',
11011100
{
11021101
cwd: currentWorkDir,
11031102
ignoreErrors: false,
@@ -1106,7 +1105,7 @@ export class InfraStack extends Stack {
11061105

11071106
if (this.additionalOsdConfig.toString() !== 'undefined') {
11081107
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;cd opensearch-dashboards/config; echo "${this.additionalOsdConfig}">additionalOsdConfig.yml; `
1109-
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P',
1108+
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P',
11101109
{
11111110
cwd: currentWorkDir,
11121111
ignoreErrors: false,
@@ -1115,7 +1114,7 @@ export class InfraStack extends Stack {
11151114

11161115
// Starting OpenSearch-Dashboards
11171116
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch-dashboards;'
1118-
+ 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &', {
1117+
+ 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &', {
11191118
cwd: currentWorkDir,
11201119
ignoreErrors: false,
11211120
}));
@@ -1146,6 +1145,7 @@ export class InfraStack extends Stack {
11461145
}
11471146

11481147
const listenerProps: BaseApplicationListenerProps | BaseNetworkListenerProps = {
1148+
sslPolicy: SslPolicy.RECOMMENDED_TLS,
11491149
port,
11501150
protocol,
11511151
certificates: useSSL ? [ListenerCertificate.fromArn(certificateArn)] : undefined,

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opensearch-project/opensearch-cluster-cdk",
3-
"version": "1.4.0",
3+
"version": "1.3.0",
44
"bin": {
55
"cdk_v2": "bin/app.js"
66
},
@@ -35,4 +35,4 @@
3535
"semver": "^7.5.4",
3636
"source-map-support": "^0.5.21"
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)