SlideShare a Scribd company logo
K8S security – Best practices
By: Sharon Vendrov
0
500
1000
1500
2000
2500
Mac Os X Windows 7 Windows XP Windows 8.1 Windows 10
CVE Sum
CVE Sum
2
Total Number Of Vulnerabilities in 2017 – Source:
CVEdetails.com
3
4
Sharon Vendrov
Sr. DevOps Engineer
About Me
5
Storm-runner functional
 Infrastructure protection
 K8s internal security
 Authentication & Authorization options
 Network
 Secrets
 Container runtime Security
 Some other security tools and considerations
6
Agenda
Infrastructure protection
7
 Limit SSH access to your cluster
 Use hardened images for your cluster ( )
 Encrypt your storage volume
 Avoid from exposing your cluster to the internet
 Limit the access to the K8s API (consider to use bastion machine)
 Create dedicated cluster for each environment (Prod, Stg, Dev)
 Separate sensitive pods into different nodes
Kubernetes internal security
8
 Use minimal base docker image
 Don’t use arbitrary base images
 Separate sensitive workloads across instances (using anti-affinity,
taints and tolerations)
 Use namespaces for isolation
 Enforce resource quota (CPU, Memory, Storage)
Image Name node:latest ubuntu:latest alpine:latest scratch
Image Size 670MB~ 110MB~ 4.1MB~ 0
Secure kubelet
9
 curl -sk https://<nodeIP>:10250/run/<namespace>/<pod-name>/<container-name> -d
"cmd=ls -la /“
 Protect kubelet by enable authentication and authorization:
start the apiserver with --kubelet-client-certificate and --kubelet-client-key flags
/usr/local/bin/kubelet
--anonymous-auth=false
--authorization-mode=Webhook
--allow-privileged=true
--kubeconfig=/var/lib/kubelet/kubeconfig
--client-ca-file=/var/lib/kubernetes/ca.pem
• Enable kubelet certification rotation (1.8 beta)
Authentication & Authorization
11
12
Authentication
13
 Static password/token file
 Client certificates x509
 Proxy + headers
 OpenID Connect
 Custom (Web hook)
password,user,uid,”group1,group2,group3”
Authentication
14
 Service accounts
 Default service account have full permissions over the cluster, use custom SA instead
 Set “automountServiceAccountToken : false” in your pod spec – when possible
Authorization
15
 ABAC
 Difficult to manage and understand
 Requires ssh and root filesystem access on the master
 For permission changes to take effect the cluster API server must be restarted
{"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "bob",
"namespace": "projectSpaceX",
"resource": "pods",
"readonly": true
}
}
Authorization
16
 RBAC (stable 1.8)
Service Account
User
Role binding Role
17
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: Bob
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
group
resources: ["pods"]
verbs: ["get", "watch", "list"]
Authorization
18
 Custom (Web hook)
 Node
Restrict kubelet to perform R/W operation only to his bound pods
--authorization-mode=Node,RBAC
--admission-control=NodeRestriction
Network
20
Netwok
21
 Limit the access to cloud provider metadata
