| name | secrets-management |
| description | Use when working with Vault, SOPS, secret scanning, or managing credentials safely |
Secrets Management
The Rule
SECRETS NEVER GO IN CODE, CONFIGS, OR GIT HISTORY
Mode Detection
- Repo mode — can scan for leaked secrets, set up SOPS, configure Vault integration.
- Chat mode — user pastes config with potential secrets. Flag issues, provide safe alternatives.
Secret Scanning
gitleaks detect --source . --verbose
trufflehog git file://. --only-verified
git log -p | grep -i "password\|secret\|api_key\|token"
If you find a secret in git history:
- Rotate the credential immediately — assume it's compromised
- Use
git filter-repo to remove it from history
- Force-push (coordinate with team first)
- Add the pattern to
.gitleaks.toml to prevent recurrence
SOPS (Secrets OPerationS)
sops --encrypt secrets.yaml > secrets.enc.yaml
sops --decrypt secrets.enc.yaml
sops secrets.enc.yaml
HashiCorp Vault
vault login
vault kv get secret/myapp/database
vault kv put secret/myapp/database password=mysecret
vault kv list secret/myapp
Kubernetes Secrets
kubectl create secret generic db-secret \
--from-literal=password=mysecret
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password
Common Mistakes
| Mistake | Prevention |
|---|
| Secret in environment variable in CI YAML | Use CI secret store — never write value directly |
Secret in Docker ENV instruction | Use secret mounts (--secret) or inject at runtime |
.env file committed to git | Add .env* to .gitignore before first commit |
| Credentials in Terraform state | Use encrypted remote state |
Tooling Templates
tooling/security/vault/ — Vault policies, auth configs
tooling/security/sops/ — .sops.yaml templates
tooling/security/scanning/ — gitleaks, truffleHog configs