2018-08-20 03:48:22 +02:00
|
|
|
# Controller security group
|
|
|
|
|
|
|
|
resource "azurerm_network_security_group" "controller" {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "${var.cluster_name}-controller"
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2024-07-06 02:21:50 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-icmp" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-icmp-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 1995 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Icmp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-ssh" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-ssh-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2000 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
|
|
|
source_address_prefix = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "controller-etcd" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-etcd-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2005 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "2379-2380"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.controller_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allow Prometheus to scrape etcd metrics
|
|
|
|
resource "azurerm_network_security_rule" "controller-etcd-metrics" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-etcd-metrics-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2010 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "2381"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-29 21:21:49 +01:00
|
|
|
# Allow Prometheus to scrape kube-proxy metrics
|
|
|
|
resource "azurerm_network_security_rule" "controller-kube-proxy" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2019-12-29 21:21:49 +01:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-kube-proxy-metrics-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2012 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10249"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2019-12-29 21:21:49 +01:00
|
|
|
}
|
|
|
|
|
2019-09-06 08:12:09 +02:00
|
|
|
# Allow Prometheus to scrape kube-scheduler and kube-controller-manager metrics
|
|
|
|
resource "azurerm_network_security_rule" "controller-kube-metrics" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2019-09-06 08:12:09 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-kube-metrics-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2014 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10257-10259"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2019-09-06 08:12:09 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-apiserver" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-apiserver-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2016 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "6443"
|
|
|
|
source_address_prefix = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-cilium-health" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = var.networking == "cilium" ? local.controller_subnets : {}
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-cilium-health-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2018 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "4240"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2024-05-13 17:38:36 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-cilium-metrics" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = var.networking == "cilium" ? local.controller_subnets : {}
|
2024-05-13 17:38:36 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-cilium-metrics-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2024-05-13 17:38:36 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2035 + (each.key == "ipv4" ? 0 : 1)
|
2024-05-13 17:38:36 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9962-9965"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2024-05-13 17:38:36 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-vxlan" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-vxlan-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2020 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "4789"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-linux-vxlan" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-linux-vxlan-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2022 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "8472"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Allow Prometheus to scrape node-exporter daemonset
|
|
|
|
resource "azurerm_network_security_rule" "controller-node-exporter" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-node-exporter-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2025 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9100"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allow apiserver to access kubelet's for exec, log, port-forward
|
|
|
|
resource "azurerm_network_security_rule" "controller-kubelet" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.controller_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-kubelet-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2030 + (each.key == "ipv4" ? 0 : 1)
|
2018-08-20 03:48:22 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10250"
|
|
|
|
# allow Prometheus to scrape kubelet metrics too
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.controller_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Override Azure AllowVNetInBound and AllowAzureLoadBalancerInBound
|
|
|
|
# https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#default-security-rules
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "controller-allow-loadblancer" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "allow-loadbalancer"
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2018-08-20 03:48:22 +02:00
|
|
|
priority = "3000"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
|
|
|
source_address_prefix = "AzureLoadBalancer"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "controller-deny-all" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "deny-all"
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2018-08-20 03:48:22 +02:00
|
|
|
priority = "3005"
|
|
|
|
access = "Deny"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
|
|
|
source_address_prefix = "*"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Worker security group
|
|
|
|
|
|
|
|
resource "azurerm_network_security_group" "worker" {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "${var.cluster_name}-worker"
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2024-07-06 02:21:50 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-icmp" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-icmp-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 1995 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Icmp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-ssh" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-ssh-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2000 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.controller_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-http" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-http-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2005 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "80"
|
|
|
|
source_address_prefix = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-https" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-https-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2010 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "443"
|
|
|
|
source_address_prefix = "*"
|
2024-07-06 02:21:50 +02:00
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-cilium-health" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = var.networking == "cilium" ? local.worker_subnets : {}
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-cilium-health-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2012 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "4240"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2024-05-13 17:38:36 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-cilium-metrics" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = var.networking == "cilium" ? local.worker_subnets : {}
|
2024-05-13 17:38:36 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-cilium-metrics-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2024-05-13 17:38:36 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2014 + (each.key == "ipv4" ? 0 : 1)
|
2024-05-13 17:38:36 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9962-9965"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2024-05-13 17:38:36 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-vxlan" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-vxlan-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2016 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "4789"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-16 07:42:57 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-linux-vxlan" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2020-06-16 07:42:57 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-linux-vxlan-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2018 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "8472"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2020-06-16 07:42:57 +02:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Allow Prometheus to scrape node-exporter daemonset
|
|
|
|
resource "azurerm_network_security_rule" "worker-node-exporter" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-node-exporter-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2020 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9100"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2019-12-29 21:21:49 +01:00
|
|
|
# Allow Prometheus to scrape kube-proxy
|
|
|
|
resource "azurerm_network_security_rule" "worker-kube-proxy" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2019-12-29 21:21:49 +01:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-kube-proxy-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2022-04-02 01:17:54 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2024 + (each.key == "ipv4" ? 0 : 1)
|
2022-04-02 01:17:54 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10249"
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.worker_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2019-12-29 21:21:49 +01:00
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Allow apiserver to access kubelet's for exec, log, port-forward
|
|
|
|
resource "azurerm_network_security_rule" "worker-kubelet" {
|
2024-07-06 02:21:50 +02:00
|
|
|
for_each = local.worker_subnets
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
name = "allow-kubelet-${each.key}"
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2024-07-06 02:21:50 +02:00
|
|
|
priority = 2026 + (each.key == "ipv4" ? 0 : 1)
|
2018-08-20 03:48:22 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10250"
|
|
|
|
# allow Prometheus to scrape kubelet metrics too
|
2024-07-06 02:21:50 +02:00
|
|
|
source_address_prefixes = local.cluster_subnets[each.key]
|
|
|
|
destination_address_prefixes = local.worker_subnets[each.key]
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Override Azure AllowVNetInBound and AllowAzureLoadBalancerInBound
|
|
|
|
# https://docs.microsoft.com/en-us/azure/virtual-network/security-overview#default-security-rules
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-allow-loadblancer" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "allow-loadbalancer"
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2018-08-20 03:48:22 +02:00
|
|
|
priority = "3000"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
|
|
|
source_address_prefix = "AzureLoadBalancer"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-deny-all" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
name = "deny-all"
|
2019-05-28 06:43:08 +02:00
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
2018-08-20 03:48:22 +02:00
|
|
|
priority = "3005"
|
|
|
|
access = "Deny"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "*"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "*"
|
|
|
|
source_address_prefix = "*"
|
|
|
|
destination_address_prefix = "*"
|
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|