(http://169.254.169.254/latest/meta-data/)
22
$ curl -s 169.254.169.254/latest/meta-data/iam/security-
credentials/kubernetes-worker-iam-policy
{
"Code" : "Success",
"LastUpdated" : "2017-12-25T00:00:00Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "MyAccessKeyID",
"SecretAccessKey" : "MySecretAccessKey",
"Token" : "MySessionToken",
"Expiration" : "2017-12-25T04:00:00Z"
} @bradgeesaman
23
# Place credentials in ENV vars
$ export AWS_REGION=us-east-1
$ export AWS_ACCESS_KEY_ID=MyAccessKeyID
$ export AWS_SECRET_ACCESS_KEY=MySecretAccessKey
$ export AWS_SESSION_TOKEN=MySessionToken
$ aws ec2 … @bradgeesaman
The solution
24
• For AWS use kube2iam or kiam (using docker proxy for requests to the
metadata)
• For GCE use k8s-metadata-proxy
• Limit egress with network policy
25
 Use network policy (GA from 1.7) https://goo.gl/HRtn5B
 Egress rules are beta from 1.8
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: access-nginx
spec:
podSelector:
matchLabels:
run: nginx
ingress:
- from:
- podSelector:
matchLabels:
access: "true"
• Istio
Network policy guidelines
26
 Label your workloads properly
 Isolate workloads from each other
 Restrict income traffic to the kube-system (except kube-dns)
 Consider limit egress to the internet
“The definition of Secret—
something you tell everybody to
tell nobody.”
– The universe
Treat your secrets with respect
28
 Don’t store your secrets on Git, it will remain in history even If you
delete it.
 Create dedicated secrets for dev and prod environments
 Secrets are stored at etcd as base64 (almost like plain text) 
encrypt your secrets (K8S encryption –alpha 1.7)
 Use Vault as you secret management (starting from Vault 0.8.3)
Security Context
A security context defines privilege and access control settings for a Pod or Container
29
 Discretionary Access Control: Permission to access an object, like a file, is
based on user ID (UID) and group ID (GID).
 Security Enhanced Linux (SELinux): Objects are assigned security labels.
 Running as privileged or unprivileged.
 Linux Capabilities: Give a process some privileges, but not all the privileges
of the root user.
 AppArmor: Use program profiles to restrict the capabilities of individual
programs.
 Seccomp: Limit a process’s access to open file descriptors.
 AllowPrivilegeEscalation: Controls whether a process can gain more
privileges than its parent process.
Example: RunasNonRoot
30
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo
spec:
containers:
- name: sec-ctx-demo
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsNonRoot : true
31
Example: readOnlyRootFilesystem
32
apiVersion: v1
kind: Pod
metadata:
name: security-context-demo
spec:
containers:
- name: sec-ctx-demo
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsNonRoot : false
readOnlyRootFilesystem : true
33
34
Other security tools and considerations
35
 Scan your docker images for vulnerabilities, (Clair CoreOS /Quay.io,
Docker Security Scanning, aqua, Twistlock).
 Use kube-bench (aqua security) or kubernetes-auto-analyzer
(nccgroup) to execute CIS Kubernetes Benchmark
 Enforce cluster wide security policy w/podSecurityPolicy
 Use only trusted private docker registry
 Always tag your images avoid from using “latest”
 Audit events and store them on external storage (beta 1.8)
 Consider using kubeaudit to audit security issue
36
Other security considerations
37
 Specify an image with its digest (SHA256)
 Keep up with K8S stable releases
 Implement monitoring and set alerts
 Don’t run “kubectl create –f <some unknown URL to some unknown
yamls>
 Keep updated with new security vulnerabilities from the google
group “kubernetes-announces”
https://groups.google.com/forum/#!forum/kubernetes-announce
38
Thanks and credit
39
 My Wife 
 All K8s contributors
 Hacking and Hardening Kubernetes Clusters by Example [I] - Brad Geesaman -
https://goo.gl/komeXN
 Running containers securely with Google Container Engine, Alex Mohr and
Jessica Frazelle - https://goo.gl/AFhTyp
 Shipping in Pirate-Infested Waters: Practical Attack and Defense in Kubernetes
[A] - Greg Castle - https://goo.gl/WFDrrv
 Compliance and Identity Management in Kubernetes [I] Marc Boorshtein -
https://goo.gl/Jf7Rkh
 Securing K8s Microservices with Calico Network Policies, Vadim Solvey -
https://goo.gl/rWGGXM
Thank You.

More Related Content

What's hot

(Draft) Kubernetes - A Comprehensive Overview
(Draft) Kubernetes - A Comprehensive Overview(Draft) Kubernetes - A Comprehensive Overview
(Draft) Kubernetes - A Comprehensive Overview
Bob Killen
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
 
Kubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and Introduction
Stefan Schimanski
 
CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes
Adnan Rashid
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
Eueung Mulyana
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
Thomas Fricke
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
Bob Killen
 
DevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to KubernetesDevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to Kubernetes
Ronny Trommer
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
Rishabh Indoria
 
Container Security
Container SecurityContainer Security
Container Security
Jie Liau
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)
DongHyeon Kim
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
Docker, Inc.
 
Kubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & OperatorsKubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & Operators
SIGHUP
 
Kubernetes Workshop
Kubernetes WorkshopKubernetes Workshop
Kubernetes Workshop
loodse
 
Deploy 22 microservices from scratch in 30 mins with GitOps
Deploy 22 microservices from scratch in 30 mins with GitOpsDeploy 22 microservices from scratch in 30 mins with GitOps
Deploy 22 microservices from scratch in 30 mins with GitOps
Opsta
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!
Krishna-Kumar
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
Martin Danielsson
 
