Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
kubesec — Kubernetes 资源的安全风险分析 | Kitploit
工具/GitHubGitHub/controlplaneio/kubesec
云基础设施安全防御工具静态分析容器安全静态代码分析 (SAST)配置审计云安全DevSecOps错误配置容器逃逸配置审计 分类第 13 名
1.5k108203个月前Kitploit 审核通过

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
容器逃逸 分类第 15 名
容器安全 分类第 9 名
错误配置 分类第 13 名
静态代码分析 (SAST) 分类第 18 名
GitHubcontrolplaneio/kubesec

kubesec

Kubernetes 资源的安全风险分析

查看仓库网站

Kubesec

Testing Workflow Security Analysis Workflow Release Workflow

Go Report Card PkgGoDev

🚨 v1 API 已弃用,请阅读 发布说明 🚨

Kubernetes 资源安全风险分析

🎬 演示

Kubesec CLI 演示

更多示例请访问 Kubesec.io,它使用 ControlPlane 托管的 API,地址为 v2.kubesec.io/scan。


  • 快速开始
  • 下载 Kubesec
  • 使用示例
    • 扫描
      • Docker 用法
      • 输出格式
    • 打印规则
    • 自定义 Schema
  • HTTP 服务器模式
  • Kubesec 即服务
  • 贡献
  • 获取帮助
  • 更新日志

🚀 快速开始

1. 准备你的清单

创建一个要扫描的 Kubernetes 资源文件(例如 kubesec-test.yaml)。为了快速测试,你可以保存以下 Pod 清单:

root@kitploit:~
$ cat <<EOF > kubesec-test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: kubesec-demo
spec:
  containers:
  - name: kubesec-demo
    image: gcr.io/google-samples/node-hello:1.0
    securityContext:
      readOnlyRootFilesystem: true
EOF

2. 运行你的第一次扫描

对你的清单文件执行扫描:

root@kitploit:~
# Using the local binary
kubesec scan kubesec-test.yaml

# Or using Docker
docker run -i kubesec/kubesec:v2 scan /dev/stdin < kubesec-test.yaml

# Using the local binary with a human-readable table output format
kubesec scan kubesec-test.yaml --format table

[!TIP] 要以人类可读的表格(而非默认的 JSON 格式)查看结果,请使用 --format table 标志

kubesec 将输出安全评分以及对你资源的详细分析。

📦 下载 Kubesec

Kubesec 可通过以下方式获取:

  • Docker 容器镜像(docker.io/kubesec/kubesec:v2)
  • Linux/MacOS/Win 二进制文件(获取最新版本)
  • Kubernetes 准入控制器
  • Kubectl 插件

或者使用以下命令从 GitHub 安装最新提交:

Go 1.16+

root@kitploit:~
$ go install github.com/controlplaneio/kubesec/v2@latest

Go 版本 < 1.16

root@kitploit:~
$ GO111MODULE="on" go get github.com/controlplaneio/kubesec/v2

📖 使用示例

扫描

从本地文件或标准输入扫描 Kubernetes 资源。

Kubesec 可以扫描单个输入文件中的多个 YAML 文档,也可以一次扫描多个文件中的文档,只要这些文档按照 --- 正确分隔为多个文档即可。

root@kitploit:~
# Scan a specific local YAML file
kubesec scan ./deployment.yaml

# Scan from standard input (JSON or YAML)
cat file.json | kubesec scan -

# Scan a rendered Helm chart
helm template -f values.yaml ./chart | kubesec scan /dev/stdin

# Scan multiple YAML documents separated by '---'
{ cat test/asset/multi.yml; echo "---"; cat test/asset/critical.yml; } | kubesec scan -

Docker 用法

你可以使用官方 Docker 镜像运行相同的扫描命令:

root@kitploit:~
# Scan a file via Docker using standard input
docker run -i kubesec/kubesec:v2 scan /dev/stdin < kubesec-test.yaml

输出格式

Kubesec 支持三种不同的输出格式,通过 --format / -f 标志指定:json(默认)、table 和 template,并且可以扫描单个输入文件中的多个 YAML 文档。

root@kitploit:~
# JSON array output (default behaviour)
kubesec scan ./deployment.yaml --format json

# Human-readable table output
kubesec scan ./deployment.yaml --format table

# Use a custom template for the output
kubesec scan ./deployment.yaml --format template --template report-template.tmpl

扫描特定规则

root@kitploit:~
# One rule
kubesec scan --rules CapSysAdmin kubesec-test.yaml

# Multiple rules
kubesec scan --rules RunAsNonRoot,SeccompAny,ApparmorAny kubesec-test.yaml
JSON 输出示例
root@kitploit:~
[
  {
    "object": "Pod/security-context-demo.default",
    "valid": true,
    "message": "Failed with a score of -30 points",
    "score": -30,
    "scoring": {
      "critical": [
        {
          "selector": "containers[] .securityContext .capabilities .add == SYS_ADMIN",
          "reason": "CAP_SYS_ADMIN is the most privileged capability and should always be avoided",
          "points": -30
        }
      ],
      "advise": [
        {
          "selector": "containers[] .securityContext .runAsNonRoot == true",
          "reason": "Force the running image to run as a non-root user to ensure least privilege",
          "points": 1
        },
        {
          // ...
        }
      ]
    }
  }
]
表格输出示例

