Halo semuanya.
Saya ingin berbagi pengalaman saya berhasil lulus ujian Certified Kubernetes Security (CKS) dari Linux Foundation . Ujian ini, seperti yang Anda duga, menguji kemampuan kami untuk mengonfigurasi berbagai aspek keamanan cluster Kubernetes dan aplikasi yang berjalan di atasnya. Saya menyukai ujiannya, melihat keamanan dari berbagai sudut pandang, dan juga menggunakan alat eksternal yang sangat berguna seperti Falco, Trivy, kube-bench, Agen Kebijakan Terbuka, gVisor, dll. Ujian itu sendiri menurut saya cukup sulit, tidak seperti CKA, yang lebih ditujukan untuk pendatang baru di Kubernetes.
Pertama-tama saya akan berbicara tentang ujian dan persiapannya secara umum, dan kemudian beralih ke topik yang dibahas dalam ujian.
Saat ini, hanya ada dua ujian keamanan Kubernetes - ini sebenarnya adalah CKS itu sendiri, serta Spesialis Bersertifikat Red Hat dalam Keamanan: Kontainer dan OpenShift , yang menangani keamanan OpenShift. Kedua ujian ini tumpang tindih dalam banyak hal, namun menurut Openshift, menurut saya ujiannya masih lebih sulit (saya berhasil gagal).
Biaya ujian $ 300 secara terpisah , kursus resmi Kubernetes Security Fundamentals (LFS260) seharga $ 299 , Anda dapat membeli kursus dan ujian bersama seharga $ 499 . Saya membeli kursus dan ujian bersama seharga $ 200 di Penjualan Tahun Baru Linux Foundation tradisional.
CKS CKA (Certified Kubernetes Administrator). CKS, , CKA. , CKS CKA.
. :
Linux Foundation: Kubernetes Security Fundamentals (LFS260). Linux Foundation, . , , , , - PDF ( , ?!), . , . , .
Udemy 3599 . , " ", . , , . https://killer.sh. , , .. - . , , .. , . , .
15-20 , 2 .. 6-8 . . , Kubernetes killer.sh, 1 40 .
67%, . , "".
. , .
- . CKS. :
Cluster Setup (10%)
Use Network security policies to restrict cluster level access
Use CIS benchmark to review the security configuration of Kubernetes components (etcd, kubelet, kubedns, kubeapi)
Properly set up Ingress objects with security control
Protect node metadata and endpoints
Minimize use of, and access to, GUI elements
Verify platform binaries before deploying
Cluster Hardening (15%)
Restrict access to Kubernetes API
Use Role Based Access Controls to minimize exposure
Exercise caution in using service accounts e.g. disable defaults, minimize permissions on newly created ones
Update Kubernetes frequently
System Hardening15%
Minimize host OS footprint (reduce attack surface)
Minimize IAM roles
Minimize external access to the network
Appropriately use kernel hardening tools such as AppArmor, seccomp
Minimize Microservice Vulnerabilities (20%)
Setup appropriate OS level security domains e.g. using PSP, OPA, security contexts
Manage Kubernetes secrets
Use container runtime sandboxes in multi-tenant environments (e.g. gvisor, kata containers)
Implement pod to pod encryption by use of mTLS
Supply Chain Security20%
Minimize base image footprint
Secure your supply chain: whitelist allowed registries, sign and validate images
Use static analysis of user workloads (e.g.Kubernetes resources, Docker files)
Scan images for known vulnerabilities
Monitoring, Logging and Runtime Security20%
Perform behavioral analytics of syscall process and file activities at the host and container level to detect malicious activities
Detect threats within physical infrastructure, apps, networks, data, users and workloads
Detect all phases of attack regardless where it occurs and how it spreads
Perform deep analytical investigation and identification of bad actors within environment
Ensure immutability of containers at runtime
Use Audit Logs to monitor access
, , , - . , , . .
. Falco Sysdig. Linux , . Falco , :
hostPID
hostNetwork
hostPath
,
/etc
IP-
... .
, Falco Kubernetes, Kubernetes API, :
hostPID
hostNetwork
.
kube-system
ClusterRoleBinding
cluster-admin
... .
, Falco . , .. , . , Falco , .
Kubernetes, RBAC , Open Policy Agent (OPA). Kubernetes , Rego. Kubernetes validating admission webhook OPA Gatekeeper. Custom Resource Definition. , costcenter.
apiVersion: templates.gatekeeper.sh/v1beta1
kind: ConstraintTemplate
metadata:
name: k8srequiredlabels
spec:
crd:
spec:
names:
kind: K8sRequiredLabels
validation:
openAPIV3Schema:
properties:
labels:
type: array
items: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package k8srequiredlabels
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.parameters.labels[_]}
missing := required - provided
count(missing) > 0
msg := sprintf("you must provide labels: %v", [missing])
}
---
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sRequiredLabels
metadata:
name: ns-must-have-costcenter
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Namespace"]
parameters:
labels: ["costcenter"]
costcenter :
Error from server (you must provide labels: "costcenter"): error when creating "ns.yaml": admission webhook "validating-webhook.openpolicyagent.org" denied the request: you must provide labels: "costcenter"
OPA Gatekeeper , , .. Kubernetes, , . , Gatekeeper mutating webhook, .. , .
, Rego playground, . , Kubernetes, .
, , Trivy Aquasecurity. , , , Clair, .
:
Network Policy. , from to . .
RBAC.
Role
ClusterRole
,RoleBinding
ClusterRoleBinding
. ,ClusterRole
ClusterRoleBinding
, ,RoleBinding
,ClusterRole
( ,admin
,edit
view
, ).
Role
RoleBinding
, , . , .
, , , ("Authorization: Bearer $TOKEN" ).
Kubernetes. Falco, . , kube-apiserver, .
Kube-bench. .
kube-apiserver, kube-scheduler, kube-controller-manager kubelet. , kubeadm, . , , , kube-apiserver, , (
/var/log/pods/*
), .. .
kubeadm .
YAML- Kubernetes . , , , .
-
-
AppArmor. AppArmor . (!)
Seccomp. , AppArmor.
RuntimeClass, gVisor. , , .
PodSecurityPolicy (PSP). , PSP , .. , , AppArmor securityContext,
defaultAllowPrivilegeEscalation
defaultAddCapabilities
.
, PodSecurityPolicy use PSP . .
Kubernetes Dashboard. Kubernetes Dashboard, , .
(, Chrome, Vivaldi). :
, . https://kubernetes.io/docs.
, Certified Kubernetes Security.