Add service-specific web egress rules
This commit is contained in:
@@ -180,6 +180,21 @@ module "network_public" {
|
||||
public_tcp_ports = [80, 443]
|
||||
}
|
||||
|
||||
web_egress_service_rules = {
|
||||
consul_serf_lan = {
|
||||
description = "Allow Consul Serf LAN gossip to the homelab service network"
|
||||
ip_protocol = "udp"
|
||||
port = 8301
|
||||
cidr_ipv4 = "192.168.10.0/24"
|
||||
}
|
||||
loki_ingest = {
|
||||
description = "Allow Loki ingest to the homelab service network"
|
||||
ip_protocol = "tcp"
|
||||
port = 3100
|
||||
cidr_ipv4 = "192.168.10.0/24"
|
||||
}
|
||||
}
|
||||
|
||||
vyos_network_interface_id = module.network_vyos.primary_network_interface_id
|
||||
vyos_security_group_id = module.network_vyos.security_group_id
|
||||
|
||||
|
||||
@@ -103,6 +103,16 @@ locals {
|
||||
cidr_ipv4 = "0.0.0.0/0"
|
||||
}
|
||||
},
|
||||
{
|
||||
for key, rule in var.web_egress_service_rules :
|
||||
"service_${key}" => {
|
||||
description = rule.description
|
||||
ip_protocol = rule.ip_protocol
|
||||
from_port = rule.port
|
||||
to_port = rule.port
|
||||
cidr_ipv4 = rule.cidr_ipv4
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
ssh_security_group_name = coalesce(var.ssh_security_group.name, "${var.name_prefix}-ssh-enabled")
|
||||
|
||||
@@ -123,6 +123,27 @@ variable "web_egress_policy" {
|
||||
}
|
||||
}
|
||||
|
||||
variable "web_egress_service_rules" {
|
||||
description = "Additional public-web egress rules for services on a single explicit destination CIDR."
|
||||
type = map(object({
|
||||
description = string
|
||||
ip_protocol = string
|
||||
port = number
|
||||
cidr_ipv4 = string
|
||||
}))
|
||||
|
||||
validation {
|
||||
condition = alltrue([
|
||||
for rule in values(var.web_egress_service_rules) :
|
||||
contains(["tcp", "udp"], rule.ip_protocol) &&
|
||||
rule.port >= 1 && rule.port <= 65535 && rule.port == floor(rule.port) &&
|
||||
trimspace(rule.description) != "" &&
|
||||
can(cidrnetmask(rule.cidr_ipv4))
|
||||
])
|
||||
error_message = "Every service egress rule must have a description, TCP or UDP protocol, an integer port from 1 through 65535, and a valid IPv4 CIDR."
|
||||
}
|
||||
}
|
||||
|
||||
variable "web_instance" {
|
||||
description = "Existing public web EC2 instance. user_data is intentionally absent."
|
||||
type = object({
|
||||
|
||||
@@ -46,6 +46,21 @@ module "network_public" {
|
||||
public_tcp_ports = [80, 443]
|
||||
}
|
||||
|
||||
web_egress_service_rules = {
|
||||
consul_serf_lan = {
|
||||
description = "Allow Consul Serf LAN gossip to the test service network"
|
||||
ip_protocol = "udp"
|
||||
port = 8301
|
||||
cidr_ipv4 = "203.0.113.0/24"
|
||||
}
|
||||
loki_ingest = {
|
||||
description = "Allow Loki ingest to the test service network"
|
||||
ip_protocol = "tcp"
|
||||
port = 3100
|
||||
cidr_ipv4 = "203.0.113.0/24"
|
||||
}
|
||||
}
|
||||
|
||||
vyos_network_interface_id = aws_network_interface.route_target.id
|
||||
vyos_security_group_id = aws_security_group.vyos_source.id
|
||||
|
||||
|
||||
@@ -15,12 +15,18 @@ output "vyos_source_security_group_ids" {
|
||||
}
|
||||
|
||||
output "web_egress_policy_matches" {
|
||||
value = length(module.network_public.web_egress_rule_specs) == 18 && alltrue([
|
||||
value = length(module.network_public.web_egress_rule_specs) == 20 && alltrue([
|
||||
for cidr in ["192.0.2.0/24", "198.51.100.0/24"] :
|
||||
toset([for rule in values(module.network_public.web_egress_rule_specs) : rule.from_port if rule.cidr_ipv4 == cidr && rule.ip_protocol == "tcp"]) == toset([3000, 3001, 8200, 8300, 8301, 9000, 25090]) &&
|
||||
toset([for rule in values(module.network_public.web_egress_rule_specs) : rule.from_port if rule.cidr_ipv4 == cidr && rule.ip_protocol == "udp"]) == toset([123])
|
||||
]) && toset([for rule in values(module.network_public.web_egress_rule_specs) : rule.from_port if rule.cidr_ipv4 == "0.0.0.0/0" && rule.ip_protocol == "tcp"]) == toset([80, 443]) && alltrue([
|
||||
for rule in values(module.network_public.web_egress_rule_specs) : rule.description != "" && rule.from_port == rule.to_port
|
||||
]) && toset([
|
||||
for key, rule in module.network_public.web_egress_rule_specs : "${key}|${rule.ip_protocol}|${rule.from_port}|${rule.cidr_ipv4}"
|
||||
if startswith(key, "service_")
|
||||
]) == toset([
|
||||
"service_consul_serf_lan|udp|8301|203.0.113.0/24",
|
||||
"service_loki_ingest|tcp|3100|203.0.113.0/24",
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ run "plan_network_group3_osaka" {
|
||||
|
||||
assert {
|
||||
condition = output.web_egress_policy_matches
|
||||
error_message = "The Osaka test must use the same 18 restricted egress rules as production."
|
||||
error_message = "The Osaka test must use the same 20-rule restricted egress structure as production."
|
||||
}
|
||||
|
||||
assert {
|
||||
|
||||
Reference in New Issue
Block a user