performing-kubernetes-cis-benchmark-with-kube-bench
使用 kube-bench 对照 CIS Benchmark 审计 Kubernetes 集群安全态势,对控制平面、工作节点和 RBAC 执行自动化检查。
Best use case
performing-kubernetes-cis-benchmark-with-kube-bench is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用 kube-bench 对照 CIS Benchmark 审计 Kubernetes 集群安全态势,对控制平面、工作节点和 RBAC 执行自动化检查。
Teams using performing-kubernetes-cis-benchmark-with-kube-bench should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/performing-kubernetes-cis-benchmark-with-kube-bench/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How performing-kubernetes-cis-benchmark-with-kube-bench Compares
| Feature / Agent | performing-kubernetes-cis-benchmark-with-kube-bench | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用 kube-bench 对照 CIS Benchmark 审计 Kubernetes 集群安全态势,对控制平面、工作节点和 RBAC 执行自动化检查。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用 kube-bench 执行 Kubernetes CIS Benchmark
## 概述
kube-bench 是 Aqua Security 开源的 Go 工具,用于运行 CIS Kubernetes Benchmark 检查。它对照安全最佳实践验证控制平面、etcd、工作节点和策略配置,生成可操作的通过/失败/警告报告。
## 前置条件
- Kubernetes 集群(v1.24+)
- 具有 cluster-admin 访问权限的 kubectl
- 直接运行需要节点访问权限,或具有特权 Pod 访问权限
## 安装
```bash
# 二进制安装
curl -L https://github.com/aquasecurity/kube-bench/releases/download/v0.7.3/kube-bench_0.7.3_linux_amd64.tar.gz | tar xz
sudo mv kube-bench /usr/local/bin/
# 以 Kubernetes Job 方式运行
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl logs job/kube-bench
# 以具有宿主机访问权限的 Pod 运行
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-master.yaml
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-node.yaml
```
## 运行基准测试
### 完整基准测试
```bash
# 运行所有检查(自动检测节点类型)
kube-bench run
# 以 JSON 格式输出
kube-bench run --json > kube-bench-results.json
# 以 JUnit 格式输出用于 CI
kube-bench run --junit > kube-bench-results.xml
```
### 特定组件检查
```bash
# 控制平面(master)检查
kube-bench run --targets master
# 工作节点检查
kube-bench run --targets node
# etcd 检查
kube-bench run --targets etcd
# 策略检查
kube-bench run --targets policies
# 控制平面 + etcd
kube-bench run --targets master,etcd
```
### 托管 Kubernetes
```bash
# Amazon EKS
kube-bench run --benchmark eks-1.2.0
# Google GKE
kube-bench run --benchmark gke-1.4.0
# Azure AKS
kube-bench run --benchmark aks-1.0
# Red Hat OpenShift
kube-bench run --benchmark rh-1.0
```
### 过滤结果
```bash
# 仅显示失败项
kube-bench run --targets master | grep "\[FAIL\]"
# 运行特定检查
kube-bench run --check 1.2.1
# 运行检查组
kube-bench run --group 1.2
```
## CIS Benchmark 章节
| 章节 | 组件 | 关键检查项 |
|---------|-----------|------------|
| 1.1 | 控制平面 - API Server | 匿名认证、RBAC、审计日志 |
| 1.2 | 控制平面 - API Server | 准入控制器、加密 |
| 1.3 | 控制平面 - Controller Manager | 服务账户令牌、绑定地址 |
| 1.4 | 控制平面 - Scheduler | 性能分析、绑定地址 |
| 2.1 | etcd | 客户端证书认证、对等加密 |
| 3.1 | 控制平面 - 认证 | OIDC、客户端证书 |
| 4.1 | 工作节点 - kubelet | 匿名认证、授权 |
| 4.2 | 工作节点 - kubelet | TLS、只读端口 |
| 5.1 | 策略 - RBAC | cluster-admin 使用、服务账户 |
| 5.2 | 策略 - Pod 安全 | 特权、宿主机命名空间 |
| 5.3 | 策略 - 网络 | 每命名空间的网络策略 |
| 5.7 | 策略 - 通用 | 密钥、安全上下文 |
## 输出示例
```
[INFO] 1 控制平面安全配置
[INFO] 1.1 控制平面节点配置文件
[PASS] 1.1.1 确保 API server Pod 规格文件权限设置为 600
[PASS] 1.1.2 确保 API server Pod 规格文件所有权设置为 root:root
[FAIL] 1.1.3 确保 controller manager Pod 规格文件权限设置为 600
[WARN] 1.1.4 确保 scheduler Pod 规格文件权限设置为 600
== 汇总 ==
45 项检查通过
12 项检查失败
8 项检查警告
0 项检查信息
```
## CI/CD 集成
### GitHub Actions
```yaml
name: CIS Benchmark
on:
schedule:
- cron: '0 6 * * 1'
jobs:
kube-bench:
runs-on: ubuntu-latest
steps:
- name: 配置 kubectl
uses: azure/setup-kubectl@v3
- name: 运行 kube-bench
run: |
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl wait --for=condition=complete job/kube-bench --timeout=120s
kubectl logs job/kube-bench > kube-bench-report.txt
- name: 检查失败项
run: |
FAILS=$(grep -c "\[FAIL\]" kube-bench-report.txt || true)
echo "Failed checks: $FAILS"
if [ "$FAILS" -gt 0 ]; then
echo "::warning::$FAILS CIS benchmark checks failed"
fi
- name: 上传报告
uses: actions/upload-artifact@v4
with:
name: kube-bench-report
path: kube-bench-report.txt
```
## 修复示例
### 1.2.1 - 确保 --anonymous-auth 设置为 false
```yaml
# /etc/kubernetes/manifests/kube-apiserver.yaml
spec:
containers:
- command:
- kube-apiserver
- --anonymous-auth=false
```
### 4.2.1 - 确保 kubelet 上的 --anonymous-auth 设置为 false
```yaml
# /var/lib/kubelet/config.yaml
authentication:
anonymous:
enabled: false
webhook:
enabled: true
```
### 5.2.1 - 最小化通配符 RBAC
```bash
# 查找具有通配符权限的角色
kubectl get clusterroles -o json | jq '.items[] | select(.rules[].resources[] == "*") | .metadata.name'
```
## 最佳实践
1. **在集群配置前后运行 kube-bench**
2. **通过 CronJob 安排每周扫描**,用于漂移检测
3. **导出 JSON** 用于 SIEM/合规报告
4. **优先修复 FAIL 项**,再处理 WARN 项
5. **使用与 Kubernetes 发行版匹配的基准配置文件**
6. **跟踪评分变化趋势**,衡量安全态势改进效果
7. **结合准入控制器**,防止配置漂移Related Skills
securing-kubernetes-on-cloud
本技能涵盖通过实施 Pod 安全标准(Pod Security Standards)、网络策略、工作负载身份、RBAC 权限控制、镜像准入控制和运行时安全监控,对 EKS、AKS 和 GKE 上的托管 Kubernetes 集群进行加固。涉及云平台特定安全功能,包括 EKS 的 IRSA、GKE 的工作负载身份(Workload Identity)以及 AKS 的托管身份(Managed Identity)。
scanning-kubernetes-manifests-with-kubesec
使用 Kubesec 对 Kubernetes 资源清单执行安全风险分析,识别错误配置、权限提升风险以及与安全最佳实践的偏差。
performing-yara-rule-development-for-detection
通过识别可执行文件中的唯一字节模式、字符串和行为指标,开发精准的 YARA 恶意软件检测规则,同时将误报率降至最低。
performing-wireless-security-assessment-with-kismet
使用 Kismet 通过被动射频监控进行无线网络安全评估,检测流氓接入点(Rogue AP)、隐藏 SSID、弱加密和未授权客户端。
performing-wireless-network-penetration-test
执行无线网络渗透测试,通过捕获握手包、破解 WPA2/WPA3 密钥、检测流氓接入点以及使用 Aircrack-ng 和相关工具测试无线网络分段,评估 WiFi 安全性。
performing-windows-artifact-analysis-with-eric-zimmerman-tools
使用 Eric Zimmerman 的开源 EZ Tools 套件(包括 KAPE、MFTECmd、PECmd、LECmd、JLECmd 和 Timeline Explorer)执行全面的 Windows 取证制品分析,解析注册表 hive、预取文件、事件日志和文件系统元数据。
performing-wifi-password-cracking-with-aircrack
在授权无线安全评估中捕获 WPA/WPA2 握手包,并使用 aircrack-ng、hashcat 和字典攻击进行离线密码破解, 以评估密码短语强度和无线网络安全状况。
performing-web-cache-poisoning-attack
在授权安全测试期间,通过未纳入缓存键的头部和参数毒化缓存响应,利用 Web 缓存机制向其他用户投递恶意内容。
performing-web-cache-deception-attack
通过利用 CDN 缓存层与源服务器之间的路径规范化差异,执行 Web 缓存欺骗攻击,从而缓存并获取敏感的已认证内容。
performing-web-application-vulnerability-triage
使用 OWASP 风险评级方法论对 DAST/SAST 扫描器的 Web 应用程序漏洞发现进行分类,区分真阳性和假阳性,并确定修复优先级。
performing-web-application-scanning-with-nikto
Nikto 是一款开源 Web 服务器和 Web 应用程序扫描器,可针对超过 7,000 个潜在危险文件/程序进行测试,检查超过 1,250 个服务器的过期版本,并识别超过 270 个服务器的版本特定问题。
performing-web-application-penetration-test
遵循 OWASP Web 安全测试指南(WSTG)方法论,对 Web 应用程序执行系统化安全测试,识别认证、授权、 输入验证、会话管理和业务逻辑中的漏洞。测试人员以 Burp Suite 作为主要拦截代理,结合手动测试技术 发现自动化扫描器遗漏的缺陷。适用于 Web 应用渗透测试、OWASP 测试、应用安全评估或 Web 漏洞测试等请求场景。