5.5 KiB
5.5 KiB
Production Secrets Management
Overview
This directory contains encrypted production secrets managed with Ansible Vault.
Security Model:
- Secrets are encrypted at rest with AES256
- Vault password is required for deployment
- Decrypted files are NEVER committed to git
- Production deployment uses secure SSH key authentication
Files
production-vault.yml- Encrypted secrets vault (safe to commit).gitignore- Prevents accidental commit of decrypted files
Quick Start
1. Initialize Secrets (First Time)
cd deployment
./scripts/setup-production-secrets.sh init
This will:
- Generate secure random passwords/keys
- Create encrypted vault file
- Prompt for vault password (store in password manager!)
2. Deploy Secrets to Production
./scripts/setup-production-secrets.sh deploy
Or via Gitea Actions:
- Go to: https://git.michaelschiemer.de/michael/framework/actions
- Select "Update Production Secrets" workflow
- Click "Run workflow"
- Enter vault password
- Click "Run"
3. Update Secrets Manually
# Edit encrypted vault
ansible-vault edit deployment/ansible/secrets/production-vault.yml
# Deploy changes
./scripts/setup-production-secrets.sh deploy
4. Rotate Secrets (Monthly Recommended)
./scripts/setup-production-secrets.sh rotate
This will:
- Generate new passwords
- Update vault
- Deploy to production
- Restart services
Vault Structure
# Database
vault_db_name: framework_production
vault_db_user: framework_app
vault_db_password: [auto-generated 32 chars]
# Redis
vault_redis_password: [auto-generated 32 chars]
# Application
vault_app_key: [auto-generated base64 key]
vault_jwt_secret: [auto-generated 64 chars]
# Docker Registry
vault_registry_url: git.michaelschiemer.de:5000
vault_registry_user: deploy
vault_registry_password: [auto-generated 24 chars]
# Security
vault_admin_allowed_ips: "127.0.0.1,::1,94.16.110.151"
Security Best Practices
DO ✅
- DO encrypt vault with strong password
- DO store vault password in password manager
- DO rotate secrets monthly
- DO use
--ask-vault-passfor deployments - DO commit encrypted vault to git
- DO use different vault passwords per environment
DON'T ❌
- DON'T commit decrypted vault files
- DON'T share vault password via email/chat
- DON'T use weak vault passwords
- DON'T decrypt vault on untrusted systems
- DON'T hardcode secrets in code
Ansible Vault Commands
# Encrypt file
ansible-vault encrypt production-vault.yml
# Decrypt file (for viewing only)
ansible-vault decrypt production-vault.yml
# Edit encrypted file
ansible-vault edit production-vault.yml
# Change vault password
ansible-vault rekey production-vault.yml
# View encrypted file content
ansible-vault view production-vault.yml
Deployment Integration
Local Deployment
cd deployment/ansible
ansible-playbook -i inventory/production.yml \
playbooks/setup-production-secrets.yml \
--ask-vault-pass
CI/CD Deployment (Gitea Actions)
Vault password stored as Gitea Secret:
- Secret name:
ANSIBLE_VAULT_PASSWORD - Used in workflow:
.gitea/workflows/update-production-secrets.yml
Docker Secrets Integration
Secrets are deployed as Docker Secrets for secure runtime access:
# List deployed secrets on production
ssh deploy@94.16.110.151 "docker secret ls"
# Services automatically use secrets via docker-compose
services:
web:
secrets:
- db_password
- redis_password
- app_key
Troubleshooting
"Decryption failed" Error
Cause: Wrong vault password
Solution:
# Verify password works
ansible-vault view deployment/ansible/secrets/production-vault.yml
# If forgotten, you must reinitialize (data loss!)
./scripts/setup-production-secrets.sh init
Secrets Not Applied After Deployment
Solution:
# Manually restart services
ssh deploy@94.16.110.151 "docker service update --force framework_web"
# Or use Ansible
cd deployment/ansible
ansible-playbook -i inventory/production.yml playbooks/restart-services.yml
Verify Secrets on Production
./scripts/setup-production-secrets.sh verify
# Or manually
ssh deploy@94.16.110.151 "docker secret ls"
ssh deploy@94.16.110.151 "cat /home/deploy/secrets/.env.production | grep -v PASSWORD"
Emergency Procedures
Lost Vault Password
Recovery Steps:
- Backup current vault:
cp production-vault.yml production-vault.yml.lost - Reinitialize vault:
./scripts/setup-production-secrets.sh init - Update database passwords manually on production
- Deploy new secrets:
./scripts/setup-production-secrets.sh deploy
Compromised Secrets
Immediate Response:
- Rotate all secrets:
./scripts/setup-production-secrets.sh rotate - Review access logs on production
- Update vault password:
ansible-vault rekey production-vault.yml - Audit git commit history
- Investigate compromise source
Monitoring
Check secrets deployment status:
# Via script
./scripts/setup-production-secrets.sh verify
# Manual check
ansible production_server -i inventory/production.yml \
-m shell -a "docker secret ls | wc -l"
# Should show 5 secrets: db_password, redis_password, app_key, jwt_secret, registry_password
Related Documentation
- Ansible Vault Documentation
- Docker Secrets Best Practices
- Main Deployment Guide:
../README.md