表格输出

打印规则

root@kitploit:~
# Print all scanning rules with their associated point scores
kubesec print-rules

# Print all scanning rules with their associated point scores as a table
kubesec print-rules --format table

规则输出 JSON 示例

root@kitploit:~
[
  {
    "id": "AllowPrivilegeEscalation",
    "selector": "containers[] .securityContext .allowPrivilegeEscalation == true",
    "reason": "Ensure a non-root process can not gain more privileges",
    "kinds": [
      "Pod",
      "Deployment",
      "StatefulSet",
      "DaemonSet"
    ],
    "points": -7,
    "advise": 0
  },
...
]

自定义 Schema

Kubesec 利用 kubeconform(感谢 @yannh)来验证要扫描的清单。这意味着指定不同的 schema 位置需要遵循 kubeconform README 中描述的规则。

root@kitploit:~
# Usees the latest schema from upstream
# Schema will be fetched from: https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone-strict/pod-v1.json
kubesec scan ./pod.yaml

# Use a specific schema version from upstream (format x.y.z with no v prefix)
# Schema will be fetched from: https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.25.3-standalone-strict/pod-v1.json
kubesec scan ./pod.yaml --kubernetes-version 1.25.3

# Use a specific schema version in an airgapped environment over HTTP
# Schema will be fetched from: `https://host.server/v<version>-standalone-strict/pod-v1.json`
kubesec scan ./deployment.yaml --kubernetes-version <version> --schema-location https://host.server

# Use a specific schema version in an airgap environment with local files
# Schema will be read from: `/opt/schemas/v<version>-standalone-strict/pod-v1.json`
kubesec scan ./deployment.yaml --kubernetes-version <version> --schema-location /opt/schemas

注意: 为了限制外部网络调用并支持在离线(airgap)环境中使用,kubesec 镜像内嵌了 schema。如果你希望更改 schema 位置,则需要在运行时更改 K8S_SCHEMA_VER 和 SCHEMA_LOCATION 环境变量。

HTTP 服务器模式

Kubesec 内置了一个 HTTP 服务器,你可以在本地或容器中运行它,以通过网络接受扫描请求。

CLI 用法

root@kitploit:~
# Start the HTTP server in the background on port 8080
kubesec http 8080 &

# Send a file to the running server via POST
curl -sSX POST --data-binary @deployment.yaml http://localhost:8080/scan

# Stop the background local server when finished
kill %

Docker 用法

root@kitploit:~
# Start the HTTP server using Docker
docker run -d -p 8080:8080 kubesec/kubesec:v2 http 8080

# Send a file to the running server via POST
curl -sSX POST --data-binary @deployment.yaml http://localhost:8080/scan

别忘了停止服务器。

Kubesec 即服务

Kubesec 还可通过 HTTPS 在 v2.kubesec.io/scan 上使用。

请勿向此公共服务提交敏感 YAML。

该服务基于良好信誉和尽力而为的原则运行。

root@kitploit:~
# Submit a manifest directly to the hosted v2 API
curl -sSX POST --data-binary @"deployment.yaml" https://v2.kubesec.io/scan

# Parse the API output using jq to return a non-zero exit code if the score is <= 10
curl -sSX POST --data-binary @"deployment.yaml" https://v2.kubesec.io/scan | jq --exit-status '.score > 10'

# Use the "rule" query parameter to scan only specific rules (multiple supported)
curl -sSX POST --data-binary @test/asset/score-0-cap-sys-admin.yml "http://localhost:8080/scan?rule=SeccompAny&rule=ApparmorAny"

你还可以定义一个 Bash 函数,例如:

root@kitploit:~
# Define a BASH function
$ kubesec ()
{
    local FILE="${1:-}";
    [[ ! -e "${FILE}" ]] && {
        echo "kubesec: ${FILE}: No such file" >&2;
        return 1
    };
    curl --silent \
      --compressed \
      --connect-timeout 5 \
      -sSX POST \
      --data-binary=@"${FILE}" \
      https://v2.kubesec.io/scan
}


# POST a Kubernetes resource to v2.kubesec.io/scan
$ kubesec ./deployment.yml

# Return non-zero status code is the score is not greater than 10
$ kubesec ./score-9-deployment.yml | jq --exit-status '.score > 10' >/dev/null
# status code 1

贡献

查看 CONTRIBUTING.md 了解更多信息。

获取帮助

如果你对 Kubesec 和 Kubernetes 安全有任何疑问:

  • 阅读 Kubesec 文档
  • 在 Twitter 上联系 @sublimino 或 @controlplaneio
  • 提交 issue

我们始终欢迎你的反馈!


由 ControlPlane 用 ❤ 制作

下载工具