Config Manager
Audits and improves configuration management — detects hardcoded secrets, generates .env templates with documentation, validates all required environment variables on startup, and optionally sets up feature flag patterns for progressive rollout.
When to Use
- User asks to "manage configuration", "audit for hardcoded secrets", or "set up env vars"
- A code review flagged hardcoded credentials or connection strings
- A new deployment environment needs its configuration documented
- The application crashes on missing config with unhelpful errors
- User wants to implement feature flags for progressive feature rollout
- Secrets have been accidentally committed and need to be cleaned up
Process
Scan for hardcoded secrets and configuration:
- Search for patterns matching:
- API keys:
sk-, pk-, AKIA (AWS), ghp_, glpat-
- Connection strings:
postgres://, mongodb+srv://, redis:// with credentials
- JWT secrets:
secret: "...", jwtSecret =
- Passwords:
password = "...", db_pass =
- Tokens: long hex/base64 strings assigned to variables named
*token*, *key*, *secret*
- Flag file:line for each finding with severity (Critical if committed to git history)
Inventory all configuration the application reads:
- Search for
process.env.*, os.environ[*], os.getenv(*), viper.Get*, config.*
- Collect all variable names, their usage context, and whether they have defaults
- Classify: required (no default, app won't function), optional (has default), feature flag (boolean)
Generate .env.example (a template — never the actual .env):
- List every discovered variable
- Add a descriptive comment for each explaining what it's for, acceptable values, and format
- Provide safe placeholder values (not real secrets)
- Group variables by concern (database, auth, external services, features, etc.)
- Mark required variables clearly with a comment:
# REQUIRED
Generate a config validation module that runs at startup:
- Read all required variables
- Validate format where applicable (URL format, integer range, enum values)
- Fail fast on startup with a clear error message listing every missing/invalid variable
- Never crash mid-request due to missing config
Generate feature flag patterns if requested:
- Simple env-based flags:
FEATURE_NEW_DASHBOARD=true
- Percentage rollout:
FEATURE_ROLLOUT_PERCENTAGE=20
- Per-user targeting: integrate with LaunchDarkly, Unleash, or Flagsmith
- Provide a
isFeatureEnabled(flag, userId?) utility function
Provide git remediation guidance if secrets are found in git history:
- Advise rotating the exposed secret immediately
- Provide BFG Repo-Cleaner or
git filter-repo commands to purge from history
- Note that force-push is required and all collaborators must re-clone
Output Format
Secret Scan Results
## Configuration Audit
### 🔴 Hardcoded Secrets Found
| File | Line | Type | Action Required |
|------|------|------|----------------|
| src/db/connection.ts | 12 | PostgreSQL connection string with password | Rotate & move to env var |
| config/auth.js | 34 | JWT secret (hardcoded string) | Rotate & move to env var |
**Immediate action:** These may be in git history. Rotate both secrets NOW, then
remove from source using `git filter-repo`.
.env.example
# =============================================================================
# Database Configuration
# =============================================================================
# REQUIRED — PostgreSQL connection string
# Format: postgresql://USER:PASSWORD@HOST:PORT/DBNAME
DATABASE_URL=postgresql://app:changeme@localhost:5432/myapp_dev
# =============================================================================
# Authentication
# =============================================================================
# REQUIRED — JWT signing secret (min 32 chars)
# Generate: openssl rand -hex 32
JWT_SECRET=replace_with_a_secure_random_value_at_least_32_chars
# =============================================================================
# Feature Flags
# =============================================================================
# Optional — Enable new dashboard UI (default: false)
FEATURE_NEW_DASHBOARD=false
Config Validation Module (TypeScript)
// src/config/index.ts
import { z } from 'zod';
const ConfigSchema = z.object({
DATABASE_URL: z.string().url('DATABASE_URL must be a valid URL'),
JWT_SECRET: z.string().min(32, 'JWT_SECRET must be at least 32 characters'),
PORT: z.coerce.number().int().min(1).max(65535).default(3000),
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
FEATURE_NEW_DASHBOARD: z.enum(['true', 'false']).transform(v => v === 'true').default('false'),
});
const result = ConfigSchema.safeParse(process.env);
if (!result.success) {
console.error('❌ Invalid configuration:\n', result.error.flatten().fieldErrors);
process.exit(1);
}
export const config = result.data;
Examples
Example Input
# config.py
DATABASE_URL = "postgresql://admin:SuperSecret123@prod.db.example.com/mydb"
API_KEY = "sk-live-abc123xyz"
DEBUG = True
Example Output
🔴 Critical: 2 hardcoded secrets found.
1. DATABASE_URL contains credentials (line 2) — rotate database password immediately
2. API_KEY contains a live API key (line 3) — revoke and regenerate
Recommended refactor:
```python
# config.py
import os
DATABASE_URL = os.environ["DATABASE_URL"] # required
API_KEY = os.environ["API_KEY"] # required
DEBUG = os.environ.get("DEBUG", "false").lower() == "true" # optional, default false
Add to .env.example:
DATABASE_URL=postgresql://user:password@localhost:5432/myapp_dev
API_KEY=your_api_key_here
DEBUG=false
## Boundaries
- Do NOT create or populate `.env` files — only `.env.example` with placeholder values.
- Do NOT display discovered secret values in output — mask after the first 4 characters (e.g., `sk-li...`).
- Do NOT attempt to rotate secrets — only advise that rotation is required and provide instructions.
- Do NOT recommend committing secrets to the repository in any form, including "encrypted in the repo".
- If secrets are found in git history, note that deleting the file is insufficient — history must be rewritten.
- Always recommend using a secrets manager (AWS Secrets Manager, Vault, GCP Secret Manager) for production rather than plain environment variables for highly sensitive values.
1---2name: config-manager3description: Manages environment variables, secrets, and feature flags — generates .env templates, validates required keys, and flags hardcoded secrets. Invoke when asked to manage configuration, audit for hardcoded secrets, generate .env templates, validate environment variables, or set up feature flags.4---56# Config Manager78Audits and improves configuration management — detects hardcoded secrets, generates `.env` templates with documentation, validates all required environment variables on startup, and optionally sets up feature flag patterns for progressive rollout.910## When to Use1112- User asks to "manage configuration", "audit for hardcoded secrets", or "set up env vars"13- A code review flagged hardcoded credentials or connection strings14- A new deployment environment needs its configuration documented15- The application crashes on missing config with unhelpful errors16- User wants to implement feature flags for progressive feature rollout17- Secrets have been accidentally committed and need to be cleaned up1819## Process20211. **Scan for hardcoded secrets and configuration**:22 - Search for patterns matching:23 - API keys: `sk-`, `pk-`, `AKIA` (AWS), `ghp_`, `glpat-`24 - Connection strings: `postgres://`, `mongodb+srv://`, `redis://` with credentials25 - JWT secrets: `secret: "..."`, `jwtSecret =`26 - Passwords: `password = "..."`, `db_pass =`27 - Tokens: long hex/base64 strings assigned to variables named `*token*`, `*key*`, `*secret*`28 - Flag file:line for each finding with severity (Critical if committed to git history)29302. **Inventory all configuration the application reads**:31 - Search for `process.env.*`, `os.environ[*]`, `os.getenv(*)`, `viper.Get*`, `config.*`32 - Collect all variable names, their usage context, and whether they have defaults33 - Classify: required (no default, app won't function), optional (has default), feature flag (boolean)34353. **Generate `.env.example`** (a template — never the actual `.env`):36 - List every discovered variable37 - Add a descriptive comment for each explaining what it's for, acceptable values, and format38 - Provide safe placeholder values (not real secrets)39 - Group variables by concern (database, auth, external services, features, etc.)40 - Mark required variables clearly with a comment: `# REQUIRED`41424. **Generate a config validation module** that runs at startup:43 - Read all required variables44 - Validate format where applicable (URL format, integer range, enum values)45 - Fail fast on startup with a clear error message listing every missing/invalid variable46 - Never crash mid-request due to missing config47485. **Generate feature flag patterns** if requested:49 - Simple env-based flags: `FEATURE_NEW_DASHBOARD=true`50 - Percentage rollout: `FEATURE_ROLLOUT_PERCENTAGE=20`51 - Per-user targeting: integrate with LaunchDarkly, Unleash, or Flagsmith52 - Provide a `isFeatureEnabled(flag, userId?)` utility function53546. **Provide git remediation guidance** if secrets are found in git history:55 - Advise rotating the exposed secret immediately56 - Provide BFG Repo-Cleaner or `git filter-repo` commands to purge from history57 - Note that force-push is required and all collaborators must re-clone5859## Output Format6061### Secret Scan Results62```63## Configuration Audit6465### 🔴 Hardcoded Secrets Found6667| File | Line | Type | Action Required |68|------|------|------|----------------|69| src/db/connection.ts | 12 | PostgreSQL connection string with password | Rotate & move to env var |70| config/auth.js | 34 | JWT secret (hardcoded string) | Rotate & move to env var |7172**Immediate action:** These may be in git history. Rotate both secrets NOW, then73remove from source using `git filter-repo`.74```7576### `.env.example`77```bash78# =============================================================================79# Database Configuration80# =============================================================================81# REQUIRED — PostgreSQL connection string82# Format: postgresql://USER:PASSWORD@HOST:PORT/DBNAME83DATABASE_URL=postgresql://app:changeme@localhost:5432/myapp_dev8485# =============================================================================86# Authentication87# =============================================================================88# REQUIRED — JWT signing secret (min 32 chars)89# Generate: openssl rand -hex 3290JWT_SECRET=replace_with_a_secure_random_value_at_least_32_chars9192# =============================================================================93# Feature Flags94# =============================================================================95# Optional — Enable new dashboard UI (default: false)96FEATURE_NEW_DASHBOARD=false97```9899### Config Validation Module (TypeScript)100```ts101// src/config/index.ts102import { z } from 'zod';103104const ConfigSchema = z.object({105 DATABASE_URL: z.string().url('DATABASE_URL must be a valid URL'),106 JWT_SECRET: z.string().min(32, 'JWT_SECRET must be at least 32 characters'),107 PORT: z.coerce.number().int().min(1).max(65535).default(3000),108 NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),109 FEATURE_NEW_DASHBOARD: z.enum(['true', 'false']).transform(v => v === 'true').default('false'),110});111112const result = ConfigSchema.safeParse(process.env);113if (!result.success) {114 console.error('❌ Invalid configuration:\n', result.error.flatten().fieldErrors);115 process.exit(1);116}117118export const config = result.data;119```120121## Examples122123### Example Input124```python125# config.py126DATABASE_URL = "postgresql://admin:SuperSecret123@prod.db.example.com/mydb"127API_KEY = "sk-live-abc123xyz"128DEBUG = True129```130131### Example Output132```133🔴 Critical: 2 hardcoded secrets found.1341351. DATABASE_URL contains credentials (line 2) — rotate database password immediately1362. API_KEY contains a live API key (line 3) — revoke and regenerate137138Recommended refactor:139```python140# config.py141import os142143DATABASE_URL = os.environ["DATABASE_URL"] # required144API_KEY = os.environ["API_KEY"] # required145DEBUG = os.environ.get("DEBUG", "false").lower() == "true" # optional, default false146```147148Add to .env.example:149DATABASE_URL=postgresql://user:password@localhost:5432/myapp_dev150API_KEY=your_api_key_here151DEBUG=false152```153154## Boundaries155156- Do NOT create or populate `.env` files — only `.env.example` with placeholder values.157- Do NOT display discovered secret values in output — mask after the first 4 characters (e.g., `sk-li...`).158- Do NOT attempt to rotate secrets — only advise that rotation is required and provide instructions.159- Do NOT recommend committing secrets to the repository in any form, including "encrypted in the repo".160- If secrets are found in git history, note that deleting the file is insufficient — history must be rewritten.161- Always recommend using a secrets manager (AWS Secrets Manager, Vault, GCP Secret Manager) for production rather than plain environment variables for highly sensitive values.