Production Checklist
Run through this list before deploying an application that uses env.
Pre-deployment Checks
File Security
- [ ]
.env.productionfile exists - [ ] File permissions are
600or stricter - [ ] Sensitive files added to
.gitignore - [ ] Configuration files contain no placeholders (e.g.,
change-me,xxx)
bash
# Check permissions
ls -la .env.production
# Should show: -rw------- (600)
# Fix permissions
chmod 600 .env.productionConfiguration Validation
- [ ] All required keys are set
- [ ] Sensitive values are not empty
- [ ] Value formats are correct (URLs, ports, etc.)
- [ ] No hardcoded secrets
go
cfg := env.ProductionConfig()
cfg.RequiredKeys = []string{
"DB_HOST", "DB_PORT", "DB_USER", "DB_PASSWORD",
"API_KEY", "API_URL",
}
cfg.FailOnMissingFile = trueSecurity Configuration Checks
Audit Logging
- [ ] Audit logging is enabled
- [ ] Log directory is writable
- [ ] Log file permissions are correct
go
auditFile, err := os.OpenFile("/var/log/app/audit.log",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
log.Fatalf("failed to open audit log: %v", err)
}
cfg.AuditEnabled = true
cfg.AuditHandler = env.NewJSONAuditHandler(auditFile)Audit enabled is not audit persisted
ProductionConfig() sets AuditEnabled = true. With no AuditHandler configured, audit events go to the stderr [AUDIT] log instead of a file. After launch, confirm that the audit log file is actually growing.
Sensitive Data Handling
- [ ] Sensitive values read with
GetSecure - [ ]
Release()called promptly (it zeroes, unlocks, and returns the value to the pool; see Memory Locking) - [ ] Logs do not contain raw sensitive values
go
secret := loader.GetSecure("DB_PASSWORD")
defer secret.Release()
log.Printf("Password length: %d", secret.Length())Access Control
- [ ]
AllowedKeyswhitelist set (recommended) - [ ] Value validation in place — the built-in validator always enforces length and control-character checks; if you swapped in a custom validator, confirm it performs equivalent checks, otherwise keep
ValidateValues = true - [ ] Size limits fit your configuration —
ProductionConfig()setsMaxFileSizeto 64 KB andMaxVariablesto 50; raise them if your config is larger - [ ] Configuration file paths are all relative —
Filenamesrejects absolute paths, UNC paths, URL-encoded%, and..traversal - [ ]
ExpansionScope: ExpansionFileOnlyset for untrusted configuration sources, so.envexpansion cannot capture process secrets (SEC-03) - [ ] Audit handler is not connected to
os.Stdoutor a shared writer —loader.Close()closes the handler;JSONAuditHandleralso closes the underlying writer, whileLogAuditHandlerdoes not
go
cfg.AllowedKeys = []string{"APP_NAME", "DB_HOST", "API_KEY"}
cfg.ValidateValues = true
cfg.MaxVariables = 50 // raise only if you have more keysAt Deployment Checks
- [ ] Configuration files loaded from a secure location
- [ ] Application validates configuration at startup
- [ ] Application refuses to start on configuration error
- [ ] No sensitive information in logs
Post-deployment Checks
- [ ] Application runs normally
- [ ] Audit logs are being written
- [ ] No sensitive information leaked
- [ ] Monitoring covers configuration-related errors
bash
# Health check: confirm the application is alive
curl -fsS http://localhost:8080/healthz > /dev/null && echo "OK: health check passed"
# Confirm the audit log file is actually receiving lines (not just the stderr [AUDIT] fallback)
tail -n 5 /var/log/app/audit.logPre-deploy Check Script
bash
#!/bin/bash
# pre-deploy-check.sh
set -e
echo "=== Pre-deployment Config Check ==="
# Check file exists
[ -f ".env.production" ] || { echo "ERROR: .env.production not found"; exit 1; }
# Check permissions
PERMS=$(stat -c %a .env.production 2>/dev/null || stat -f %Lp .env.production)
[ "$PERMS" = "600" ] || [ "$PERMS" = "400" ] || echo "WARNING: permissions are $PERMS"
# Check for placeholders
grep -qE "(change-?me|placeholder|xxx|YOUR_)" .env.production && \
{ echo "ERROR: Found placeholder values"; exit 1; }
# Check required keys
for key in DB_HOST DB_PORT DB_USER DB_PASSWORD API_KEY; do
grep -q "^$key=" .env.production || { echo "ERROR: Missing $key"; exit 1; }
done
echo "=== All checks passed ==="Related Documentation
- Security Overview - security architecture and built-in defaults
- Data Masking - sensitive values in logs and error output
- Memory Locking - mlock memory protection and the
Release()lifecycle - SecureValue API - secure value handling
- Constants & Errors - forbidden keys list