Communitygithub.com

使用 kube-bench 對 Kubernetes 進行基準測試

利用 kube-bench (Aqua Security) 執行 CIS Kubernetes 基準測試,檢測叢集控制平面、工作節點與政策層面的安全合規性,並提供修復建議。

使用 kube-bench 對 Kubernetes 進行基準測試 是什麼?

此技能詳細說明如何使用 kube-bench 對 Kubernetes 叢集進行安全基準測試。kube-bench 是由 Aqua Security 開發的開源工具,它會根據 CIS Kubernetes 基準測試文件,自動檢查叢集控制平面元件(如 API Server、Controller Manager、Scheduler、etcd)、kubelet 及工作節點配置,以及叢集範圍的政策設定。每個檢查項目都會以 PASS、FAIL、WARN 或 INFO 狀態報告,並附上直接來自 CIS 指南的修復建議。 技能涵蓋多種執行模式:可作為獨立二進位檔在節點上執行、以容器方式執行,或最常見的是以 Kubernetes Job 的形式在叢集內執行,Job 的 Pod 會掛載宿主機檔案系統以讀取相關配置檔。輸出格式支援人類可讀的文字、JSON、JUnit 以及 AWS Security Finding Format (ASFF),並可匯入 PostgreSQL 資料庫進行趨勢追蹤。 使用此技能,您可以為新叢集建立安全基準、進行定期合規稽核、驗證修復措施是否生效、將合規掃描整合至 CI/CD 管線或持續監控系統,並為 SOC 2、PCI DSS 等合規準備證據。技能也對應到 MITRE ATT&CK 技術 T1610 (Deploy Container),透過強制執行 CIS 基準來限制特權容器、主機命名空間、匿名 API 存取等攻擊面。 支援的 Kubernetes 平台包括一般 Kubernetes 以及 EKS、GKE、AKS、ACK、OpenShift、RKE、k3s 等受管發行版。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/benchmarking-kubernetes-with-kube-bench

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

使用 kube-bench 對 Kubernetes 進行基準測試 是做什麼的?

概述

kube-bench(由 Aqua Security 開發)是一款開源工具,它會根據 CIS Kubernetes 基準測試 文件中記載的檢查項目,檢查 Kubernetes 叢集是否已安全部署。它會檢查控制平面元件(API Server、Controller Manager、Scheduler、etcd)、kubelet 及工作節點配置,以及叢集範圍的政策設定,然後將每個檢查項目報告為 PASS、FAIL、WARN 或 INFO,並附上直接來自 CIS 指南的修復建議。測試項目由 YAML 檔案驅動配置,因此 kube-bench 能追蹤新的 Kubernetes 版本和基準修訂版,並支援受管發行版(EKS、GKE、AKS、ACK、OpenShift、RKE、k3s)。

根據 CIS 基準來強化叢集可以直接減少 T1610(Deploy Container) 的攻擊面,攻擊者會利用未強化叢集中的特權容器、主機命名空間、匿名 API 存取或不安全的 kubelet 設定來部署容器以執行程式碼或規避防禦。

kube-bench 可以作為節點上的獨立二進位檔、容器內執行,或最常見的是以 Kubernetes Job 的形式執行,其 Pod 會掛載宿主機檔案系統以讀取相關的配置檔。輸出格式支援人類可讀的文字、JSON、JUnit 或 AWS Security Finding Format (ASFF),並可匯入 PostgreSQL 資料庫進行趨勢追蹤。

使用時機

  • 為新的 Kubernetes 叢集根據 CIS Kubernetes 基準建立安全基準。
  • 對控制平面和節點強化進行定期合規稽核。
  • 在套用強化變更後驗證修復效果(重新執行以確認檢查項目已 PASS)。
  • 將叢集合規掃描整合到 CI/CD 或持續監控管線中。
  • 為 SOC 2、PCI DSS 或內部強化合規準備證據。

先決條件

  • 存取叢集:能夠 SSH 到控制平面/工作節點(二進位模式),或擁有 kubectl 並具有建立 Job 的權限(叢集內模式)。
  • 了解叢集的 Kubernetes 版本(kube-bench 會自動偵測,或使用 --version / --benchmark 指定)。
  • 安裝 kube-bench(Aqua Security 官方方法):
# 二進位檔釋出(Linux)
KB_VERSION=0.10.7
curl -L -o kube-bench.tgz \
  "https://github.com/aquasecurity/kube-bench/releases/download/v${KB_VERSION}/kube-bench_${KB_VERSION}_linux_amd64.tar.gz"
tar -xzf kube-bench.tgz
sudo mv kube-bench /usr/local/bin/
sudo cp -R cfg /etc/kube-bench/cfg

# 透過 Go 安裝
go install github.com/aquasecurity/kube-bench@latest

# 直接在節點上以一次性容器執行(掛載宿主機配置)
docker run --rm --pid=host \
  -v /etc:/etc:ro -v /var:/var:ro \
  -t docker.io/aquasec/kube-bench:latest run --targets node

# 驗證
kube-bench version

目標

  • 針對叢集的 Kubernetes 版本執行適當的 kube-bench 基準測試。
  • 掃描控制平面(master)、節點、etcd、控制平面政策以及受管服務目標。
  • 產生機器可讀的 JSON/JUnit 輸出,用於管線和儀表板。
  • 分類處理 FAIL 和 WARN 結果,並套用 CIS 修復指南。
  • 重新執行以驗證修復措施現在已 PASS。