Kubernetes
KubernetesKubernetes
Kubernetes
erialc_w
 
Kubernetes for Beginners: An Introductory Guide
Kubernetes for Beginners: An Introductory GuideKubernetes for Beginners: An Introductory Guide
Kubernetes for Beginners: An Introductory Guide
Bytemark
 
DevOps with Kubernetes
DevOps with KubernetesDevOps with Kubernetes
DevOps with Kubernetes
EastBanc Tachnologies
 

What's hot (20)

(Draft) Kubernetes - A Comprehensive Overview
(Draft) Kubernetes - A Comprehensive Overview(Draft) Kubernetes - A Comprehensive Overview
(Draft) Kubernetes - A Comprehensive Overview
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
 
Kubernetes Architecture and Introduction
Kubernetes Architecture and IntroductionKubernetes Architecture and Introduction
Kubernetes Architecture and Introduction
 
CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes CKA Certified Kubernetes Administrator Notes
CKA Certified Kubernetes Administrator Notes
 
Kubernetes Basics
Kubernetes BasicsKubernetes Basics
Kubernetes Basics
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
Introduction to Kubernetes Workshop
Introduction to Kubernetes WorkshopIntroduction to Kubernetes Workshop
Introduction to Kubernetes Workshop
 
DevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to KubernetesDevJam 2019 - Introduction to Kubernetes
DevJam 2019 - Introduction to Kubernetes
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
Container Security
Container SecurityContainer Security
Container Security
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)
 
Docker and the Linux Kernel
Docker and the Linux KernelDocker and the Linux Kernel
Docker and the Linux Kernel
 
Kubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & OperatorsKubernetes extensibility: CRDs & Operators
Kubernetes extensibility: CRDs & Operators
 
Kubernetes Workshop
Kubernetes WorkshopKubernetes Workshop
Kubernetes Workshop
 
Deploy 22 microservices from scratch in 30 mins with GitOps
Deploy 22 microservices from scratch in 30 mins with GitOpsDeploy 22 microservices from scratch in 30 mins with GitOps
Deploy 22 microservices from scratch in 30 mins with GitOps
 
Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!Kubernetes Application Deployment with Helm - A beginner Guide!
Kubernetes Application Deployment with Helm - A beginner Guide!
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Kubernetes for Beginners: An Introductory Guide
Kubernetes for Beginners: An Introductory GuideKubernetes for Beginners: An Introductory Guide
Kubernetes for Beginners: An Introductory Guide
 
DevOps with Kubernetes
DevOps with KubernetesDevOps with Kubernetes
DevOps with Kubernetes
 

Similar to K8s security best practices

K8s security best practices
K8s security best practicesK8s security best practices
K8s security best practices
Sharon Vendrov
 
Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2
Imesh Gunaratne
 
Container security
Container securityContainer security
Container security
Anthony Chow
 
Security best practices for kubernetes deployment
Security best practices for kubernetes deploymentSecurity best practices for kubernetes deployment
Security best practices for kubernetes deployment
Michael Cherny
 
Security best practices for kubernetes deployment
Security best practices for kubernetes deployment  Security best practices for kubernetes deployment
Security best practices for kubernetes deployment
Aqua Security
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
Ted Jung
 
Docker London: Container Security
Docker London: Container SecurityDocker London: Container Security
Docker London: Container Security
Phil Estes
 
Who is afraid of privileged containers ?
Who is afraid of privileged containers ?Who is afraid of privileged containers ?
Who is afraid of privileged containers ?
Marko Bevc
 
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Michael Man
 
New and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profileNew and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profile
Emily Jiang
 
Veer's Container Security
Veer's Container SecurityVeer's Container Security
Veer's Container Security
Jim Barlow
 
Docker security: Rolling out Trust in your container
Docker security: Rolling out Trust in your containerDocker security: Rolling out Trust in your container
Docker security: Rolling out Trust in your container
Ronak Kogta
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
DoiT International
 
Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops
Jose Manuel Ortega Candel
 
Three Years of Lessons Running Potentially Malicious Code Inside Containers
Three Years of Lessons Running Potentially Malicious Code Inside ContainersThree Years of Lessons Running Potentially Malicious Code Inside Containers
Three Years of Lessons Running Potentially Malicious Code Inside Containers
Ben Hall
 
