config-scan
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConfig Scan
配置扫描
Security review of configuration files and infrastructure as code.
对配置文件和基础设施即代码(IaC)进行安全审核。
Quick Start
快速开始
/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/config-scan # 扫描所有配置文件
/config-scan --docker # 仅扫描Docker文件
/config-scan --k8s # 扫描Kubernetes清单
/config-scan --terraform # 扫描Terraform文件
/config-scan --env # 扫描环境文件What This Skill Detects
本Skill可检测的内容
Environment Files
环境文件
- Secrets in files
.env - Insecure default values
- Missing required security variables
- .env文件中的敏感凭据
- 不安全的默认值
- 缺失必要的安全变量
Docker Security
Docker安全
- Running as root
- Exposed sensitive ports
- Insecure base images
- Missing security options
- 以root用户运行
- 暴露敏感端口
- 不安全的基础镜像
- 缺失安全选项
Kubernetes Security
Kubernetes安全
- Privileged containers
- Missing resource limits
- Insecure service accounts
- Network policy gaps
- 特权容器
- 缺失资源限制
- 不安全的服务账户
- 网络策略缺口
Infrastructure as Code
基础设施即代码(IaC)
- Overly permissive IAM policies
- Public S3 buckets
- Unencrypted storage
- Missing security groups
- 权限过度宽松的IAM策略
- 公开的S3存储桶
- 未加密的存储
- 缺失安全组
Application Config
应用程序配置
- Debug mode enabled
- Verbose error messages
- Insecure defaults
- 启用调试模式
- 详细错误信息暴露
- 不安全的默认设置
Scan Categories
扫描分类
Environment Files
环境文件
Files scanned: , ,
.env.env.**.env| Issue | Severity | Description |
|---|---|---|
| Secrets in .env | HIGH | Credentials should use secrets manager |
| .env committed | CRITICAL | Should be in .gitignore |
| DEBUG=true | HIGH | Debug mode in production config |
| Weak secrets | MEDIUM | Short or simple values |
Detection patterns:
undefined扫描文件: , ,
.env.env.**.env| 问题 | 严重程度 | 描述 |
|---|---|---|
| .env文件中的敏感凭据 | 高 | 凭据应使用密钥管理器存储 |
| .env文件已提交到版本库 | 关键 | 应将其添加到.gitignore |
| DEBUG=true | 高 | 生产配置中启用调试模式 |
| 弱凭据 | 中 | 凭据值过短或过于简单 |
检测规则:
undefinedCommitted .env files
已提交的.env文件
git ls-files | grep -E '.env$|.env.'
git ls-files | grep -E '.env$|.env.'
Secrets in env files
环境文件中的敏感凭据
(PASSWORD|SECRET|KEY|TOKEN|CREDENTIAL)=.+
(PASSWORD|SECRET|KEY|TOKEN|CREDENTIAL)=.+
Debug flags
调试标志
DEBUG=(true|1|yes)
NODE_ENV=development
undefinedDEBUG=(true|1|yes)
NODE_ENV=development
undefinedDocker Security
Docker安全
Files scanned: ,
Dockerfiledocker-compose.yml| Issue | Severity | Description |
|---|---|---|
| USER root | HIGH | Container runs as root |
| COPY secrets | CRITICAL | Secrets copied into image |
| Latest tag | MEDIUM | Unpinned base image |
| Exposed ports | LOW | Wide port exposure |
| No healthcheck | LOW | Missing health monitoring |
Detection patterns:
dockerfile
undefined扫描文件: ,
Dockerfiledocker-compose.yml| 问题 | 严重程度 | 描述 |
|---|---|---|
| USER root | 高 | 容器以root用户运行 |
| 复制敏感凭据到镜像 | 关键 | 敏感凭据被复制到镜像中 |
| 使用latest标签 | 中 | 基础镜像未固定版本 |
| 暴露端口范围过宽 | 低 | 端口暴露范围过大 |
| 缺失健康检查 | 低 | 未配置健康监控 |
检测规则:
dockerfile
undefinedRunning as root (no USER directive)
以root用户运行(无USER指令)
FROM.*\n(?!.*USER)
FROM.*\n(?!.*USER)
Copying secrets
复制敏感凭据
COPY.*.(pem|key|crt|env)
COPY.*secret
COPY.*password
COPY.*.(pem|key|crt|env)
COPY.*secret
COPY.*password
Unpinned images
未固定版本的镜像
FROM\s+\w+:latest
FROM\s+\w+\s*$
FROM\s+\w+:latest
FROM\s+\w+\s*$
Dangerous capabilities
危险的权限配置
--privileged
--cap-add
**docker-compose.yml issues**:
```yaml--privileged
--cap-add
**docker-compose.yml中的问题**:
```yamlPrivileged mode
特权模式
privileged: true
privileged: true
All capabilities
所有权限
cap_add:
- ALL
cap_add:
- ALL
Host network
主机网络
network_mode: host
network_mode: host
Sensitive mounts
敏感挂载
volumes:
- /:/host
- /var/run/docker.sock
undefinedvolumes:
- /:/host
- /var/run/docker.sock
undefinedKubernetes Security
Kubernetes安全
Files scanned: , (k8s manifests)
*.yaml*.yml| Issue | Severity | Description |
|---|---|---|
| privileged: true | CRITICAL | Full host access |
| runAsRoot | HIGH | Container runs as root |
| No resource limits | MEDIUM | DoS risk |
| hostNetwork | HIGH | Pod uses host network |
| No securityContext | MEDIUM | Missing security settings |
Detection patterns:
yaml
undefined扫描文件: , (Kubernetes清单)
*.yaml*.yml| 问题 | 严重程度 | 描述 |
|---|---|---|
| privileged: true | 关键 | 获得完整主机访问权限 |
| runAsRoot | 高 | 容器以root用户运行 |
| 缺失资源限制 | 中 | 存在拒绝服务(DoS)风险 |
| hostNetwork | 高 | Pod使用主机网络 |
| 缺失securityContext | 中 | 未配置安全设置 |
检测规则:
yaml
undefinedPrivileged containers
特权容器
securityContext:
privileged: true
securityContext:
privileged: true
Running as root
以root用户运行
securityContext:
runAsUser: 0
runAsNonRoot: false
securityContext:
runAsUser: 0
runAsNonRoot: false
Host access
主机访问权限
hostNetwork: true
hostPID: true
hostIPC: true
hostNetwork: true
hostPID: true
hostIPC: true
Dangerous volume mounts
危险的卷挂载
volumes:
- hostPath: path: /
volumes:
- hostPath: path: /
Missing limits
缺失资源限制
(absence of resources.limits)
(未定义resources.limits)
Wildcard RBAC
通配符RBAC规则
rules:
- apiGroups: [""] resources: [""] verbs: ["*"]
undefinedrules:
- apiGroups: [""] resources: [""] verbs: ["*"]
undefinedTerraform/IaC
Terraform/IaC
Files scanned: ,
*.tf*.tfvars| Issue | Severity | Description |
|---|---|---|
| Public S3 bucket | CRITICAL | Data exposure |
| * in IAM policy | HIGH | Overly permissive |
| No encryption | HIGH | Data at rest unencrypted |
| 0.0.0.0/0 ingress | HIGH | Open to internet |
| Hardcoded secrets | CRITICAL | Credentials in TF |
Detection patterns:
hcl
undefined扫描文件: ,
*.tf*.tfvars| 问题 | 严重程度 | 描述 |
|---|---|---|
| 公开的S3存储桶 | 关键 | 数据存在泄露风险 |
| IAM策略中的*通配符 | 高 | 权限过度宽松 |
| 未启用加密 | 高 | 静态数据未加密 |
| 0.0.0.0/0的入站规则 | 高 | 对互联网完全开放 |
| 硬编码敏感凭据 | 关键 | 凭据直接写在Terraform文件中 |
检测规则:
hcl
undefinedPublic S3
公开的S3存储桶
acl = "public-read"
acl = "public-read-write"
acl = "public-read"
acl = "public-read-write"
Overly permissive IAM
权限过度宽松的IAM策略
"Action": ""
"Resource": ""
"Principal": "*"
"Action": ""
"Resource": ""
"Principal": "*"
Open security groups
开放的安全组
cidr_blocks = ["0.0.0.0/0"]
ingress {
from_port = 0
to_port = 65535
cidr_blocks = ["0.0.0.0/0"]
ingress {
from_port = 0
to_port = 65535
Missing encryption
未启用加密
encrypted = false
encrypted = false
(or absence of encryption settings)
(或未配置加密设置)
Hardcoded secrets
硬编码的敏感凭据
password = "..."
secret_key = "..."
undefinedpassword = "..."
secret_key = "..."
undefinedApplication Config
应用程序配置
Files scanned: , ,
config/*.json*.config.jsapplication.yml| Issue | Severity | Description |
|---|---|---|
| DEBUG=true | HIGH | Debug in production |
| Verbose errors | MEDIUM | Stack traces exposed |
| CORS * | HIGH | All origins allowed |
| No HTTPS | MEDIUM | Unencrypted transport |
Detection patterns:
javascript
// 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/*.json*.config.jsapplication.yml| 问题 | 严重程度 | 描述 |
|---|---|---|
| DEBUG=true | 高 | 生产环境中启用调试模式 |
| 详细错误信息暴露 | 中 | 暴露堆栈跟踪信息 |
| CORS设置为* | 高 | 允许所有源访问 |
| 未使用HTTPS | 中 | 传输数据未加密 |
检测规则:
javascript
// 调试模式
debug: true,
DEBUG: true,
NODE_ENV: 'development'
// 详细错误信息
showStackTrace: true
detailedErrors: true
// CORS配置
origin: '*'
origin: true
Access-Control-Allow-Origin: *
// Session安全
secure: false // Cookie设置
httpOnly: false
sameSite: 'none'Output Format
输出格式
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 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)
----------
...Configuration
配置
Ignore Rules
忽略规则
Create :
.config-scan-ignoreyaml
undefined创建文件:
.config-scan-ignoreyaml
undefinedIgnore specific files
忽略特定文件
files:
- "docker-compose.dev.yml"
- "terraform/modules/test/**"
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"
undefinedrules:
-
id: "docker-root-user" files: ["Dockerfile.dev"] reason: "仅用于开发环境"
-
id: "k8s-no-limits" reason: "已通过LimitRange处理"
undefinedScan Profiles
扫描配置文件
yaml
undefinedyaml
undefined.config-scan.yaml
.config-scan.yaml
profile: production # or: development, strict
profile: production # 可选值: development, strict
Custom thresholds
自定义阈值
thresholds:
fail_on: high
warn_on: medium
thresholds:
fail_on: high
warn_on: medium
Specific scanners
启用的扫描器
scanners:
docker: true
kubernetes: true
terraform: true
env_files: true
app_config: true
undefinedscanners:
docker: true
kubernetes: true
terraform: true
env_files: true
app_config: true
undefinedBest Practices Checked
已检查的最佳实践
Docker
Docker
- Non-root user specified
- Base image pinned to digest
- No secrets in build
- Multi-stage build used
- Health check defined
- Read-only root filesystem
- 指定非root用户
- 基础镜像固定到摘要版本
- 构建过程中不包含敏感凭据
- 使用多阶段构建
- 定义健康检查
- 根文件系统设为只读
Kubernetes
Kubernetes
- Non-root security context
- Resource limits defined
- Network policies in place
- No privileged containers
- Service accounts scoped
- Secrets encrypted at rest
- 配置非root用户的securityContext
- 定义资源限制
- 配置网络策略
- 禁用特权容器
- 限制服务账户权限
- 静态敏感凭据已加密
Terraform
Terraform
- State file encrypted
- No hardcoded secrets
- Least privilege IAM
- Encryption enabled
- Logging enabled
- No public access by default
- 状态文件已加密
- 无硬编码敏感凭据
- 遵循最小权限原则配置IAM
- 启用加密
- 启用日志记录
- 默认不允许公共访问
Remediation Examples
修复示例
Docker: Run as Non-Root
Docker: 以非root用户运行
dockerfile
undefineddockerfile
undefinedBefore
修复前
FROM node:18
FROM node:18
After
修复后
FROM node:18
RUN groupadd -r app && useradd -r -g app app
USER app
undefinedFROM node:18
RUN groupadd -r app && useradd -r -g app app
USER app
undefinedKubernetes: Security Context
Kubernetes: 配置安全上下文
yaml
undefinedyaml
undefinedBefore
修复前
containers:
- name: app image: myapp
containers:
- name: app image: myapp
After
修复后
containers:
- name: app image: myapp securityContext: runAsNonRoot: true runAsUser: 1000 readOnlyRootFilesystem: true allowPrivilegeEscalation: false
undefinedcontainers:
- name: app image: myapp securityContext: runAsNonRoot: true runAsUser: 1000 readOnlyRootFilesystem: true allowPrivilegeEscalation: false
undefinedTerraform: Private S3
Terraform: 配置私有S3存储桶
hcl
undefinedhcl
undefinedBefore
修复前
resource "aws_s3_bucket" "data" {
acl = "public-read"
}
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
}
undefinedresource "aws_s3_bucket" "data" {
不设置ACL(默认私有)
}
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
}
undefinedCI/CD Integration
CI/CD集成
yaml
undefinedyaml
undefinedGitHub Actions
GitHub Actions
-
name: Config Security Scan run: | /config-scan --fail-on high
-
name: Docker Scan run: | /config-scan --docker --fail-on critical
undefined-
name: 配置安全扫描 run: | /config-scan --fail-on high
-
name: Docker安全扫描 run: | /config-scan --docker --fail-on critical
undefinedRelated Skills
相关Skill
- - Full security analysis
/security-scan - - Credential detection
/secrets-scan - - Package vulnerabilities
/dependency-scan
- - 全面安全分析
/security-scan - - 凭据检测
/secrets-scan - - 依赖包漏洞检测
/dependency-scan