运维知识点-Kubernetes_K8s

运维知识点-Kubernetes_K8s_第1张图片

Kubernetes

  • RBAC配置不当
    • 攻击场景
    • 攻击过程

RBAC配置不当

Service Account本质是服务账号,是Pod连接K8s集群的凭证。
在默认情况下,系统会为创建的Pod提供一个默认的Service Account,

用户也可以自定义Service Account,与Service Account关联的凭证会自动挂载到Pod的文件系统中。

当攻击者通过某个web应用获取到一个Pod权限时,如果RBAC权限配置不当,

Pod关联的Service Account拥有创建Pod的权限。

攻击者就可以使用污点容忍的方式,将挂载根目录的恶意Pod调度到Master节点,获取Master 节点上的 kubeconfig 文件,从而直接接管整个集群。

攻击场景

(1)Service Account赋予bypass对test名称空间拥有管理员权限。


kubectl create serviceaccount bypass -n test
kubectl create rolebinding sa-admin --clusterrole=cluster-admin --serviceaccount=test:bypass -n test
kubectl get pod --as=system:serviceaccount:test:bypass

运维知识点-Kubernetes_K8s_第2张图片
(2)在Pod中,使用自定义的Service Account。

运维知识点-Kubernetes_K8s_第3张图片


# pod-sa.yaml
apiVersion: v1
kind: Pod
metadata:
    name: pod-sa
    namespace: test
spec:
    serviceAccountName: "bypass"
    containers:
    - name: ubuntu
      image: ubuntu:20.04
      command: ['/bin/sh','-c','sleep 24h']

(3)在Pod创建时,Service Account关联的凭证,

会挂载到 /var/run/secrets/kubernetes.io/serviceaccount/ 目录,
其中ca.crt是证书、namespace是Pod所属的命名空间,
token是访问API Server的令牌 。

在这里插入图片描述

攻击过程

(1)攻击方式:kubectl 命令行操作
(2)攻击方式:curl 命令操作

你可能感兴趣的:(运维,kubernetes,容器)