Skip to content

Commit b59a36b

Browse files
authored
fix: Add missing NSG rules for VCN-Native Pod Networking (#563)
Add missing NSG rules for VCN-Native Pod Networking Changed to reflect https://docs.oracle.com/en-us/iaas/Content/ContEng/Concepts/contengnetworkconfig.htm#securitylistconfig: * Moved `oci_core_network_security_group_security_rule.workers_egress_flannel` to CNI-agnostic `local.workers_egress` for node to node. * Added `oci_core_network_security_group_security_rule.workers_ingress_npn` for pod to worker. * Added `oci_core_network_security_group_security_rule.pods_ingress"` for CP to pod, worker to pod, and pod to pod (`local.pods_ingress` existed for them but was not yet referenced). * Added to TCP 6443 to `local.pods_egress` for pod to CP. * Updated `oci_core_network_security_group_security_rule.pods_egress_internet` from tcp -> all protocols. * Updated some NSG rule descriptions to clarify usage. * Added NPN conditional to `oci_core_network_security_group.pods`. Signed-off-by: Devon Crouse <devon.crouse@oracle.com>
1 parent a660d5f commit b59a36b

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

modules/network/locals.tf

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
locals {
5+
# VCN subnet configuration
6+
# See https://docs.oracle.com/en-us/iaas/Content/ContEng/Concepts/contengnetworkconfig.htm#vcnconfig
57

68
# first vcn cidr
79
# pick the first cidr block in the list as this is where we will create the oke subnets
@@ -54,9 +56,11 @@ locals {
5456
waf_subnet.cidr
5557
] : []
5658

59+
# Security configuration
60+
# See https://docs.oracle.com/en-us/iaas/Content/ContEng/Concepts/contengnetworkconfig.htm#securitylistconfig
5761
# if port = -1, allow all ports
5862

59-
#control plane seclist
63+
# Security List rules for control plane subnet (Flannel & VCN-Native Pod networking)
6064
cp_egress_seclist = [
6165
{
6266
description = "Allow Bastion service to communicate to the control plane endpoint. Required for when using OCI Bastion service.",
@@ -78,7 +82,8 @@ locals {
7882
stateless = false
7983
}
8084
]
81-
# control plane
85+
86+
# Network Security Group egress rules for control plane subnet (Flannel & VCN-Native Pod networking)
8287
cp_egress = [
8388
{
8489
description = "Allow Kubernetes Control plane to communicate to the control plane subnet. Required for when using OCI Bastion service.",
@@ -114,6 +119,7 @@ locals {
114119
},
115120
]
116121

122+
# Network Security Group ingress rules for control plane subnet (Flannel & VCN-Native Pod networking)
117123
cp_ingress = [
118124
{
119125
description = "Allow worker nodes to control plane API endpoint communication"
@@ -149,8 +155,16 @@ locals {
149155
},
150156
]
151157

152-
# workers
158+
# Network Security Group egress rules for workers subnet (Flannel & VCN-Native Pod networking)
153159
workers_egress = [
160+
{
161+
description = "Allows communication from (or to) worker nodes.",
162+
destination = local.workers_subnet
163+
destination_type = "CIDR_BLOCK",
164+
protocol = local.all_protocols,
165+
port = -1,
166+
stateless = false
167+
},
154168
{
155169
description = "Allow ICMP traffic for path discovery",
156170
destination = local.anywhere
@@ -185,6 +199,7 @@ locals {
185199
}
186200
]
187201

202+
# Network Security Group ingress rules for workers subnet (Flannel & VCN-Native Pod networking)
188203
workers_ingress = [
189204
{
190205
description = "Allow ingress for all traffic to allow pods to communicate between each other on different worker nodes on the worker subnet",
@@ -213,6 +228,7 @@ locals {
213228
}
214229
]
215230

231+
# Network Security Group egress rules for pods subnet (VCN-Native Pod networking only)
216232
pods_egress = [
217233
{
218234
description = "Allow pods to communicate with other pods.",
@@ -238,19 +254,28 @@ locals {
238254
port = -1,
239255
stateless = false
240256
},
257+
{
258+
description = "Allow pods to communicate with Kubernetes API server",
259+
destination = local.cp_subnet,
260+
destination_type = "CIDR_BLOCK",
261+
protocol = local.tcp_protocol,
262+
port = 6443,
263+
stateless = false
264+
}
241265
]
242266

267+
# Network Security Group ingress rules for pods subnet (VCN-Native Pod networking only)
243268
pods_ingress = [
244269
{
245-
description = "Allow worker nodes to access pods.",
270+
description = "Allow Kubernetes control plane to communicate with webhooks served by pods",
246271
protocol = local.all_protocols,
247272
port = -1,
248273
source = local.cp_subnet,
249274
source_type = "CIDR_BLOCK",
250275
stateless = false
251276
},
252277
{
253-
description = "Allow Kubernetes Control Plane to communicate with pods.",
278+
description = "Allow cross-node pod communication when using NodePorts or hostNetwork: true",
254279
protocol = local.all_protocols,
255280
port = -1,
256281
source = local.workers_subnet,
@@ -267,6 +292,7 @@ locals {
267292
},
268293
]
269294

295+
# Network Security Group rules for load balancer subnet
270296
int_lb_egress = [
271297
{
272298
description = "Allow stateful egress to workers. Required for NodePorts",

modules/network/nsgs.tf

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,6 @@ resource "oci_core_network_security_group_security_rule" "workers_egress" {
149149
count = length(local.workers_egress)
150150
}
151151

152-
resource "oci_core_network_security_group_security_rule" "workers_egress_flannel" {
153-
network_security_group_id = oci_core_network_security_group.workers.id
154-
description = "Allow egress for all traffic to allow pods to communicate between each other on different worker nodes on the worker subnet"
155-
destination = local.workers_subnet
156-
destination_type = "CIDR_BLOCK"
157-
direction = "EGRESS"
158-
protocol = local.all_protocols
159-
160-
stateless = false
161-
162-
count = var.cni_type == "flannel" ? 1: 0
163-
}
164-
165152
resource "oci_core_network_security_group_security_rule" "workers_egress_npn" {
166153
network_security_group_id = oci_core_network_security_group.workers.id
167154
description = "Allow worker nodes access to pods"
@@ -307,6 +294,17 @@ resource "oci_core_network_security_group_security_rule" "workers_healthcheck_in
307294

308295
}
309296

297+
resource "oci_core_network_security_group_security_rule" "workers_ingress_npn" {
298+
network_security_group_id = oci_core_network_security_group.workers.id
299+
description = "Allow cross-node pod communication when using NodePorts or hostNetwork: true"
300+
direction = "INGRESS"
301+
protocol = local.all_protocols
302+
source = local.pods_subnet
303+
source_type = "CIDR_BLOCK"
304+
stateless = false
305+
count = var.cni_type == "npn" ? 1 : 0
306+
}
307+
310308
resource "oci_core_network_security_group_security_rule" "workers_ssh_ingress_from_bastion" {
311309
network_security_group_id = oci_core_network_security_group.workers.id
312310
description = "Allow ssh access to workers via Bastion host"
@@ -333,6 +331,7 @@ resource "oci_core_network_security_group" "pods" {
333331
compartment_id = var.compartment_id
334332
display_name = var.label_prefix == "none" ? "pods" : "${var.label_prefix}-pods"
335333
vcn_id = var.vcn_id
334+
count = var.cni_type == "npn" ? 1 : 0
336335
}
337336

338337
resource "oci_core_network_security_group_security_rule" "pods_egress" {
@@ -366,14 +365,25 @@ resource "oci_core_network_security_group_security_rule" "pods_egress" {
366365
count = var.cni_type =="npn" ? length(local.pods_egress) : 0
367366
}
368367

368+
resource "oci_core_network_security_group_security_rule" "pods_ingress" {
369+
network_security_group_id = oci_core_network_security_group.pods.id
370+
description = local.pods_ingress[count.index].description
371+
source = local.pods_ingress[count.index].source
372+
source_type = local.pods_ingress[count.index].source_type
373+
protocol = local.pods_ingress[count.index].protocol
374+
direction = "INGRESS"
375+
stateless = false
376+
count = var.cni_type =="npn" ? length(local.pods_ingress) : 0
377+
}
378+
369379
# add this rule separately so it can be controlled independently
370380
resource "oci_core_network_security_group_security_rule" "pods_egress_internet" {
371381
network_security_group_id = oci_core_network_security_group.pods.id
372382
description = "Allow pods access to Internet"
373383
destination = local.anywhere
374384
destination_type = "CIDR_BLOCK"
375385
direction = "EGRESS"
376-
protocol = local.tcp_protocol
386+
protocol = local.all_protocols
377387

378388
stateless = false
379389
count = (var.cni_type =="npn" && var.allow_pod_internet_access == true) ? 1 : 0

0 commit comments

Comments
 (0)