Skip to content

Commit 0c9414a

Browse files
committed
eli-383 switching to trying to restrict egress via security groups rather than nacls
1 parent 2d1b232 commit 0c9414a

File tree

5 files changed

+46
-53
lines changed

5 files changed

+46
-53
lines changed

infrastructure/stacks/iams-developer-roles/github_actions_policies.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ resource "aws_iam_policy" "api_infrastructure" {
344344
"ec2:ReplaceNetworkAclAssociation",
345345
"ec2:DeleteSecurityGroup",
346346
"ec2:DeleteNetworkAcl",
347+
"ec2:UpdateSecurityGroupRuleDescriptionsEgress",
347348

348349
# ssm
349350
"ssm:GetParameter",

infrastructure/stacks/iams-developer-roles/iams_permissions_boundary.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ data "aws_iam_policy_document" "permissions_boundary" {
6464
"ec2:CreateFlowLogs",
6565
"ec2:ReplaceNetworkAclAssociation",
6666
"ec2:DeleteSecurityGroup",
67+
"ec2:UpdateSecurityGroupRuleDescriptionsEgress",
6768

6869
# EventBridge - alarm forwarding to Splunk
6970
"events:PutRule",

infrastructure/stacks/networking/locals.tf

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
locals {
2+
any_ip_cidr = "0.0.0.0/0"
23
vpc_cidr_block = "10.0.0.0/16"
34
private_subnet_1_cidr = "10.0.6.0/24"
45
private_subnet_2_cidr = "10.0.7.0/24"
@@ -13,15 +14,15 @@ locals {
1314

1415
# VPC Interface Endpoints
1516
vpc_interface_endpoints = {
16-
kms = "com.amazonaws.${local.region}.kms"
17-
cloudwatch-logs = "com.amazonaws.${local.region}.logs"
18-
ssm = "com.amazonaws.${local.region}.ssm"
19-
secrets-manager = "com.amazonaws.${local.region}.secretsmanager"
20-
lambda = "com.amazonaws.${local.region}.lambda"
21-
sts = "com.amazonaws.${local.region}.sts"
22-
sqs = "com.amazonaws.${local.region}.sqs"
23-
kinesis-firehose = "com.amazonaws.${local.region}.kinesis-firehose"
24-
xray = "com.amazonaws.${local.region}.xray"
17+
kms = "com.amazonaws.${local.region}.kms"
18+
cloudwatch-logs = "com.amazonaws.${local.region}.logs"
19+
ssm = "com.amazonaws.${local.region}.ssm"
20+
secrets-manager = "com.amazonaws.${local.region}.secretsmanager"
21+
lambda = "com.amazonaws.${local.region}.lambda"
22+
sts = "com.amazonaws.${local.region}.sts"
23+
sqs = "com.amazonaws.${local.region}.sqs"
24+
kinesis-firehose = "com.amazonaws.${local.region}.kinesis-firehose"
25+
xray = "com.amazonaws.${local.region}.xray"
2526

2627
}
2728

infrastructure/stacks/networking/network_acls.tf

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,16 @@ resource "aws_network_acl" "private" {
77
aws_subnet.private_3.id
88
]
99

10-
# Allow outbound traffic from private subnets to VPC CIDR only
10+
# Allow all outbound traffic from private subnets
1111
egress {
1212
rule_no = 100
1313
action = "allow"
14-
cidr_block = local.vpc_cidr_block
14+
cidr_block = "0.0.0.0/0"
1515
protocol = -1
1616
from_port = 0
1717
to_port = 0
1818
}
1919

20-
# Allow HTTPS egress for Gateway endpoints (S3 and DynamoDB)
21-
# Gateway endpoints use AWS prefix lists which can't be specified in NACLs
22-
# This allows HTTPS to any destination, but security groups still control actual access
23-
egress {
24-
rule_no = 110
25-
action = "allow"
26-
cidr_block = "0.0.0.0/0"
27-
protocol = "tcp"
28-
from_port = 443
29-
to_port = 443
30-
}
31-
32-
# Allow ephemeral port responses for Gateway endpoint traffic
33-
egress {
34-
rule_no = 120
35-
action = "allow"
36-
cidr_block = "0.0.0.0/0"
37-
protocol = "tcp"
38-
from_port = 1024
39-
to_port = 65535
40-
}
41-
4220
# Allow inbound traffic from within the VPC
4321
ingress {
4422
rule_no = 100
@@ -49,31 +27,21 @@ resource "aws_network_acl" "private" {
4927
to_port = 0
5028
}
5129

52-
# Allow HTTPS responses from Gateway endpoints
53-
ingress {
54-
rule_no = 110
55-
action = "allow"
56-
cidr_block = "0.0.0.0/0"
57-
protocol = "tcp"
58-
from_port = 443
59-
to_port = 443
60-
}
61-
6230
# Block RDP access
6331
ingress {
64-
rule_no = 150
65-
action = "deny"
66-
cidr_block = "0.0.0.0/0"
67-
protocol = "tcp"
68-
from_port = 3389
69-
to_port = 3389
32+
rule_no = 150
33+
action = "deny"
34+
cidr_block = "0.0.0.0/0"
35+
protocol = "tcp"
36+
from_port = 3389
37+
to_port = 3389
7038
}
7139

72-
# Allow responses to outbound requests (ephemeral ports) from VPC endpoints
40+
# Allow responses to outbound requests (ephemeral ports)
7341
ingress {
7442
rule_no = 200
7543
action = "allow"
76-
cidr_block = local.vpc_cidr_block
44+
cidr_block = "0.0.0.0/0"
7745
protocol = "tcp"
7846
from_port = 1024
7947
to_port = 65535

infrastructure/stacks/networking/vpc_endpoints.tf

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,34 @@ resource "aws_security_group_rule" "main_https_in" {
2020
}
2121

2222
resource "aws_security_group_rule" "main_https_out" {
23-
description = "Allow VPC resources to access VPC endpoints and AWS services"
23+
description = "Allow HTTPS access to Interface VPC Endpoints within VPC"
2424
type = "egress"
2525
from_port = local.default_port
2626
to_port = local.default_port
2727
protocol = "tcp"
28-
cidr_blocks = ["0.0.0.0/0"]
28+
cidr_blocks = [local.vpc_cidr_block]
29+
security_group_id = aws_security_group.main.id
30+
}
31+
32+
# Allow egress to S3 via Gateway endpoint prefix list
33+
resource "aws_security_group_rule" "main_s3_prefix_out" {
34+
description = "Allow HTTPS access to S3 via Gateway endpoint"
35+
type = "egress"
36+
from_port = local.default_port
37+
to_port = local.default_port
38+
protocol = "tcp"
39+
prefix_list_ids = [aws_vpc_endpoint.gateways["s3"].prefix_list_id]
40+
security_group_id = aws_security_group.main.id
41+
}
42+
43+
# Allow egress to DynamoDB via Gateway endpoint prefix list
44+
resource "aws_security_group_rule" "main_dynamodb_prefix_out" {
45+
description = "Allow HTTPS access to DynamoDB via Gateway endpoint"
46+
type = "egress"
47+
from_port = local.default_port
48+
to_port = local.default_port
49+
protocol = "tcp"
50+
prefix_list_ids = [aws_vpc_endpoint.gateways["dynamodb"].prefix_list_id]
2951
security_group_id = aws_security_group.main.id
3052
}
3153

0 commit comments

Comments
 (0)