Security hardening enhancements for Kubernetes

RuncyOommen 133 views 46 slides Aug 19, 2024
Slide 1
Slide 1 of 46
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46

About This Presentation

The default security settings of a Kubernetes deployment is not hardened and fine tuned for security. Let's walk through what enhancements and config changes can be done to make it robust and ready for production.


Slide Content

Kubernetes Security Hardening

01 C loud native security intro 02 Shared responsibility model The next 30 mins... 04  K ubernetes security improvements 03 Journey from VMs to Microservices

Engineering Leader with 2 decades of primary exp in systems, cloud, security, networking Special interest in serverless, containers and cloud-native offerings. Firm believer of a multi-hybrid cloud future Career Community Organizer of GDG Cloud; Former co-organizer of AWS UG Bangalore Google Developer Expert (GDE) in cloud Multiple hackathon wins in cloud/security topics Recognized by Google as a community influencer runcyoommen https://runcy.me

What being “Cloud Native” means ? A cloud computing approach to build & run scalable apps in modern environments such as public, private and hybrid clouds . Technologies such as containers, microservices and serverless are elements of this architecture. Reference: https://en.wikipedia.org/wiki/Cloud_native_computing

So, how exactly should cloud native security differ from traditional network security ?

Cloud Features v/s Security Balances Agility Self service Scale Automation Gatekeeper Standards Control Centralized Pay as you go Timely alerts

Shared Responsibility Model

MONOLITH M-I-C-R-O-S-E-R-V-I-C-E-S Let’s begin the journey… f rom to

VM Container

Portability – A bstract apps from host ; easy to run on any platform Scalability – Containerized apps can handle increasing workload Security – App isolation ensures separate containers run independently Continuity – Failure of one will not influence the state of others Easy Management – Performs orchestration, workload management, automated installation

How did we get here?

LET'S FIX THE BREAKING K8s

Ensure each container has a configured... Hardening #1 Memory request & limit​ CPU request & limit Liveness probe Readiness probe​

Overview of hardening Mem requests allocate guaranteed memory to pods in the cluster Mem limits restrict max memory resources to pods in the cluster Memory requests & limits CPU requests enable guaranteed computing to pods in the cluster CPU limits restrict max computing resources to pods in the cluster CPU requests & limits Liveness probe determines when a pod should be replaced (resiliency) Readiness probe determines when a pod is ready to accept traffic Liveness & Readiness probe

Remediation Set memory requests & limits Set CPU requests & limits

Remediation Configure liveness probe with HTTP req, TCP protocol or exec command Configure readiness probe with HTTP req, TCP protocol or exec command

Hardening #2 Prevent deploying naked pods

Overview of hardening It's preferable to manage services and applications using higher-level resources like Deployments, StatefulSets and DaemonSets instead of raw Pod resources These are necessary to configure & maintain a stable cluster

Remediation Deploy pods using higher-level resources

Use images only with... Hardening #3 Pinned (tag) version​ Digest (checksum)

Overview of hardening When an image tag is not descriptive, every time that image is pulled, version will be different and might break your code Non-descriptive image tag does not allow to easily roll back to different image version​

Remediation Each container image should have a pinned version tag or image ID

Prevent containers from... Hardening #4 Accessing underlying host Allowing command execution Escalating privileges Running with root privileges

Overview of hardening Pods can use host bind mounts ( dirs and vols mounted on container host) Using hostPath may enable to break from container and gain host access Prevent access to underlying host As an example ' kubectl exec' allows to execute a command in container Prevent command execution Containers allow privilege escalation by default Attackers may utilise this to manipulate app or process Prevent privilege escalation Having non-root execution provides better assurance that apps will function correctly without root privileges Recommended to run with least privileges possible Prevent running with root

Remediation Refrain from using hostPath mount Refrain from setting exec, create in your Role

Remediation Set the allowPrivilegeEscalation to false Set runAsNonRoot to true

Configure HPA with... Hardening #5 Minimum replicas Maximum replicas

Overview of hardening When auto-scaling resource utilization is triggered with Horizontal Pod Autoscaler , acceptable values must be set to prevent unintended scale HPA doesn't have min replicas HPA doesn't have max replicas

Remediation Configure HPA with minReplicas and maxReplicas value

CronJob has... Hardening #6 Deadline configured Concurrent execution forbidden

Overview of hardening By default, cron job allows concurrently running jobs, but would be more deterministic if prevented Allowing concurrency requires locking to avoid race conditions When CronJob controller miss more than 100, job is no longer scheduled Counts how many missed schedules since lastScheduleTime

Remediation Set deadline to reduce number of missed schedules and increase CronJob reliability Set concurrencyPolicy to either Forbid or Replace

runcyoommen https://runcy.me