关于 config-scan
用于审查应用配置和基础设施即代码安全性的技能,可扫描环境文件、Docker、Kubernetes、Terraform 等配置,并支持扫描配置档和忽略规则。
主要功能
- 01检查环境文件中的密钥与不安全默认值
- 02检查 Docker 安全设置
- 03审查 Kubernetes 清单
- 04发现 Terraform 和 IaC 配置问题
- 05使用扫描配置档与忽略规则
适用场景
- 01部署前审查配置文件
- 02检查 Docker 镜像与 Compose 设置
- 03查找 Kubernetes 工作负载风险
- 04在 CI/CD 中加入配置检查
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ jwynia/ agent-skills --skill config-scan安装后在 Claude Code 中输入/config-scan确认已加载。
详细介绍
配置扫描
对配置文件和基础设施即代码进行安全审查。
快速开始
/config-scan # Scan all config files
/config-scan --docker # Docker files only
/config-scan --k8s # Kubernetes manifests
/config-scan --terraform # Terraform files
/config-scan --env # Environment files
此技能检测的内容
环境文件
.env文件中的密钥- 不安全的默认值
- 缺少必需的安全变量
Docker 安全
- 以 root 身份运行
- 暴露敏感端口
- 不安全的基础镜像
- 缺少安全选项
Kubernetes 安全
- 特权容器
- 缺少资源限制
- 不安全的服务账户
- 网络策略缺口
基础设施即代码
- 权限过大的 IAM 策略
- 公共 S3 存储桶
- 未加密的存储
- 缺少安全组
应用配置
- 启用了调试模式
- 详细的错误消息
- 不安全的默认值
扫描类别
环境文件
扫描文件:.env、.env.*、*.env
| 问题 | 严重程度 | 描述 |
|---|---|---|
| .env 中包含密钥 | 高 | 凭据应使用密钥管理器 |
| 已提交 .env | 严重 | 应将其加入 .gitignore |
| DEBUG=true | 高 | 生产配置中启用了调试模式 |
| 弱密钥 | 中 | 值过短或过于简单 |
检测模式:
# Committed .env files
git ls-files | grep -E '\.env$|\.env\.'
# Secrets in env files
(PASSWORD|SECRET|KEY|TOKEN|CREDENTIAL)=.+
# Debug flags
DEBUG=(true|1|yes)
NODE_ENV=development
Docker 安全
扫描文件:Dockerfile、docker-compose.yml
| 问题 | 严重程度 | 描述 |
|---|---|---|
| USER root | 高 | 容器以 root 身份运行 |
| COPY secrets | 严重 | 密钥被复制到镜像中 |
| Latest 标签 | 中 | 基础镜像未固定版本 |
| 暴露端口 | 低 | 暴露的端口范围过宽 |
| 无健康检查 | 低 | 缺少健康监控 |
检测模式:
# Running as root (no USER directive)
FROM.*\n(?!.*USER)
# Copying secrets
COPY.*\.(pem|key|crt|env)
COPY.*secret
COPY.*password
# Unpinned images
FROM\s+\w+:latest
FROM\s+\w+\s*$
# Dangerous capabilities
--privileged
--cap-add
docker-compose.yml 问题:
# Privileged mode
privileged: true
# All capabilities
cap_add:
- ALL
# Host network
network_mode: host
# Sensitive mounts
volumes:
- /:/host
- /var/run/docker.sock
Kubernetes 安全
扫描文件:*.yaml、*.yml(k8s 清单)
| 问题 | 严重程度 | 描述 |
|---|---|---|
| privileged: true | 严重 | 完全访问主机 |
| runAsRoot | 高 | 容器以 root 身份运行 |
| 无资源限制 | 中 | 存在 DoS 风险 |
| hostNetwork | 高 | Pod 使用主机网络 |
| 无 securityContext | 中 | 缺少安全设置 |
检测模式:
# Privileged containers
securityContext:
privileged: true
# Running as root
securityContext:
runAsUser: 0
runAsNonRoot: false
# Host access
hostNetwork: true
hostPID: true
hostIPC: true
# Dangerous volume mounts
volumes:
- hostPath:
path: /
# Missing limits
# (absence of resources.limits)
# Wildcard RBAC
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
Terraform/IaC
扫描文件:*.tf、*.tfvars
| 问题 | 严重程度 | 描述 |
|---|---|---|
| 公共 S3 存储桶 | 严重 | 数据暴露 |
| IAM 策略中的 * | 高 | 权限过大 |
| 未加密 | 高 | 静态数据未加密 |
| 0.0.0.0/0 入站规则 | 高 | 对互联网开放 |
| 硬编码密钥 | 严重 | TF 中包含凭据 |
检测模式:
# Public S3
acl = "public-read"
acl = "public-read-write"
# Overly permissive IAM
"Action": "*"
"Resource": "*"
"Principal": "*"
# Open security groups
cidr_blocks = ["0.0.0.0/0"]
ingress {
from_port = 0
to_port = 65535
# Missing encryption
encrypted = false
# (or absence of encryption settings)
# Hardcoded secrets
password = "..."
secret_key = "..."
应用配置
扫描文件:config/*.json、*.config.js、application.yml
| 问题 | 严重程度 | 描述 |
|---|---|---|
| DEBUG=true | 高 | 生产环境中启用了调试模式 |
| 详细错误 | 中 | 暴露了堆栈跟踪 |
| CORS * | 高 | 允许所有来源 |
| 无 HTTPS | 中 | 传输未加密 |
检测模式:
// Debug mode
debug: true,
DEBUG: true,
NODE_ENV: 'development'
// Verbose errors
showStackTrace: true
detailedErrors: true
// CORS
origin: '*'
origin: true
Access-Control-Allow-Origin: *
// Session security
secure: false // cookies
httpOnly: false
sameSite: 'none'
输出格式
CONFIG SCAN RESULTS
===================
Files scanned: 23
Issues found: 15
CRITICAL (2)
------------
[!] Dockerfile:1 - Running as root
No USER directive found
Fix: Add "USER node" or similar non-root user
[!] terraform/s3.tf:12 - Public S3 bucket
acl = "public-read"
Fix: Remove public ACL, use bucket policies
HIGH (5)
--------
[H] docker-compose.yml:15 - Privileged container
privileged: true
Fix: Remove privileged flag, use specific capabilities
[H] k8s/deployment.yaml:34 - Missing resource limits
No CPU/memory limits defined
Fix: Add resources.limits section
...
MEDIUM (8)
----------
...
配置
忽略规则
创建 .config-scan-ignore:
# Ignore specific files
files:
- "docker-compose.dev.yml"
- "terraform/modules/test/**"
# Ignore specific rules
rules:
- id: "docker-root-user"
files: ["Dockerfile.dev"]
reason: "Development only"
- id: "k8s-no-limits"
reason: "Handled by LimitRange"
扫描配置
# .config-scan.yaml
profile: production # or: development, strict
# Custom thresholds
thresholds:
fail_on: high
warn_on: medium
# Specific scanners
scanners:
docker: true
kubernetes: true
terraform: true
env_files: true
app_config: true
检查的最佳实践
Docker
- 指定非 root 用户
- 基础镜像固定到摘要
- 构建过程中不包含密钥
- 使用多阶段构建
- 定义健康检查
- 根文件系统为只读
Kubernetes
- 使用非 root 安全上下文
- 定义资源限制
- 配置网络策略
- 不使用特权容器
- 限定服务账户权限
- 静态加密密钥
Terraform
- 加密状态文件
- 不硬编码密钥
- IAM 遵循最小权限原则
- 启用加密
- 启用日志记录
- 默认不允许公共访问
修复示例
Docker:以非 root 身份运行
# Before
FROM node:18
# After
FROM node:18
RUN groupadd -r app && useradd -r -g app app
USER app
Kubernetes:安全上下文
# Before
containers:
- name: app
image: myapp
# After
containers:
- name: app
image: myapp
securityContext:
runAsNonRoot: true
runAsUser: 1000
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
Terraform:私有 S3
# Before
resource "aws_s3_bucket" "data" {
acl = "public-read"
}
# After
resource "aws_s3_bucket" "data" {
# No ACL (private by default)
}
resource "aws_s3_bucket_public_access_block" "data" {
bucket = aws_s3_bucket.data.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
CI/CD 集成
# GitHub Actions
- name: Config Security Scan
run: |
/config-scan --fail-on high
- name: Docker Scan
run: |
/config-scan --docker --fail-on critical
相关技能
/security-scan- 全面安全分析/secrets-scan- 凭据检测/dependency-scan- 软件包漏洞
评论
支持 Markdown