当前位置: 首页 > Skill >

Config Drift Scanner

Config Drift Scanner

Config Drift Scanner

Detect configuration drift across environments (dev, staging, production). Compare config files, environment variables, feature flags, and secrets across dep...

1.0.1 2026.11.20 165
获取Skill文件查看使用说明
作 者:顾禾 许可证: 更新时间:2026.11.20
本文目录展开

Config Drift Scanner

Find configuration differences across your environments before they cause incidents. Compare config files, environment variables, feature flags, database settings, and runtime parameters between dev/staging/production — catching the "works on my machine" problems that slip past code review.

Use when: "compare configs between environments", "find config drift", "why does staging work but prod doesn't", "audit environment parity", "check env vars across deploys", or after an incident caused by config mismatch.

Commands

1. scan — Detect Drift Across Environments

Step 1: Discover Configuration Sources

# Find config files in the project
find . -maxdepth 4 ( 
  -name "*.env" -o -name "*.env.*" -o 
  -name "*.config.*" -o -name "config.yaml" -o -name "config.json" -o 
  -name "*.toml" -o -name "settings.*" -o 
  -name "docker-compose*.yml" -o -name "docker-compose*.yaml" -o 
  -name "values*.yaml" -o -name "*.tfvars" 
  ) -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null

# Find environment variable references in code
rg "process.env.|os.environ|os.getenv|ENV[|System.getenv" 
  --type-not binary -g '!node_modules' -g '!vendor' --stats 2>&1 | tail -5

Step 2: Extract Config from Each Environment

For Kubernetes:

# ConfigMaps
for env in dev staging prod; do
  kubectl get configmaps -n "$env" -o json | python3 -c "
import json, sys
cms = json.load(sys.stdin)['items']
for cm in cms:
    name = cm['metadata']['name']
    for k, v in cm.get('data', {}).items():
        print(f'{name}.{k}={v}')
" > "/tmp/config-$env.txt"
done

For .env files:

# Compare .env files across environments
for f in .env.development .env.staging .env.production; do
  if [[ -f "$f" ]]; then
    echo "=== $f ==="
    grep -v '^#' "$f" | grep -v '^$' | sort
  fi
done

For Terraform:

# Compare tfvars across environments
for f in terraform/environments/*/terraform.tfvars; do
  echo "=== $f ==="
  cat "$f"
done

Step 3: Diff and Classify

Compare each key across environments and classify differences:

🔴 Dangerous Drift (same key, unexpected difference):

  • Database connection strings pointing to wrong environment
  • API keys that should be environment-specific but are shared
  • Feature flags enabled in prod but disabled in staging (testing gap)
  • Timeout values that differ without documented reason
  • Memory/CPU limits that are lower in prod than staging

🟡 Expected Drift (different by design):

  • Database URLs (each env has its own DB)
  • API endpoints (staging.api.com vs api.com)
  • Log levels (DEBUG in dev, INFO in prod)
  • Replica counts (1 in dev, 3 in prod)

🟢 Missing in Environment (potential problem):

  • Env var exists in prod but not staging → can't test that code path
  • Config key exists in staging but not prod → forgot to add on deploy

Step 4: Generate Report

# Configuration Drift Report

## Environments Compared: dev ↔ staging ↔ production

## 🔴 Dangerous Drift (3 found)
1. `DATABASE_POOL_SIZE`: dev=5, staging=10, **prod=5**
   → Prod should be ≥ staging. Likely copy-paste from dev config.

2. `FEATURE_NEW_CHECKOUT`: dev=true, staging=true, **prod=false**
   → Feature tested in staging but not enabled in prod. Intentional? If so, document.

3. `REDIS_TIMEOUT_MS`: dev=5000, **staging=500**, prod=5000
   → Staging has 10× shorter timeout. Will mask timeout bugs in staging tests.

## 🟡 Expected Drift (8 found)
- DATABASE_URL: different per environment ✅
- LOG_LEVEL: debug/info/warn ✅
- API_BASE_URL: per-environment ✅

## 🟢 Missing Variables (2 found)
- `SENTRY_DSN`: exists in prod, missing in staging → errors not tracked in staging
- `RATE_LIMIT_RPS`: exists in prod (100), missing in dev/staging → no rate limit testing

## Recommendations
1. Add SENTRY_DSN to staging for error visibility
2. Fix DATABASE_POOL_SIZE in prod (should be ≥ staging value)
3. Document why FEATURE_NEW_CHECKOUT differs between staging and prod

2. watch — Continuous Drift Monitoring

Set up a CI check that runs on every config change:

# GitHub Actions
name: Config Drift Check
on:
  push:
    paths:
      - '**/*.env*'
      - '**/config.*'
      - '**/values*.yaml'
      - '**/*.tfvars'
