mcpField
C
config-scan

config-scan

github.com/jwynia安全179338 次安装35 周前更新
代码仓库

关于 config-scan

用于审查应用配置和基础设施即代码安全性的技能,可扫描环境文件、Docker、Kubernetes、Terraform 等配置,并支持扫描配置档和忽略规则。

主要功能

  1. 01检查环境文件中的密钥与不安全默认值
  2. 02检查 Docker 安全设置
  3. 03审查 Kubernetes 清单
  4. 04发现 Terraform 和 IaC 配置问题
  5. 05使用扫描配置档与忽略规则

适用场景

  1. 01部署前审查配置文件
  2. 02检查 Docker 镜像与 Compose 设置
  3. 03查找 Kubernetes 工作负载风险
  4. 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