MITRE ATT&CK 對應

技術 ID名稱戰術關聯性
T1610Deploy Container執行 / 防禦規避kube-bench 強制執行的 CIS 基準強化限制了攻擊者在部署惡意容器時經常利用的特權/主機命名空間部署、匿名 API 存取以及不安全的 kubelet 設定。

工作流程

1. 執行預設掃描(自動偵測)

執行所有適用的目標,讓 kube-bench 自動偵測 Kubernetes 版本和基準:

sudo kube-bench

2. 以 Kubernetes Job 執行(叢集內)

套用 kube-bench 儲存庫提供的 Job Manifest,並從 Pod 日誌中讀取結果:

# 通用 Job
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml

# 等待,然後取得結果
kubectl get pods -l app=kube-bench
kubectl logs -l app=kube-bench

# 也可使用平台專用 Job,例如 EKS:
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-eks.yaml

3. 指定目標元件

使用 run --targets 將掃描範圍限定於特定元件群組:

# 控制平面(API Server, Scheduler, Controller Manager)
sudo kube-bench run --targets master

# 工作節點(kubelet, proxy)
sudo kube-bench run --targets node

# etcd 資料儲存
sudo kube-bench run --targets etcd

# 叢集範圍政策(RBAC, Pod Security, Network Policy)
sudo kube-bench run --targets policies

# 組合多個目標
sudo kube-bench run --targets master,node,etcd,policies

4. 指定特定基準或 Kubernetes 版本

當自動偵測錯誤或必須針對特定修訂版進行稽核時,明確指定基準:

# 指定特定 CIS 基準修訂版
sudo kube-bench run --benchmark cis-1.8

# 或透過 Kubernetes 版本對應
sudo kube-bench --version 1.27

# 受管/發行版特定基準
sudo kube-bench run --benchmark eks-1.5.0
sudo kube-bench run --benchmark gke-1.6.0
sudo kube-bench run --benchmark rke2-cis-1.7

5. 執行或跳過個別檢查

在修復週期中專注於或排除特定的檢查 ID:

# 僅執行特定檢查
sudo kube-bench run --targets master --check 1.2.1,1.2.2

# 跳過有噪音/已知可接受的檢查
sudo kube-bench run --targets node --skip 4.2.6

6. 產生機器可讀輸出

輸出 JSON 或 JUnit 格式以便匯入管線、SIEM 或儀表板,並寫入檔案:

# JSON 輸出至檔案
sudo kube-bench run --targets master,node --json --outputfile kube-bench-report.json

# JUnit(用於 CI 測試報告)
sudo kube-bench --junit --outputfile kube-bench-junit.xml

# AWS Security Finding Format(用於 Security Hub)
sudo kube-bench run --targets node --asff

7. 分類與修復 FAIL/WARN 發現

每個失敗的檢查都會顯示修復建議。在節點/Manifest 上套用 CIS 建議的修復,例如在靜態 Pod Manifest 中強化 API Server 旗標:

# 常見控制平面 FAIL 的修復範例:
# CIS 1.2.x — 確保在 API Server 上停用 anonymous-auth。
# 編輯靜態 Pod Manifest 並設定旗標:
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
#   - --anonymous-auth=false
# kubelet 會自動重新啟動靜態 Pod。

# 節點修復範例 — kubelet 配置檔權限(CIS 4.1.x):
sudo chmod 600 /etc/kubernetes/kubelet/kubelet-config.json
sudo chown root:root /etc/kubernetes/kubelet/kubelet-config.json

8. 修復後重新驗證

重新執行相關目標並確認先前失敗的檢查現在已 PASS,然後追蹤隨時間變化的分數:

sudo kube-bench run --targets master --check 1.2.1 --json --outputfile recheck.json

# 可選:將結果持久化至 PostgreSQL 以進行趨勢追蹤
sudo kube-bench run --targets master,node --pgsql

工具與資源

工具 / 資源用途連結
kube-benchCIS Kubernetes 基準檢查器https://github.com/aquasecurity/kube-bench
kube-bench 文件執行 / 平台 / 旗標https://aquasecurity.github.io/kube-bench/
CIS Kubernetes 基準來源強化標準https://www.cisecurity.org/benchmark/kubernetes
Trivy Operator叢集內持續合規 + 漏洞掃描https://github.com/aquasecurity/trivy-operator
kube-hunter補充性滲透測試工具https://github.com/aquasecurity/kube-hunter

驗證標準

  • kube-bench 已安裝(kube-bench version)或已作為 Job 執行。
  • 已針對叢集 Kubernetes 版本的正確基準執行掃描。
  • 已掃描 master、node、etcd 和 policies 目標。
  • 已產生 JSON/JUnit 輸出供管線/儀表板匯入。
  • FAIL 和 WARN 發現已分類並排定優先級。
  • 已將 CIS 修復套用至控制平面 Manifest 和節點配置。
  • 重新執行確認先前失敗的檢查現在已 PASS。
  • 結果已隨時間追蹤(檔案存檔或 PostgreSQL)。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相關技能