Cloud Native TLV Meetup: Securing Containerized Applications Primer
Cloud Native TLV Meetup: Securing Containerized Applications PrimerCloud Native TLV Meetup: Securing Containerized Applications Primer
Cloud Native TLV Meetup: Securing Containerized Applications Primer
Phil Estes
 
Meetup 12-12-2017 - Application Isolation on Kubernetes
Meetup 12-12-2017 - Application Isolation on KubernetesMeetup 12-12-2017 - Application Isolation on Kubernetes
Meetup 12-12-2017 - Application Isolation on Kubernetes
dtoledo67
 
Securing the Infrastructure and the Workloads of Linux Containers
Securing the Infrastructure and the Workloads of Linux ContainersSecuring the Infrastructure and the Workloads of Linux Containers
Securing the Infrastructure and the Workloads of Linux Containers
Massimiliano Mattetti
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
Rafael Konlechner
 
Evolution of security strategies in K8s environments.pdf
Evolution of security strategies in K8s environments.pdfEvolution of security strategies in K8s environments.pdf
Evolution of security strategies in K8s environments.pdf
Jose Manuel Ortega Candel
 

Similar to K8s security best practices (20)

K8s security best practices
K8s security best practicesK8s security best practices
K8s security best practices
 
Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2Deep Dive into Kubernetes - Part 2
Deep Dive into Kubernetes - Part 2
 
Container security
Container securityContainer security
Container security
 
Security best practices for kubernetes deployment
Security best practices for kubernetes deploymentSecurity best practices for kubernetes deployment
Security best practices for kubernetes deployment
 
Security best practices for kubernetes deployment
Security best practices for kubernetes deployment  Security best practices for kubernetes deployment
Security best practices for kubernetes deployment
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
Docker London: Container Security
Docker London: Container SecurityDocker London: Container Security
Docker London: Container Security
 
