第⼀次使⽤ k8s 就不埋漏洞
YSc

CYBERSEC 2020
第⼀次使⽤ k8s 就不埋 理 漏洞
YSc
• Balsn CTF Team Co-Founder

• HITCON CMT & Summit & Training Speaker

• Modern Web & DevOps Days Speaker

• Security Engineer & Security Consultant

• ⽩帽觀點 https://secview.io/
y
Kubernetes Basics
https://kubernetes.io/docs/tutorials/kubernetes-basics/
Control Plane
Node 1
Node 2
Node 3
Node 1
Node 2
Node 3PodControl Plane
Pod
Node 1
Node 2
Node 3
Pod
Pod
D
Deployment
Control Plane
Pod
Node 1
Node 2
Node 3
Pod
Pod
Kubelet
Kubelet
Kubelet
D
Deployment
Control Plane
Pod
Node 1
Node 2
Node 3
Pod
Pod
Kubelet
Kubelet
Kubelet
D
Deployment
S
Service
Control Plane
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp1
spec:
replicas: 1
selector:
matchLabels:
app: webapp1
template:
metadata:
labels:
app: webapp1
spec:
containers:
- name: webapp1
image: a-image:latest
ports:
- containerPort: 80
kubectl apply -f deployment.yaml
Kubernetes 基礎上的資安問題 Kubernetes 應⽤上的資安問題
⾃建 vs 雲端
https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture
Kubernetes 基礎上的資安問題 Kubernetes 應⽤上的資安問題
Kubernetes 基礎上的資安問題
⾦鑰管理
權限管理
網路管理
Encrypting Secret Data at Rest
https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/
權限管理
• ⼀個 Admin Role 憑證共⽤

• 切不同 Team Roles,但憑證更新、⽣命週期管理不當

• 服務間耦合複雜,無法切割權限界線
Cloud Metadata
140.112.256.432
192.168.3.10
192.168.3.11
http://140.112.256.432/image?url=http://metadata.google.internal/computeMetadata/
v1beta1/instance/service-accounts/default/token
內網滲透
• Pod 和 Pod 間預設互通,儘管 Pod 是在不同 Namespace

• 內網平⾏滲透

• Intranet port scan

• 內網服務 e.g. Mongodb, Redis(預設沒有 Auth 的服務)

• Cloud Provider Metadata
Kubernetes 基礎上的資安問題
⾦鑰管理
權限管理
網路管理
Secret Management
https://www.vaultproject.io/
Kubernetes authentication through dex
https://github.com/dexidp/dex
Network Policy
https://kubernetes.io/docs/concepts/services-
networking/network-policies/
Service Mesh on Kubernetes
https://istio.io/
Kubernetes 基礎上的資安問題 Kubernetes 應⽤上的資安問題
Kubernetes 應⽤上的資安問題
服務運⾏時的資安
映像檔安全
設定檔檢查
設定檔疏失
• 沒有限制 CPU 和 Memory

• 沒有做服務存活檢查 Readiness and Liveness
Probes

• 沒有配置 Network Policies

• 使⽤ Root 執⾏服務、使⽤ Privileged 模式
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp1
spec:
replicas: 1
selector:
matchLabels:
app: webapp1
template:
metadata:
labels:
app: webapp1
spec:
containers:
- name: webapp1
image: a-image:latest
ports:
- containerPort: 80
報告:前⼗⼤熱⾨ Docker 映像檔都有⾄少 30 個以上的漏洞
https://www.ithome.com.tw/news/129018
Runtime Security
• 偵測是否有 shell 正在運⾏

• 偵測是否是 privileged mode

• 偵測是否使⽤敏感檔案(e.g. /etc/shadow)
Kubernetes 應⽤上的資安問題
服務運⾏時的資安
映像檔安全
設定檔檢查
設定檔檢查
kube-score
https://github.com/zegl/kube-score
映像檔安全
https://github.com/aquasecurity/trivy
Runtime Security
https://github.com/falcosecurity/falco
Kubernetes 部署後是否安全?
https://github.com/aquasecurity/kube-bench
開發服務時配置 Kubernetes建立 Kubernetes 前
• 建立公司內基礎建設

• ⾦鑰管理、⾝份與權限管理
• ⾃建 vs 雲端:調整資安參數

• ⾦鑰、權限規劃與串接

• 啟⽤ Network Policy

• 配置 Service Mesh

• 配置 Runtime Security

• Kubernetes Audit Event
• DevSecOps

• CI Pipeline 設定檔檢查

• CD Pipeline 映像檔檢查
Reference
• Official Documents

• https://kubernetes.io/docs/tasks/administer-cluster/securing-a-cluster/

• https://kubernetes.io/blog/2018/07/18/11-ways-not-to-get-hacked/

• Tools

• https://sysdig.com/blog/33-kubernetes-security-tools/

• https://learnk8s.io/validating-kubernetes-yaml

• https://rancher.com/blog/2019/2019-03-21-comparing-kubernetes-cni-providers-flannel-calico-canal-
and-weave/
⽩帽觀點
https://secview.io

CYBERSEC 2020 臺灣資安大會 - 第一次使用 k8s 就不埋漏洞