-
Notifications
You must be signed in to change notification settings - Fork 20
/
policy.tf
151 lines (141 loc) · 3.89 KB
/
policy.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
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0 */
# --- single-account/policy.tf ---
resource "aws_networkfirewall_firewall_policy" "anfw_policy" {
name = "firewall-policy-${var.identifier}"
firewall_policy {
# Stateless configuration
stateless_default_actions = ["aws:forward_to_sfe"]
stateless_fragment_default_actions = ["aws:forward_to_sfe"]
stateless_rule_group_reference {
priority = 10
resource_arn = aws_networkfirewall_rule_group.drop_remote.arn
}
# Stateful configuration
stateful_engine_options {
rule_order = "STRICT_ORDER"
}
stateful_default_actions = ["aws:drop_strict", "aws:alert_strict"]
stateful_rule_group_reference {
priority = 10
resource_arn = aws_networkfirewall_rule_group.allow_icmp.arn
}
stateful_rule_group_reference {
priority = 20
resource_arn = aws_networkfirewall_rule_group.allow_tcp.arn
}
stateful_rule_group_reference {
priority = 30
resource_arn = aws_networkfirewall_rule_group.allow_domains.arn
}
}
}
# Stateless Rule Group - Dropping any SSH connection
resource "aws_networkfirewall_rule_group" "drop_remote" {
capacity = 2
name = "drop-remote-${var.identifier}"
type = "STATELESS"
rule_group {
rules_source {
stateless_rules_and_custom_actions {
stateless_rule {
priority = 1
rule_definition {
actions = ["aws:drop"]
match_attributes {
protocols = [6]
source {
address_definition = "0.0.0.0/0"
}
source_port {
from_port = 22
to_port = 22
}
destination {
address_definition = "0.0.0.0/0"
}
destination_port {
from_port = 22
to_port = 22
}
}
}
}
}
}
}
}
# Stateful Rule Group 1 - Allowing ICMP traffic
resource "aws_networkfirewall_rule_group" "allow_icmp" {
capacity = 1
name = "allow-icmp-${var.identifier}"
type = "STATEFUL"
rule_group {
rule_variables {
ip_sets {
key = "SUPERNET"
ip_set {
definition = ["10.0.0.0/16"]
}
}
}
rules_source {
rules_string = <<EOF
pass icmp $SUPERNET any -> $SUPERNET any (msg: "Allowing ICMP packets"; sid:2; rev:1;)
EOF
}
stateful_rule_options {
rule_order = "STRICT_ORDER"
}
}
}
# Stateful Rule Group 2 - Allowing TCP traffic to port 443 (HTTS) access to .amazon.com (HTTPS)
resource "aws_networkfirewall_rule_group" "allow_tcp" {
capacity = 1
name = "allow-tcp-${var.identifier}"
type = "STATEFUL"
rule_group {
rule_variables {
ip_sets {
key = "VPCS"
ip_set {
definition = values({for k, v in var.spoke_vpcs: k => v.cidr_block })
}
}
}
rules_source {
rules_string = <<EOF
pass tcp $VPCS any <> $EXTERNAL_NET 443 (msg:"Allowing TCP in port 443"; flow:not_established; sid:892123; rev:1;)
EOF
}
stateful_rule_options {
rule_order = "STRICT_ORDER"
}
}
}
# Stateful Rule Group 3 - Allowing access to .amazon.com (HTTPS)
resource "aws_networkfirewall_rule_group" "allow_domains" {
capacity = 100
name = "allow-domains-${var.identifier}"
type = "STATEFUL"
rule_group {
rule_variables {
ip_sets {
key = "HOME_NET"
ip_set {
definition = values({ for k, v in var.spoke_vpcs: k => v.cidr_block })
}
}
}
rules_source {
rules_source_list {
generated_rules_type = "ALLOWLIST"
target_types = ["TLS_SNI"]
targets = [".amazon.com"]
}
}
stateful_rule_options {
rule_order = "STRICT_ORDER"
}
}
}