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

Update the sslPolicy from default to recommended TLS #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
82 changes: 41 additions & 41 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
import { Unit } from 'aws-cdk-lib/aws-cloudwatch';
import {
AmazonLinuxCpuType,
AmazonLinuxGeneration,
CloudFormationInit,
ISecurityGroup,
IVpc,
InitCommand,
InitElement,
InitPackage,
Instance,
InstanceClass,
InstanceSize,
Expand All @@ -40,6 +38,7 @@
BaseNetworkListenerProps,
ListenerCertificate,
NetworkListener, NetworkLoadBalancer, Protocol,
SslPolicy,
} from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { InstanceTarget } from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets';
import {
Expand All @@ -59,9 +58,9 @@
} from '../opensearch-config/node-config';
import { RemoteStoreResources } from './remote-store-resources';

enum cpuArchEnum{
X64='x64',
ARM64='arm64'
enum cpuArchEnum {
X64 = 'x64',
ARM64 = 'arm64'
}

export enum LoadBalancerType {
Expand Down Expand Up @@ -142,11 +141,11 @@
/** Whether to enable monioring with alarms */
readonly enableMonitoring?: boolean,
/** Certificate ARN to attach to the listener */
readonly certificateArn ?: string
readonly certificateArn?: string
/** Map opensearch port on load balancer to */
readonly mapOpensearchPortTo ?: number
readonly mapOpensearchPortTo?: number
/** Map opensearch-dashboards port on load balancer to */
readonly mapOpensearchDashboardsPortTo ?: number
readonly mapOpensearchDashboardsPortTo?: number
/** Type of load balancer to use (e.g., 'nlb' or 'alb') */
readonly loadBalancerType?: LoadBalancerType
/** Use instance based storage (if supported) on ec2 instance */
Expand Down Expand Up @@ -470,7 +469,7 @@

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

const useSSLOpensearchListener = !this.securityDisabled && !this.minDistribution && this.opensearchPortMapping === 443 && certificateArn !== 'undefined';
Expand All @@ -485,7 +484,7 @@
let dashboardsListener: NetworkListener | ApplicationListener;
if (this.dashboardsUrl !== 'undefined') {
const useSSLDashboardsListener = !this.securityDisabled && !this.minDistribution
&& this.opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined';
&& this.opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined';
dashboardsListener = InfraStack.createListener(
this.elb,
this.elbType,
Expand All @@ -495,7 +494,7 @@
);
}
if (this.singleNodeCluster) {
console.log('Single node value is true, creating single node configurations');

Check warning on line 497 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 Down Expand Up @@ -537,12 +536,12 @@

if (this.dashboardsUrl !== 'undefined') {
InfraStack.addTargetsToListener(
dashboardsListener!,
this.elbType,
'single-node-osd-target',
5601,
new InstanceTarget(singleNodeInstance),
false,
dashboardsListener!,
this.elbType,
'single-node-osd-target',
5601,
new InstanceTarget(singleNodeInstance),
false,
);
}
new CfnOutput(this, 'private-ip', {
Expand Down Expand Up @@ -761,12 +760,12 @@

if (this.dashboardsUrl !== 'undefined') {
InfraStack.addTargetsToListener(
dashboardsListener!,
this.elbType,
'dashboardsTarget',
5601,
clientNodeAsg,
false,
dashboardsListener!,
this.elbType,
'dashboardsTarget',
5601,
clientNodeAsg,
false,
);
}
}
Expand Down Expand Up @@ -804,7 +803,7 @@

if ((nodeType === 'data' || nodeType === 'single-node') && this.useInstanceBasedStorage) {
cfnInitConfig.push(InitCommand.shellCommand('set -ex; sudo mkfs -t xfs /dev/nvme1n1; '
+ 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data',
+ 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data',
{
ignoreErrors: false,
}));
Expand All @@ -813,11 +812,11 @@

const cwInit = [
InitCommand.shellCommand('MAX_RETRIES=5; RETRY_DELAY=10; for i in $(seq 1 $MAX_RETRIES); '
+ 'do sudo yum install -y amazon-cloudwatch-agent && break || '
+ '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done'),
+ 'do sudo yum install -y amazon-cloudwatch-agent && break || '
+ '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done'),
InitCommand.shellCommand('arc=$(arch); if [ "$arc" == "aarch64" ]; then dist="arm64"; else dist="amd64"; fi; '
+ 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
+ '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq'),
+ 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
+ '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq'),
CloudwatchAgent.asInitFile('/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json',
{
agent: {
Expand Down Expand Up @@ -900,7 +899,7 @@
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'),
InitCommand.shellCommand('set -ex; sudo echo "vm.max_map_count=262144" >> /etc/sysctl.conf;sudo sysctl -p'),
InitCommand.shellCommand(`set -ex;mkdir opensearch; curl -L ${this.distributionUrl} -o opensearch.tar.gz;`
+ 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;', {
+ 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;', {
cwd: currentWorkDir,
ignoreErrors: false,
}),
Expand Down Expand Up @@ -950,8 +949,8 @@
}));
} else {
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
+ `/tar/builds/opensearch/core-plugins/discovery-ec2-${this.distVersion}.zip --batch`, {
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
+ `/tar/builds/opensearch/core-plugins/discovery-ec2-${this.distVersion}.zip --batch`, {
cwd: currentWorkDir,
ignoreErrors: false,
}));
Expand Down Expand Up @@ -997,8 +996,8 @@
}));
} else {
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
+ `/tar/builds/opensearch/core-plugins/repository-s3-${this.distVersion}.zip --batch`, {
+ `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${this.distVersion}/latest/linux/${this.cpuArch}`
+ `/tar/builds/opensearch/core-plugins/repository-s3-${this.distVersion}.zip --batch`, {
cwd: currentWorkDir,
ignoreErrors: false,
}));
Expand All @@ -1017,7 +1016,7 @@
// Check if there are any jvm properties being passed
if (this.jvmSysProps.toString() !== 'undefined') {
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch; jvmSysPropsList=$(echo "${this.jvmSysProps.toString()}" | tr ',' '\\n');`
+ 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done',
+ 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done',
{
cwd: currentWorkDir,
ignoreErrors: false,
Expand All @@ -1039,7 +1038,7 @@

if (this.additionalConfig.toString() !== 'undefined') {
cfnInitConfig.push(InitCommand.shellCommand(`set -ex; cd opensearch/config; echo "${this.additionalConfig}">additionalConfig.yml; `
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P',
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P',
{
cwd: currentWorkDir,
ignoreErrors: false,
Expand Down Expand Up @@ -1072,7 +1071,7 @@
}));
} else {
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch; '
+ `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${this.adminPassword} ./opensearch-tar-install.sh >> install.log 2>&1 &`,
+ `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${this.adminPassword} ./opensearch-tar-install.sh >> install.log 2>&1 &`,
{
cwd: currentWorkDir,
ignoreErrors: false,
Expand All @@ -1082,7 +1081,7 @@
// If OpenSearch-Dashboards URL is present
if (this.dashboardsUrl !== 'undefined') {
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;mkdir opensearch-dashboards; curl -L ${this.dashboardsUrl} -o opensearch-dashboards.tar.gz;`
+ 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;', {
+ 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;', {
cwd: currentWorkDir,
ignoreErrors: false,
}));
Expand All @@ -1095,9 +1094,9 @@

