Slide 1

Slide 1 text

From Squire to Network Knight Defending the Kubernetes Castle the Cloud Native Way Donia Chaiehloudj SW Engineer and Community, Isovalent @Cisco

Slide 2

Slide 2 text

The Wide-Open Castle 0 Security in Kubernetes Cluster

Slide 3

Slide 3 text

Firewalls Controls accesses... External: Ingress traffic to the target machine Internal: between machines on your server

Slide 4

Slide 4 text

Perimeter Firewalls Why Old Defenses Fail in Kubernetes Cluster Dynamic: pods come and go, IPs change East–west traffic dominates Multi-tenant workloads make static rules useless

Slide 5

Slide 5 text

Level 0: No Network Policy Network Squire, eager but... Tuntrained apprentice, running around the open castle with no armor.

Slide 6

Slide 6 text

Organise your Kubernetes Castle ... Before routing traffic Think class of workloads AI workoads Frontend Backend UI Databases

Slide 7

Slide 7 text

Organise your Kubernetes Castle ... Before routing traffic Think class of workloads AI workoads Frontend Backend UI Databases Separate resources logically per namespace

Slide 8

Slide 8 text

Organise your Kubernetes Castle ... Before routing traffic Think class of workloads AI workoads Frontend Backend UI Databases Separate resources logically per namespace Label your resources in thoughtful way

Slide 9

Slide 9 text

NetworkPolicies: The Cloud Native way Securing and routing the entrances... Define network rules as code instead of cables apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend namespace: castle The Royal Decree: What This Is

Slide 10

Slide 10 text

NetworkPolicies: The Cloud Native way Securing and routing the entrances... apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend namespace: castle spec: podSelector: matchLabels: role: backend policyTypes: - Ingress The Royal Decree: What This Is The Assignment of Guards: Who and What Direction Define network rules as code instead of cables

Slide 11

Slide 11 text

NetworkPolicies: The Cloud Native way Securing and routing the entrances... apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend namespace: castle spec: podSelector: matchLabels: role: backend policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: role: frontend ports: - protocol: TCP port: 8080 The Royal Decree: What This Is The Assignment of Guards: Who and What Direction The Guest List: Who May Enter and How Define network rules as code instead of cables

Slide 12

Slide 12 text

NetworkPolicies: The Cloud Native way apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend-policy namespace: castle spec: podSelector: matchLabels: role: backend policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: role: frontend ports: - protocol: TCP port: 8080 Kubernetes Network Policy Example Front Back External App

Slide 13

Slide 13 text

The L3/L4 Gatekeer learns to close the gates and set basic rules. Level 0: No Network Policy Level 1: Kubernetes Network Policy

Slide 14

Slide 14 text

Core CNIs Multi-Network & Cloud Lightweight & Legacy Cilium – eBPF-based networking, security & observability Multus – Multiple CNIs per pod (Calico, Cilium, SR-IOV…) Weave Net – Simple, self-healing overlay with policy Calico – Flexible overlay/BGP networking with policies Canal – Flannel networking + Calico policy Flannel – Basic overlay network for pod connectivity Antrea – OVS-based networking & NetworkPolicy Cloud CNIs – Native VPC networking (AWS, Azure, GCP, Terway) OVN-Kubernetes – OVS/OVN overlay & load balancing Enterprise CNIs – SDN integration (NSX-T, ACI) NetworkPolicies: The Cloud Native way Go Beyond with Container Network Interface Plugins

Slide 15

Slide 15 text

Cilium: Leveling Up Your Armor CNI = a modern firewall

Slide 16

Slide 16 text

src: https://isovalent.com/blog/post/intro-to-cilium-network-policies/ NetworkPolicies: The Cloud Native way Go Beyond with Container Network Interface Plugins

Slide 17

Slide 17 text

Cilium: Leveling Up Your Armor Identity is your strength

Slide 18

Slide 18 text

Cilium: Select on Endpoint Prevent from invaders... Deny All role = queen role = assistant role = invader

Slide 19

Slide 19 text

Cilium: Select on Endpoint Prevent from invaders... Deny All role = queen role = assistant role = invader

Slide 20

Slide 20 text

Cilium: Select on Endpoint apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: default-deny-all namespace: app spec: endpointSelector: {} ingress: [] Prevent from invaders... Deny All External App frontend pods backend pods

Slide 21

Slide 21 text

Cilium: Select on Endpoint Let the fighters join the battle! .... But keep the Queen inaccessible role = queen role = assistant role = fighter

Slide 22

Slide 22 text

Cilium: Select on Endpoint apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: "allow-frontend-backend" spec: endpointSelector: matchLabels: role: "backend" ingress: - fromEndpoints: - matchLabels: role: "frontend" Let the fighters join the battle! .... But keep the Queen inaccessible External App frontend pods backend pods

Slide 23

Slide 23 text

Cilium: L4 Filtering on TCP Protocol Guard at the doors apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: "l4-rule" spec: endpointSelector: matchLabels: role: frontend egress: - toPorts: - ports: - port: "443" protocol: TCP frontend pods backend pods :443

Slide 24

Slide 24 text

Cilium: L7 Filtering on HTTP ... Be more speficic role = queen role = assistant GET /letters role = queen role = assistant GET /queen role = queen role = assistant PUT /letters

Slide 25

Slide 25 text

Cilium: L7 Filtering on HTTP Route with Egress Allow apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: frontend-egress-policy namespace: castle spec: endpointSelector: matchLabels: role: frontend egress: - toEndpoints: - matchLabels: role: backend toPorts: - ports: - port: "8080" protocol: TCP rules: http: - method: "GET" path: "^/letters$" - method: "PUT" path: "^/letters$" role=frontend GET /letters role=backend backend pod frontend pod PUT /letters backend pod frontend pod GET /queen backend pod frontend pod

