2018-08-20 03:48:22 +02:00
|
|
|
# Controller security group
|
|
|
|
|
|
|
|
resource "azurerm_network_security_group" "controller" {
|
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 = "${var.cluster_name}-controller"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "controller-ssh" {
|
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-ssh"
|
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 = "2000"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
|
|
|
source_address_prefix = "*"
|
2019-05-28 06:43:08 +02:00
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "controller-etcd" {
|
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-etcd"
|
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 = "2005"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "2379-2380"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefix = azurerm_subnet.controller.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allow Prometheus to scrape etcd metrics
|
|
|
|
resource "azurerm_network_security_rule" "controller-etcd-metrics" {
|
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-etcd-metrics"
|
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 = "2010"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "2381"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
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" {
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
|
|
|
|
|
|
|
name = "allow-kube-proxy-metrics"
|
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
|
|
|
priority = "2011"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10249"
|
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
|
|
|
}
|
|
|
|
|
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" {
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
|
|
|
|
|
|
|
name = "allow-kube-metrics"
|
|
|
|
network_security_group_name = azurerm_network_security_group.controller.name
|
2019-12-29 21:21:49 +01:00
|
|
|
priority = "2012"
|
2019-09-06 08:12:09 +02:00
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10251-10252"
|
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-apiserver" {
|
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-apiserver"
|
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 = "2015"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "6443"
|
|
|
|
source_address_prefix = "*"
|
2019-05-28 06:43:08 +02:00
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
resource "azurerm_network_security_rule" "controller-vxlan" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
name = "allow-vxlan"
|
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 = "2020"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
2019-05-07 06:56:38 +02:00
|
|
|
destination_port_range = "4789"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefixes = [azurerm_subnet.controller.address_prefix, azurerm_subnet.worker.address_prefix]
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allow Prometheus to scrape node-exporter daemonset
|
|
|
|
resource "azurerm_network_security_rule" "controller-node-exporter" {
|
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-node-exporter"
|
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 = "2025"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9100"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
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" {
|
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-kubelet"
|
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 = "2030"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10250"
|
|
|
|
|
|
|
|
# allow Prometheus to scrape kubelet metrics too
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefixes = [azurerm_subnet.controller.address_prefix, azurerm_subnet.worker.address_prefix]
|
|
|
|
destination_address_prefix = azurerm_subnet.controller.address_prefix
|
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" {
|
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 = "${var.cluster_name}-worker"
|
2019-05-28 06:43:08 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-ssh" {
|
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-ssh"
|
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 = "2000"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "22"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefix = azurerm_subnet.controller.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-http" {
|
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-http"
|
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 = "2005"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "80"
|
|
|
|
source_address_prefix = "*"
|
2019-05-28 06:43:08 +02:00
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_network_security_rule" "worker-https" {
|
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-https"
|
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 = "2010"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "443"
|
|
|
|
source_address_prefix = "*"
|
2019-05-28 06:43:08 +02:00
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
resource "azurerm_network_security_rule" "worker-vxlan" {
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2018-08-20 03:48:22 +02:00
|
|
|
|
2019-05-07 06:56:38 +02:00
|
|
|
name = "allow-vxlan"
|
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 = "2015"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Udp"
|
|
|
|
source_port_range = "*"
|
2019-05-07 06:56:38 +02:00
|
|
|
destination_port_range = "4789"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefixes = [azurerm_subnet.controller.address_prefix, azurerm_subnet.worker.address_prefix]
|
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Allow Prometheus to scrape node-exporter daemonset
|
|
|
|
resource "azurerm_network_security_rule" "worker-node-exporter" {
|
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-node-exporter"
|
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 = "2020"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "9100"
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
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" {
|
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
|
|
|
|
|
|
|
name = "allow-kube-proxy"
|
|
|
|
network_security_group_name = azurerm_network_security_group.worker.name
|
|
|
|
priority = "2024"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10249"
|
|
|
|
source_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
|
|
|
}
|
|
|
|
|
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" {
|
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-kubelet"
|
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 = "2025"
|
|
|
|
access = "Allow"
|
|
|
|
direction = "Inbound"
|
|
|
|
protocol = "Tcp"
|
|
|
|
source_port_range = "*"
|
|
|
|
destination_port_range = "10250"
|
|
|
|
|
|
|
|
# allow Prometheus to scrape kubelet metrics too
|
2019-05-28 06:43:08 +02:00
|
|
|
source_address_prefixes = [azurerm_subnet.controller.address_prefix, azurerm_subnet.worker.address_prefix]
|
|
|
|
destination_address_prefix = azurerm_subnet.worker.address_prefix
|
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
|
|
|
|