Skip to content

Commit

Permalink
fix: default network policy for admission webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lefevre <[email protected]>
  • Loading branch information
ArchiFleKs committed Sep 7, 2020
1 parent df5d17b commit 383e66c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions nginx-ingress.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ locals {
ingress_cidr = "0.0.0.0/0"
chart_version = "2.15.0"
version = "0.35.0"
allowed_cidrs = ["0.0.0.0/0"]
},
var.nginx_ingress
)
Expand Down Expand Up @@ -174,6 +175,42 @@ resource "kubernetes_network_policy" "nginx_ingress_allow_ingress" {
}
}

resource "kubernetes_network_policy" "nginx_ingress_allow_control_plane" {
count = local.nginx_ingress["enabled"] && local.nginx_ingress["default_network_policy"] ? 1 : 0

metadata {
name = "${kubernetes_namespace.nginx_ingress.*.metadata.0.name[count.index]}-allow-control-plane"
namespace = kubernetes_namespace.nginx_ingress.*.metadata.0.name[count.index]
}

spec {
pod_selector {
match_expressions {
key = "app.kubernetes.io/name"
operator = "In"
values = ["ingress-nginx"]
}
}

ingress {
ports {
port = "8443"
protocol = "TCP"
}

dynamic "from" {
for_each = local.nginx_ingress["allowed_cidrs"]
content {
ip_block {
cidr = from.value
}
}
}
}

policy_types = ["Ingress"]
}
}
output "nginx_ingress" {
value = map(
"name", local.nginx_ingress["name"],
Expand Down

0 comments on commit 383e66c

Please sign in to comment.