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

Modify security group ingress rules to allow access only on specific ports #105

Merged
merged 1 commit into from
Mar 12, 2024
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
6 changes: 5 additions & 1 deletion lib/networking/vpc-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

// VPC specs
if (vpcId === 'undefined') {
console.log('No VPC-Id Provided, a new VPC will be created');

Check warning on line 57 in lib/networking/vpc-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
this.vpc = new Vpc(this, 'opensearchClusterVpc', {
cidr: cidrRange,
maxAzs: 3,
Expand All @@ -72,7 +72,7 @@
],
});
} else {
console.log('VPC provided, using existing');

Check warning on line 75 in lib/networking/vpc-stack.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
this.vpc = Vpc.fromLookup(this, 'opensearchClusterVpc', {
vpcId,
});
Expand All @@ -90,7 +90,11 @@

/* The security group allows all ip access by default to all the ports.
Please update below if you want to restrict access to certain ips and ports */
this.osSecurityGroup.addIngressRule(serverAccess, Port.allTcp());
this.osSecurityGroup.addIngressRule(serverAccess, Port.tcp(80));
this.osSecurityGroup.addIngressRule(serverAccess, Port.tcp(443));
this.osSecurityGroup.addIngressRule(serverAccess, Port.tcp(9200));
this.osSecurityGroup.addIngressRule(serverAccess, Port.tcp(5601));
this.osSecurityGroup.addIngressRule(serverAccess, Port.tcp(8443));
this.osSecurityGroup.addIngressRule(this.osSecurityGroup, Port.allTraffic());
}

Expand Down
32 changes: 32 additions & 0 deletions test/opensearch-cluster-cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,38 @@ test('Test Resources with security enabled multi-node with existing Vpc with use
SecurityGroupIngress: [
{
CidrIp: '10.10.10.10/32',
Description: 'from 10.10.10.10/32:80',
FromPort: 80,
IpProtocol: 'tcp',
ToPort: 80,
},
{
CidrIp: '10.10.10.10/32',
Description: 'from 10.10.10.10/32:443',
FromPort: 443,
IpProtocol: 'tcp',
ToPort: 443,
},
{
CidrIp: '10.10.10.10/32',
Description: 'from 10.10.10.10/32:9200',
FromPort: 9200,
IpProtocol: 'tcp',
ToPort: 9200,
},
{
CidrIp: '10.10.10.10/32',
Description: 'from 10.10.10.10/32:5601',
FromPort: 5601,
IpProtocol: 'tcp',
ToPort: 5601,
},
{
CidrIp: '10.10.10.10/32',
Description: 'from 10.10.10.10/32:8443',
FromPort: 8443,
IpProtocol: 'tcp',
ToPort: 8443,
},
],
});
Expand Down
Loading