Skip to content

Commit e1cf42f

Browse files
authored
Merge pull request #72 from hcloud-k8s/firewall-api
Enhance firewall configuration to support custom API source networks
2 parents 7bd05a3 + 81b8978 commit e1cf42f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

firewall.tf

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
locals {
2+
firewall_kube_api_source = (
3+
var.firewall_kube_api_source != null ?
4+
var.firewall_kube_api_source :
5+
var.firewall_api_source
6+
)
7+
firewall_talos_api_source = (
8+
var.firewall_talos_api_source != null ?
9+
var.firewall_talos_api_source :
10+
var.firewall_api_source
11+
)
212
firewall_use_current_ipv4 = local.network_public_ipv4_enabled && coalesce(
313
var.firewall_use_current_ipv4,
4-
var.cluster_access == "public" && var.firewall_kube_api_source == null && var.firewall_talos_api_source == null
14+
var.cluster_access == "public" && local.firewall_kube_api_source == null && local.firewall_talos_api_source == null
515
)
616
firewall_use_current_ipv6 = local.network_public_ipv6_enabled && coalesce(
717
var.firewall_use_current_ipv6,
8-
var.cluster_access == "public" && var.firewall_kube_api_source == null && var.firewall_talos_api_source == null
18+
var.cluster_access == "public" && local.firewall_kube_api_source == null && local.firewall_talos_api_source == null
919
)
1020

1121
current_ip = concat(
@@ -18,20 +28,20 @@ locals {
1828
)
1929

2030
firewall_default_rules = concat(
21-
var.firewall_kube_api_source != null || length(local.current_ip) > 0 ? [
31+
local.firewall_kube_api_source != null || length(local.current_ip) > 0 ? [
2232
{
2333
description = "Allow Incoming Requests to Kube API"
2434
direction = "in"
25-
source_ips = coalesce(var.firewall_kube_api_source, local.current_ip)
35+
source_ips = coalesce(local.firewall_kube_api_source, local.current_ip)
2636
protocol = "tcp"
2737
port = local.kube_api_port
2838
}
2939
] : [],
30-
var.firewall_talos_api_source != null || length(local.current_ip) > 0 ? [
40+
local.firewall_talos_api_source != null || length(local.current_ip) > 0 ? [
3141
{
3242
description = "Allow Incoming Requests to Talos API"
3343
direction = "in"
34-
source_ips = coalesce(var.firewall_talos_api_source, local.current_ip)
44+
source_ips = coalesce(local.firewall_talos_api_source, local.current_ip)
3545
protocol = "tcp"
3646
port = local.talos_api_port
3747
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ variable "firewall_extra_rules" {
207207
}
208208
}
209209

210+
variable "firewall_api_source" {
211+
type = list(string)
212+
default = null
213+
description = "Source networks that have access to Kube and Talos API. If set, this overrides the firewall_use_current_ipv4 and firewall_use_current_ipv6 settings."
214+
}
215+
210216
variable "firewall_kube_api_source" {
211217
type = list(string)
212218
default = null

0 commit comments

Comments
 (0)