DEV Community

terngr
terngr

Posted on

1

CVE-2022-0185 - How to mitigate - Linux Kernel - cap_sys_admin - K8s vulnerability

ระดับความรุนแรง: สูง
Description: User Account ที่มีสิทธิ์ใช้งานในระดับ User ปกติ สามารถ Exploit code ทำ Privilege escalation จนได้สิทธิ์ root โดยช่องโหว่เกิดจากการเรียกใช้ cap_sys_admin ที่ kernel

  1. ฉะนั้น การป้องกันช่องโหว่นี้ ที่ต้นตอ ทำได้โดย Patch Linux Kernel ตามแต่ละ Distro
    RHEL: https://access.redhat.com/security/cve/CVE-2022-0185
    Ubuntu: https://ubuntu.com/security/CVE-2022-0185
    Debian: https://security-tracker.debian.org/tracker/CVE-2022-0185

  2. ถ้ายังไม่สะดวกที่จะ Patch Linux

2.1 Linux ที่ไม่ได้มีการใช้งาน Container และไม่ได้มีการใช้งาน namespace สามารถ mitigate ด้วยคำสั่ง
**ห้ามใช้คำสั่งนี้กับ Linux ที่มีการใช้งาน Container เพราะจะทำให้ Container ใช้งานไม่ได้
2.1.1for RHEL:

echo "user.max_user_namespaces=0" > /etc/sysctl.d/userns.conf

sysctl -p /etc/sysctl.d/userns.conf

2.1.2for Ubuntu

sysctl -w kernel.unprivileged_userns_clone=0

2.2 Linux ที่มีการใช้งาน Container ต้องดูเป็นเคสๆ ไปครับ

2.2.1 Red Hat OpenShift มี Default Security Context Constraint(SCC) ช่วยป้องกันได้ แต่เพื่อความแน่ใจให้ตรวจสอบว่าการ Deploy pod, container ไม่มีการระบุให้ใช้ seccompProfile ตัวอื่น
สามารถเช็คได้โดยดูใน yaml ของ pod และ resources ที่เกี่ยวกับ pod(เช่น daemonset, deployment, replicasets) ว่าไม่มีการใช้ seccompProfile ตัวอื่น
ตัวอย่าง กรณีมีการใช้งาน seccompProfile ที่ไม่ใช่ Default
https://kubernetes.io/docs/tutorials/security/seccomp/#create-pod-with-seccomp-profile-that-only-allows-necessary-syscalls
kind: pod
spec:
securityContext:
seccompProfile:
type: Localhost
localhostProfile: profiles/fine-grained.json
ถ้ามีการใช้แบบนี้ ต้องไปเช็ค seccompProfile ที่ชื่อว่า fine-grained ว่ามีการเปิดให้ใช้ cap_sys_admin ไหม

2.2.2 บน Kubernetes Cluster โดย Default จะไม่ได้มีการ Enable seccomp profile(ที่ช่วยป้องกันไม่ให้เรียก cap_sys_admin) ไว้ ฉะนั้นบน Kubernetes มาตรฐาน จึงมีช่องโหว่(ยังอยู่ใน alpha state จึงถูก disable by default)

2.2.2.1ทางแก้ไข บน Production ให้ทำการแก้ไข pod และที่เกี่ยวกับ pod(เช่น daemonset, deployment, replicasets) ให้มีการใช้งาน default seccompProfile โดยเพิ่ม seccompProfile ตามตัวอย่างนี้
https://kubernetes.io/docs/tutorials/security/seccomp/#create-pod-that-uses-the-container-runtime-default-seccomp-profile
kind: pod
spec:
securityContext:
seccompProfile:
type: RuntimeDefault

เมื่อเพิ่ม Profile แล้ว จำเป็นต้องทดสอบการทำงานของ pod ว่ายังทำงานได้ปกติไหม ไม่ถูก seccompProfile จำกัดสิทธิ์บางอย่างจนทำงานไม่ได้, ทำการปรับและทดสอบไปทีละ pod
หากมี pod ไหนใช้งานไม่ได้ ให้เช็ค Error และปรับแก้ seccompProfile ใหม่ ให้ allow seccomp ที่ต้องการใช้งาน, ตัวอย่างการปรับแก้ seccompProfile

ตัวอย่าง seccompProfile: https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/security/seccomp/profiles/fine-grained.json

ตัวอย่างการใช้ custom seccompProfile: https://kubernetes.io/docs/tutorials/security/seccomp/#create-pod-that-uses-the-container-runtime-default-seccomp-profile

2.2.2.2 เมื่อปรับแก้และทดสอบตามทำงานตาม 2.2.2.1 เสร็จแล้ว และต้องการให้ container ที่จะรันในอนาคต ใช้งาน seccompProfile ได้แบบ Default โดยไม่จำเป็นต้องระบุใน seccompProfile เพิ่มใน pod ทุกครั้ง
สามารถ enable RuntimeDefault ได้ที่ kubelet(เปิดใช้งานที่ Worker node ทีละ node)
วิธีเปิด SeccompDefault: https://kubernetes.io/docs/tutorials/security/seccomp/#enable-the-use-of-runtimedefault-as-the-default-seccomp-profile-for-all-workloads
ทำได้โดยเพิ่ม --feature-gates=SeccompDefault=true ให้กับ kubelet
*ควรเปิดใช้งาน SeccompDefault หลังจากเช็คแต่ละ pod ตามข้อ 2.2.2.1 เสร็จแล้ว ว่าการทำงานของ Apps ใน pod ไม่ได้รับผลกระทบ
*
อีกวิธีที่ kubernetes.io แนะนำ คือให้ Enable SeccompDefault แค่บาง worker ก่อน แล้วทดสอบนำ pod มารันจนครบ, เมื่อไม่ติดปัญหาแล้วจึง enable ให้ครบทุก worker

สรุป: ช่องโหว่นี้มีความร้ายแรงสูง แนะนำให้ Patch โดยเร็วตามคำแนะนำของแต่ละ Products ครับ


References:
https://www.armosec.io/blog/cve-2022-0185-kubernetes-users/
https://access.redhat.com/security/cve/CVE-2022-0185
https://security-tracker.debian.org/tracker/CVE-2022-0185
https://ubuntu.com/security/CVE-2022-0185
https://sysdig.com/blog/cve-2022-0185-container-escape/
https://blog.aquasec.com/cve-2022-0185-linux-kernel-container-escape-in-kubernetes
https://kubernetes.io/docs/tutorials/security/seccomp/#enable-the-use-of-runtimedefault-as-the-default-seccomp-profile-for-all-workloads
https://github.com/nestybox/sysbox-ee
https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#securitycontext-v1-core

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more