Who is afraid of privileged containers ?
Who is afraid of privileged containers ?Who is afraid of privileged containers ?
Who is afraid of privileged containers ?
 
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
Control Plane: Continuous Kubernetes Security (DevSecOps - London Gathering, ...
 
New and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profileNew and smart way to develop microservice for istio with micro profile
New and smart way to develop microservice for istio with micro profile
 
Veer's Container Security
Veer's Container SecurityVeer's Container Security
Veer's Container Security
 
Docker security: Rolling out Trust in your container
Docker security: Rolling out Trust in your containerDocker security: Rolling out Trust in your container
Docker security: Rolling out Trust in your container
 
K8s best practices from the field!
K8s best practices from the field!K8s best practices from the field!
K8s best practices from the field!
 
Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops Evolution of security strategies in K8s environments- All day devops
Evolution of security strategies in K8s environments- All day devops
 
Three Years of Lessons Running Potentially Malicious Code Inside Containers
Three Years of Lessons Running Potentially Malicious Code Inside ContainersThree Years of Lessons Running Potentially Malicious Code Inside Containers
Three Years of Lessons Running Potentially Malicious Code Inside Containers
 
Cloud Native TLV Meetup: Securing Containerized Applications Primer
Cloud Native TLV Meetup: Securing Containerized Applications PrimerCloud Native TLV Meetup: Securing Containerized Applications Primer
Cloud Native TLV Meetup: Securing Containerized Applications Primer
 
Meetup 12-12-2017 - Application Isolation on Kubernetes
Meetup 12-12-2017 - Application Isolation on KubernetesMeetup 12-12-2017 - Application Isolation on Kubernetes
Meetup 12-12-2017 - Application Isolation on Kubernetes
 
Securing the Infrastructure and the Workloads of Linux Containers
Securing the Infrastructure and the Workloads of Linux ContainersSecuring the Infrastructure and the Workloads of Linux Containers
Securing the Infrastructure and the Workloads of Linux Containers
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Evolution of security strategies in K8s environments.pdf
Evolution of security strategies in K8s environments.pdfEvolution of security strategies in K8s environments.pdf
Evolution of security strategies in K8s environments.pdf
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 

K8s security best practices

  • 1. K8S security – Best practices By: Sharon Vendrov
  • 2. 0 500 1000 1500 2000 2500 Mac Os X Windows 7 Windows XP Windows 8.1 Windows 10 CVE Sum CVE Sum 2 Total Number Of Vulnerabilities in 2017 – Source: CVEdetails.com
  • 3. 3
  • 4. 4
  • 5. Sharon Vendrov Sr. DevOps Engineer About Me 5 Storm-runner functional
  • 6.  Infrastructure protection  K8s internal security  Authentication & Authorization options  Network  Secrets  Container runtime Security  Some other security tools and considerations 6 Agenda
  • 7. Infrastructure protection 7  Limit SSH access to your cluster  Use hardened images for your cluster ( )  Encrypt your storage volume  Avoid from exposing your cluster to the internet  Limit the access to the K8s API (consider to use bastion machine)  Create dedicated cluster for each environment (Prod, Stg, Dev)  Separate sensitive pods into different nodes
  • 8. Kubernetes internal security 8  Use minimal base docker image  Don’t use arbitrary base images  Separate sensitive workloads across instances (using anti-affinity, taints and tolerations)  Use namespaces for isolation  Enforce resource quota (CPU, Memory, Storage) Image Name node:latest ubuntu:latest alpine:latest scratch Image Size 670MB~ 110MB~ 4.1MB~ 0
  • 9. Secure kubelet 9  curl -sk https://<nodeIP>:10250/run/<namespace>/<pod-name>/<container-name> -d "cmd=ls -la /“  Protect kubelet by enable authentication and authorization: start the apiserver with --kubelet-client-certificate and --kubelet-client-key flags /usr/local/bin/kubelet --anonymous-auth=false --authorization-mode=Webhook --allow-privileged=true --kubeconfig=/var/lib/kubelet/kubeconfig --client-ca-file=/var/lib/kubernetes/ca.pem • Enable kubelet certification rotation (1.8 beta)
  • 11. 11
  • 12. 12
  • 13. Authentication 13  Static password/token file  Client certificates x509  Proxy + headers  OpenID Connect  Custom (Web hook) password,user,uid,”group1,group2,group3”
  • 14. Authentication 14  Service accounts  Default service account have full permissions over the cluster, use custom SA instead  Set “automountServiceAccountToken : false” in your pod spec – when possible
  • 15. Authorization 15  ABAC  Difficult to manage and understand  Requires ssh and root filesystem access on the master  For permission changes to take effect the cluster API server must be restarted {"apiVersion": "abac.authorization.kubernetes.io/v1beta1", "kind": "Policy", "spec": { "user": "bob", "namespace": "projectSpaceX", "resource": "pods", "readonly": true } }
  • 16. Authorization 16  RBAC (stable 1.8) Service Account User Role binding Role
  • 17. 17 kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: read-pods namespace: default subjects: - kind: User name: Bob apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.io kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: default name: pod-reader rules: - apiGroups: [""] group resources: ["pods"] verbs: ["get", "watch", "list"]
  • 18. Authorization 18  Custom (Web hook)  Node Restrict kubelet to perform R/W operation only to his bound pods --authorization-mode=Node,RBAC --admission-control=NodeRestriction
  • 20. 20
  • 21. Netwok 21  Limit the access to cloud provider metadata (http://169.254.169.254/latest/meta-data/)
  • 22. 22 $ curl -s 169.254.169.254/latest/meta-data/iam/security- credentials/kubernetes-worker-iam-policy { "Code" : "Success", "LastUpdated" : "2017-12-25T00:00:00Z", "Type" : "AWS-HMAC", "AccessKeyId" : "MyAccessKeyID", "SecretAccessKey" : "MySecretAccessKey", "Token" : "MySessionToken", "Expiration" : "2017-12-25T04:00:00Z" } @bradgeesaman
  • 23. 23 # Place credentials in ENV vars $ export AWS_REGION=us-east-1 $ export AWS_ACCESS_KEY_ID=MyAccessKeyID $ export AWS_SECRET_ACCESS_KEY=MySecretAccessKey $ export AWS_SESSION_TOKEN=MySessionToken $ aws ec2 … @bradgeesaman
  • 24. The solution 24 • For AWS use kube2iam or kiam (using docker proxy for requests to the metadata) • For GCE use k8s-metadata-proxy • Limit egress with network policy
  • 25. 25  Use network policy (GA from 1.7) https://goo.gl/HRtn5B  Egress rules are beta from 1.8 kind: NetworkPolicy apiVersion: networking.k8s.io/v1 metadata: name: access-nginx spec: podSelector: matchLabels: run: nginx ingress: - from: - podSelector: matchLabels: access: "true" • Istio
  • 26. Network policy guidelines 26  Label your workloads properly  Isolate workloads from each other  Restrict income traffic to the kube-system (except kube-dns)  Consider limit egress to the internet
  • 27. “The definition of Secret— something you tell everybody to tell nobody.” – The universe
  • 28. Treat your secrets with respect 28  Don’t store your secrets on Git, it will remain in history even If you delete it.  Create dedicated secrets for dev and prod environments  Secrets are stored at etcd as base64 (almost like plain text)  encrypt your secrets (K8S encryption –alpha 1.7)  Use Vault as you secret management (starting from Vault 0.8.3)
  • 29. Security Context A security context defines privilege and access control settings for a Pod or Container 29  Discretionary Access Control: Permission to access an object, like a file, is based on user ID (UID) and group ID (GID).  Security Enhanced Linux (SELinux): Objects are assigned security labels.  Running as privileged or unprivileged.  Linux Capabilities: Give a process some privileges, but not all the privileges of the root user.  AppArmor: Use program profiles to restrict the capabilities of individual programs.  Seccomp: Limit a process’s access to open file descriptors.  AllowPrivilegeEscalation: Controls whether a process can gain more privileges than its parent process.
  • 30. Example: RunasNonRoot 30 apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: containers: - name: sec-ctx-demo image: gcr.io/google-samples/node-hello:1.0 securityContext: runAsNonRoot : true
  • 31. 31
  • 32. Example: readOnlyRootFilesystem 32 apiVersion: v1 kind: Pod metadata: name: security-context-demo spec: containers: - name: sec-ctx-demo image: gcr.io/google-samples/node-hello:1.0 securityContext: runAsNonRoot : false readOnlyRootFilesystem : true
  • 33. 33
  • 34. 34
  • 35. Other security tools and considerations 35  Scan your docker images for vulnerabilities, (Clair CoreOS /Quay.io, Docker Security Scanning, aqua, Twistlock).  Use kube-bench (aqua security) or kubernetes-auto-analyzer (nccgroup) to execute CIS Kubernetes Benchmark  Enforce cluster wide security policy w/podSecurityPolicy  Use only trusted private docker registry  Always tag your images avoid from using “latest”  Audit events and store them on external storage (beta 1.8)  Consider using kubeaudit to audit security issue
  • 36. 36
  • 37. Other security considerations 37  Specify an image with its digest (SHA256)  Keep up with K8S stable releases  Implement monitoring and set alerts  Don’t run “kubectl create –f <some unknown URL to some unknown yamls>  Keep updated with new security vulnerabilities from the google group “kubernetes-announces” https://groups.google.com/forum/#!forum/kubernetes-announce
  • 38. 38
  • 39. Thanks and credit 39  My Wife   All K8s contributors  Hacking and Hardening Kubernetes Clusters by Example [I] - Brad Geesaman - https://goo.gl/komeXN  Running containers securely with Google Container Engine, Alex Mohr and Jessica Frazelle - https://goo.gl/AFhTyp  Shipping in Pirate-Infested Waters: Practical Attack and Defense in Kubernetes [A] - Greg Castle - https://goo.gl/WFDrrv  Compliance and Identity Management in Kubernetes [I] Marc Boorshtein - https://goo.gl/Jf7Rkh  Securing K8s Microservices with Calico Network Policies, Vadim Solvey - https://goo.gl/rWGGXM

Editor's Notes

  1. https://www.youtube.com/watch?v=sdF5IsyOxU4
  2. Using the firewall will force the attacker to run from the cluster and not from his “friendly environment”
  3. Public images – we aren’t aware who build them and what they contain Enforcing quota will protected us in some cases of DOS Quota doesn’t currently support ASG
  4. Who need to authenticate to the Kubernetes API?
  5. Why certificates are better? You can enable multiple authentication methods at once. You should usually use at least two methods: Reverse proxy – not secure enough we need to take into account possibility the some is already in our network. OpenID connect – no web oauth2 client and token no revokeable usually requires refresh
  6. Normal users are assumed to be managed by an outside, independent service.  Kubernetes does not have objects which represent normal user accounts. In contrast, service accounts are users managed by the Kubernetes API.
  7. Example attacker needs curl
  8. Many security features have been implemented for each release you must keep updated with them