-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsecurity.tf
110 lines (97 loc) · 2.99 KB
/
security.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
resource "aws_security_group" "k8s_sg" {
vpc_id = var.vpc_id
name = "k8s_sg"
description = "Kubernetes ingress rules"
lifecycle {
create_before_destroy = true
}
tags = merge(
local.global_tags,
{
"Name" = lower("${var.common_prefix}-allow-strict-${var.environment}")
}
)
}
resource "aws_security_group_rule" "ingress_self" {
type = "ingress"
from_port = 0
to_port = 0
protocol = "-1"
self = true
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "ingress_kubeapi" {
type = "ingress"
from_port = var.kube_api_port
to_port = var.kube_api_port
protocol = "tcp"
cidr_blocks = [var.vpc_subnet_cidr]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "ingress_ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [var.my_public_ip_cidr]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "egress_all" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "allow_lb_http_traffic" {
count = var.create_extlb ? 1 : 0
type = "ingress"
from_port = var.extlb_listener_http_port
to_port = var.extlb_listener_http_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "allow_lb_https_traffic" {
count = var.create_extlb ? 1 : 0
type = "ingress"
from_port = var.extlb_listener_https_port
to_port = var.extlb_listener_https_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group_rule" "allow_lb_kubeapi_traffic" {
count = var.create_extlb && var.expose_kubeapi ? 1 : 0
type = "ingress"
from_port = var.kube_api_port
to_port = var.kube_api_port
protocol = "tcp"
cidr_blocks = [var.my_public_ip_cidr]
security_group_id = aws_security_group.k8s_sg.id
}
resource "aws_security_group" "efs_sg" {
count = var.efs_persistent_storage ? 1 : 0
vpc_id = var.vpc_id
name = "${var.common_prefix}-efs-sg-${var.environment}"
description = "Allow EFS access from VPC subnets"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = [var.vpc_subnet_cidr]
}
tags = merge(
local.global_tags,
{
"Name" = lower("${var.common_prefix}-efs-sg-${var.environment}")
}
)
}