-
Notifications
You must be signed in to change notification settings - Fork 60
/
vpc-security-groups.tf
176 lines (156 loc) · 5.37 KB
/
vpc-security-groups.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Security Groups (SG)
## Load Balancer SG
resource "aws_security_group" "load_balancer" {
name_prefix = "${var.main_project_tag}-alb-sg"
description = "Firewall for the application load balancer fronting the vault instances."
vpc_id = aws_vpc.vault.id
tags = merge(
{ "Name" = "${var.main_project_tag}-alb-sg" },
{ "Project" = var.main_project_tag }
)
}
resource "aws_security_group_rule" "load_balancer_allow_80" {
security_group_id = aws_security_group.load_balancer.id
type = "ingress"
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = var.allowed_traffic_cidr_blocks
ipv6_cidr_blocks = length(var.allowed_traffic_cidr_blocks_ipv6) > 0 ? var.allowed_traffic_cidr_blocks_ipv6 : null
description = "Allow HTTP traffic."
}
resource "aws_security_group_rule" "load_balancer_allow_443" {
security_group_id = aws_security_group.load_balancer.id
type = "ingress"
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = var.allowed_traffic_cidr_blocks
ipv6_cidr_blocks = length(var.allowed_traffic_cidr_blocks_ipv6) > 0 ? var.allowed_traffic_cidr_blocks_ipv6 : null
description = "Allow HTTPS traffic."
}
## Only the Load Balancer is set up to work with IPv6. Once a request
## comes in, it all goes through IPv4 internally.
resource "aws_security_group_rule" "load_balancer_allow_outbound" {
security_group_id = aws_security_group.load_balancer.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = length(var.allowed_traffic_cidr_blocks_ipv6) > 0 ? ["::/0"] : null
description = "Allow any outbound traffic."
}
## Vault Instance SG
resource "aws_security_group" "vault_instance" {
name_prefix = "${var.main_project_tag}-vault-instance-sg"
description = "Firewall for the vault instances."
vpc_id = aws_vpc.vault.id
tags = merge(
{ "Name" = "${var.main_project_tag}-vault-instance-sg" },
{ "Project" = var.main_project_tag }
)
}
resource "aws_security_group_rule" "vault_instance_allow_8200" {
security_group_id = aws_security_group.vault_instance.id
type = "ingress"
protocol = "tcp"
from_port = 8200
to_port = 8200
source_security_group_id = aws_security_group.load_balancer.id
description = "Allow traffic from Load Balancer."
}
resource "aws_security_group_rule" "vault_instance_allow_8201" {
security_group_id = aws_security_group.vault_instance.id
type = "ingress"
protocol = "tcp"
from_port = 8201
to_port = 8201
self = true
description = "Allow traffic from fellow vault instances that have this SG."
}
resource "aws_security_group_rule" "vault_instance_allow_22_bastion" {
security_group_id = aws_security_group.vault_instance.id
type = "ingress"
protocol = "tcp"
from_port = 22
to_port = 22
source_security_group_id = aws_security_group.bastion.id
description = "Allow SSH traffic from vault bastion."
}
resource "aws_security_group_rule" "vault_instance_allow_outbound" {
security_group_id = aws_security_group.vault_instance.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
description = "Allow any outbound traffic."
}
## Bastion SG
resource "aws_security_group" "bastion" {
name_prefix = "${var.main_project_tag}-bastion-sg"
description = "Firewall for the operator bastion instance"
vpc_id = aws_vpc.vault.id
tags = merge(
{ "Name" = "${var.main_project_tag}-bastion-sg" },
{ "Project" = var.main_project_tag }
)
}
resource "aws_security_group_rule" "bastion_allow_22" {
security_group_id = aws_security_group.bastion.id
type = "ingress"
protocol = "tcp"
from_port = 22
to_port = 22
cidr_blocks = var.allowed_bastion_cidr_blocks
ipv6_cidr_blocks = length(var.allowed_bastion_cidr_blocks_ipv6) > 0 ? var.allowed_bastion_cidr_blocks_ipv6 : null
description = "Allow SSH traffic."
}
resource "aws_security_group_rule" "bastion_allow_outbound" {
security_group_id = aws_security_group.bastion.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = length(var.allowed_bastion_cidr_blocks_ipv6) > 0 ? ["::/0"] : null
description = "Allow any outbound traffic."
}
## KMS Endpoint SG
resource "aws_security_group" "kms_endpoint" {
name_prefix = "${var.main_project_tag}-kms-endpoint-sg"
description = "Firewall for the KMS Endpoint."
vpc_id = aws_vpc.vault.id
tags = merge(
{ "Name" = "${var.main_project_tag}-kms-endpoint-sg" },
{ "Project" = var.main_project_tag }
)
}
resource "aws_security_group_rule" "vault_instance_allow_80" {
security_group_id = aws_security_group.kms_endpoint.id
type = "ingress"
protocol = "tcp"
from_port = 80
to_port = 80
source_security_group_id = aws_security_group.vault_instance.id
description = "Allow HTTP traffic from vault instances."
}
resource "aws_security_group_rule" "vault_instance_allow_443" {
security_group_id = aws_security_group.kms_endpoint.id
type = "ingress"
protocol = "tcp"
from_port = 443
to_port = 443
source_security_group_id = aws_security_group.vault_instance.id
description = "Allow HTTPS traffic from vault instances."
}
resource "aws_security_group_rule" "kms_allow_outbound" {
security_group_id = aws_security_group.kms_endpoint.id
type = "egress"
protocol = "-1"
from_port = 0
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
description = "Allow any outbound traffic."
}