if (this.securityDisabled && !this.minDistribution) {
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch-dashboards;'
+ './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
+ 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
+ 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml',
+ './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
+ 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
+ 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml',
{
cwd: currentWorkDir,
ignoreErrors: false,
Expand All @@ -1106,7 +1105,7 @@

if (this.additionalOsdConfig.toString() !== 'undefined') {
cfnInitConfig.push(InitCommand.shellCommand(`set -ex;cd opensearch-dashboards/config; echo "${this.additionalOsdConfig}">additionalOsdConfig.yml; `
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P',
+ 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P',
{
cwd: currentWorkDir,
ignoreErrors: false,
Expand All @@ -1115,7 +1114,7 @@

// Starting OpenSearch-Dashboards
cfnInitConfig.push(InitCommand.shellCommand('set -ex;cd opensearch-dashboards;'
+ 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &', {
+ 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &', {
cwd: currentWorkDir,
ignoreErrors: false,
}));
Expand Down Expand Up @@ -1146,6 +1145,7 @@
}

const listenerProps: BaseApplicationListenerProps | BaseNetworkListenerProps = {
sslPolicy: SslPolicy.RECOMMENDED_TLS,
port,
protocol,
certificates: useSSL ? [ListenerCertificate.fromArn(certificateArn)] : undefined,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensearch-project/opensearch-cluster-cdk",
"version": "1.4.0",
"version": "1.3.0",
"bin": {
"cdk_v2": "bin/app.js"
},
Expand Down Expand Up @@ -35,4 +35,4 @@
"semver": "^7.5.4",
"source-map-support": "^0.5.21"
}
}
}
Loading