jobs:
  drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Check for drift
        run: |
          # Compare all env files and flag dangerous differences
          diff <(grep -v '^#' .env.staging | sort) <(grep -v '^#' .env.production | sort) || true

3. template — Generate Config Parity Checklist

For a new environment setup, generate a checklist of all config keys that need to be set, with:

  • Required vs optional
  • Expected value ranges
  • Whether the value should differ or match other environments
  • Where to get the value (secrets manager, team lead, auto-generated)

4. secrets-check — Verify Secret Rotation

Cross-reference config with secrets management:

  • Which secrets are hardcoded vs pulled from vault/secrets manager?
  • When were secrets last rotated?
  • Are any secrets shared across environments (bad practice)?
  • Are test/dev credentials accidentally in prod config?

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,034
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,031
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,019
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,017
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,014
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,013
Skill 文件
  • SKILL.md
    • Config Drift Scanner
    • Commands
      • 1. scan — Detect Drift Across Environments
        • Step 1: Discover Configuration Sources
        • Step 2: Extract Config from Each Environment
        • Step 3: Diff and Classify
        • Step 4: Generate Report
      • 2. watch — Continuous Drift Monitoring
      • 3. template — Generate Config Parity Checklist
      • 4. secrets-check — Verify Secret Rotation
  • 项目或源文件

相关 Skill

更多
Codex Agent Codex Agent 作为项目经理全面操作 OpenAI Codex CLI。包含:知识库维护(自动跟踪 Codex 最新功能)、任务执行(提示词设计→执行→监控→质量检查→迭代→报告)、配置管理(feature flags/模型/skills/MCP)。通过 tmux 操作交互式 TUI,通过 notify hooks + pa...
Codex Agent Enhanced Codex Agent Enhanced 作为项目经理全面操作 OpenAI Codex CLI。包含:知识库维护(自动跟踪 Codex 最新功能)、任务执行(提示词设计→执行→监控→质量检查→迭代→报告)、配置管理(feature flags/模型/skills/MCP)。通过 tmux 操作交互式 TUI,通过 notify hooks + pa...
Feature Flags Feature Flags 深度功能开关工作流——涵盖分类、定向、生命周期、安全开关与熔断、清理及治理。适用于渐进式发布、实验或...
gy4 gy4 Use when looking for unused functions, stale modules, unreachable branches, obsolete feature flags, or code that appears safe to delete.
relay-knowledge-cli relay-knowledge-cli Use relay-knowledge local CLI as an agent knowledge backend for repository knowledge graphs and GraphRAG: repo query --kind hybrid/symbol/definition/references/callers/callees/imports/sbom; repo software --kind dependencies/sdks/files/topics/relationships/build/iac/design/all; feature flags/config gates; indexing, impact, setup, install/upgrade diagnostics. Use for 用户代码查询kind/查询类型, 图关系, 调用关系, 导入依赖, 软件依赖, SDK/API, 代码地图, definitions, references, usage, impact. For large cold repo indexing, do not