Slide 26

Slide 26 text

Cilium: L7 Filtering on HTTP Protect with Ingress Policy role=frontend GET /letters role=backend backend pod frontend pod PUT /letters backend pod frontend pod GET /queen backend pod frontend pod apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-ingress-policy namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - fromEndpoints: - matchLabels: role: frontend toPorts: - ports: - port: "8080" protocol: TCP rules: http: - method: "GET" path: "^/letters$" - method: "PUT" path: "^/letters$"

Slide 27

Slide 27 text

Cilium: L7 Filtering per DNS The Queen, the Messenger - Fetch the Doctor Address role = messenger role = queen Fetch the doctor Fetch Doctor Address

Slide 28

Slide 28 text

Cilium: L7 Filtering per DNS The Queen, the Messenger - Fetch the Doctor Address role = messenger role = queen Fetch the doctor Doctor Address Doctor Address Fetch Doctor Address

Slide 29

Slide 29 text

Fetch Doctor Cilium: L7 Filtering per DNS The Queen, the Messenger - Fetch the Doctor role = messenger role = queen External Doctor

Slide 30

Slide 30 text

Cilium: L7 Filtering per DNS The Queen, the Messenger role=backend backend pod kube-dns pod apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-egress-fqdn namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - toEndpoints: - matchLabels: "k8s:io.kubernetes.pod.namespace": kube-system "k8s:k8s-app": kube-dns toPorts: - ports: - port: "53" protocol: ANY rules: dns: - matchPattern: "*" - toFQDNs: - matchPattern: "betterhelp.com" toPorts: - ports: - port: "443" protocol: TCP

Slide 31

Slide 31 text

Cilium: L7 Filtering per DNS The Queen, the Messenger Fetch Doctor Address role=backend backend pod kube-dns pod https://betterhelp.com apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-egress-fqdn namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - toEndpoints: - matchLabels: "k8s:io.kubernetes.pod.namespace": kube-system "k8s:k8s-app": kube-dns toPorts: - ports: - port: "53" protocol: ANY rules: dns: - matchPattern: "*" - toFQDNs: - matchPattern: "betterhelp.com" toPorts: - ports: - port: "443" protocol: TCP

Slide 32

Slide 32 text

Cilium: L7 Filtering per DNS The Queen, the Messenger Fetch Doctor Address External DNS role=backend backend pod kube-dns pod https://betterhelp.com https://betterhelp.com {https://betterhelp.com: 192.168.10.2} apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-egress-fqdn namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - toEndpoints: - matchLabels: "k8s:io.kubernetes.pod.namespace": kube-system "k8s:k8s-app": kube-dns toPorts: - ports: - port: "53" protocol: ANY rules: dns: - matchPattern: "*" - toFQDNs: - matchPattern: "betterhelp.com" toPorts: - ports: - port: "443" protocol: TCP

Slide 33

Slide 33 text

Cilium: L7 Filtering per DNS The Queen, the Messenger Fetch Doctor Address External DNS 192.168.10.2 role=backend backend pod kube-dns pod https://betterhelp.com 192.168.10.2 https://betterhelp.com {https://betterhelp.com: 192.168.10.2} apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-egress-fqdn namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - toEndpoints: - matchLabels: "k8s:io.kubernetes.pod.namespace": kube-system "k8s:k8s-app": kube-dns toPorts: - ports: - port: "53" protocol: ANY rules: dns: - matchPattern: "*" - toFQDNs: - matchPattern: "betterhelp.com" toPorts: - ports: - port: "443" protocol: TCP

Slide 34

Slide 34 text

Cilium: L7 Filtering per DNS The Queen, the Messenger role=backend kube-dns pod backend pod https://betterhelp.com apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: backend-egress-fqdn namespace: castle spec: endpointSelector: matchLabels: role: backend egress: - toEndpoints: - matchLabels: "k8s:io.kubernetes.pod.namespace": kube-system "k8s:k8s-app": kube-dns toPorts: - ports: - port: "53" protocol: ANY rules: dns: - matchPattern: "*" - toFQDNs: - matchPattern: "betterhelp.com" toPorts: - ports: - port: "443" protocol: TCP

Slide 35

Slide 35 text

Queen Pod King Pod Cilium: Namespaces organisation CiliumClusterwideNetworkPolicy Castle Cluster Namespace Royalty Namespace Messenger Messenger Pods CNP CCNP CNP

Slide 36

Slide 36 text

Cilium: Namespaces organisation CiliumClusterwideNetworkPolicy

Slide 37

Slide 37 text

Level 0: No Network Policy Level 1: Kubernetes Network Policy Level 2: Cilium Network Policy Network Knight, the fully trained defender ...using intelligence to keep the kingdom safe.

Slide 38

Slide 38 text

🏰 The Tenets of the Network Knight Principles to Remember... 1️⃣ Thou Shalt Protect Every Pod in Thy Realm Every Pod must be covered by a Network Policy, lest open paths invite unwanted guests. 2️⃣ Thou Shalt Be Precise in Thy Rules A careless label may open the gates to the wrong visitors. 3️⃣ Thou Shalt Deny by Default and Grant by Grace The stronghold stands firm when trust is earned, not assumed. 4️⃣ Thou Shalt Keep Watch and Update Thy Defenses Review thy policies often, for what was safe yesterday may be perilous today. 5️⃣ Thou Shalt Test Thy Defenses with Thine Own Hand Verify each rule and path, that thy guards are not asleep at their post.

Slide 39

Slide 39 text

@doniacld ebpf.io @ciliumproject @isovalent Resources and Credits Feedback is a gift! Special Thanks 🙏 https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy/ https:/isovalent.com/blog/post/intro-to-cilium-network-policies/