Last Updated: 2025-10-19 Security Rating: 75/100 (Good) - 5 critical items implemented
This folder contains all security-related documentation, audits, implementation guides, and procedures for CostPlusDB.
001-security/
├── README.md (this file)
├── audits/ Security audit reports
│ └── 006-DR-SOPS-security-audit.md
├── implementation/ Implementation guides and procedures
│ └── 007-DR-SOPS-security-implementation-guide.md
├── procedures/ Operational security procedures
│ ├── 008-DR-GUID-add-wasabi-s3-backups.md
│ ├── provision-customer-database.sh
│ └── deprovision-customer-database.sh
└── keys/ Encryption keys and passphrases (NOT in git)
└── .gitignore
| Security Control | Status | Details |
|---|---|---|
| PostgreSQL SSL/TLS | ✅ Implemented | TLSv1.2+, proper certificates |
| fail2ban Protection | ✅ Implemented | Port 5433, 5 retries, 1hr ban |
| Customer DB Isolation | ✅ Implemented | Per-customer users + databases |
| Backup Encryption | ✅ Implemented | AES-256-CBC, pgBackRest |
| Connection Logging | ✅ Enabled | All connections logged |
| SSH Hardening | ✅ Implemented | Key-only, custom port, fail2ban |
| UFW Firewall | ✅ Configured | Minimal open ports |
Location on Server:
- Encryption passphrase:
/root/pgbackrest-keys/encryption-passphrase.txt - Customer credentials:
/root/customer-credentials/ - SSL certificates:
/var/lib/postgresql/16/main/ssl/
006-DR-SOPS-security-audit.md
- Complete security audit against industry standards
- Rating: 75/100 (Good)
- 18 controls implemented
- 12 improvements recommended
- Based on: How To Secure A Linux Server
007-DR-SOPS-security-implementation-guide.md
- Step-by-step implementation of 5 critical security items
- Complete with scripts, configs, and verification steps
- Time estimates for each task
- Ready-to-use code snippets
008-DR-GUID-add-wasabi-s3-backups.md
- Guide for adding Wasabi S3 cloud backups
- Upgrades from local-only to cloud storage
- Cost impact analysis
- Step-by-step configuration
provision-customer-database.sh
- Automated customer database provisioning
- Creates isolated database + user
- Generates secure credentials
- Adds SSL-required pg_hba entry
deprovision-customer-database.sh
- Safe customer database removal
- Terminates active connections
- Removes database, user, and pg_hba entry
- Archives credentials
1. Internal Security (Operator Access)
- Who: Jeremy (CostPlusDB operator only)
- Access: SSH to VPS, root/sudo, OS-level management
- Controls: SSH key auth, custom port, fail2ban, UFW
2. Customer Security (Database Access)
- Who: Customers and their applications
- Access: PostgreSQL connections ONLY (port 5433)
- Controls: SSL/TLS enforced, scram-sha-256, database isolation
Customers do NOT get:
- ❌ SSH access to VPS
- ❌ OS-level access
- ❌ Access to other customers' databases
# PostgreSQL SSL status
sudo -u postgres psql -p 5433 -c "SHOW ssl; SHOW ssl_cert_file; SHOW ssl_min_protocol_version;"
# fail2ban status
sudo fail2ban-client status
sudo fail2ban-client status postgresql
# Backup status
sudo -u postgres pgbackrest --stanza=main info
# Customer databases
sudo -u postgres psql -p 5433 -c "\l"
# Active connections
sudo -u postgres psql -p 5433 -c "SELECT datname, usename, application_name, client_addr FROM pg_stat_activity WHERE datname NOT IN ('postgres', 'template0', 'template1');"cd /home/admincostplus/projects/costplusdb/001-security/procedures
./provision-customer-database.sh <customer_name># Manual backup
sudo -u postgres pgbackrest --stanza=main --type=full backup
# Check backup status
sudo -u postgres pgbackrest --stanza=main info# List customer databases and owners
sudo -u postgres psql -p 5433 -c "SELECT datname, datdba::regrole AS owner FROM pg_database WHERE datname NOT IN ('postgres', 'template0', 'template1');"
# Check pg_hba.conf entries
sudo cat /etc/postgresql/16/main/pg_hba.conf | grep hostsslCostPlusDB security is based on these industry-proven standards:
-
- Comprehensive Linux hardening guide
- CC-BY-SA License
-
- SSH configuration best practices
-
PostgreSQL Security Documentation
- Official database security guidelines
-
- Industry-standard security configurations
- Automatic alert via Betterstack
- Check PostgreSQL status:
sudo systemctl status postgresql - Check logs:
sudo tail -100 /var/log/postgresql/postgresql-18-main.log - Email customer within 5 minutes
- Post-mortem report within 24 hours
- Isolate affected systems immediately
- Email affected customers within 1 hour
- Check fail2ban logs:
sudo fail2ban-client status postgresql - Review connection logs:
sudo grep FATAL /var/log/postgresql/postgresql-18-main.log - Detailed incident report to customers
Email: jeremy@intentsolutions.io Subject: "SECURITY: [brief description]"
Response times:
- Acknowledgment: 24 hours
- Assessment: 72 hours
- Fix: Critical issues within 7 days
- PostgreSQL SSL/TLS enforced
- fail2ban for PostgreSQL configured
- Per-customer database isolation tested
- Backup encryption enabled
- Wasabi S3 cloud backups configured (local backups working)
- Test restoration from backup
- Document server IP address
- Set up monitoring alerts (Betterstack)
- Create first customer invoice template
Before going live, remove test customer:
sudo -u postgres psql -p 5433 -c "DROP DATABASE IF EXISTS testcustomer_db;"
sudo -u postgres psql -p 5433 -c "DROP USER IF EXISTS testcustomer_user;"
sudo sed -i '/testcustomer/d' /etc/postgresql/16/main/pg_hba.conf
sudo -u postgres psql -p 5433 -c "SELECT pg_reload_conf();"- Automated backups (2 AM)
- Backup verification logs
- Review fail2ban logs
- Check disk space:
df -h /var/lib/pgbackrest - Security updates:
sudo apt-get update && sudo apt-get upgrade -y
- Test backup restoration
- Review customer access logs
- Update security documentation
- Run security audit:
sudo lynis audit system
Priority items from security audit:
High Priority (Month 0-3):
- Wasabi S3 cloud backups
- Automated backup restoration testing
- Security incident playbooks
- Betterstack monitoring setup
Medium Priority (Month 3-6):
- Automated security updates
- Log aggregation/SIEM
- Rate limiting for connections
- Customer-specific connection limits
Low Priority (Month 6-12):
- Two-factor authentication for operator access
- External penetration testing
- SOC 2 compliance preparation
- Automated vulnerability scanning
Security issues: jeremy@intentsolutions.io Emergency: Same (email, 4-hour SLA)
GitHub: https://github.com/jeremylongshore/cost-plus-db (private)
Security practices based on open-source standards and guides from:
- imthenachoman - Linux Server Security Guide
- Mozilla - OpenSSH Guidelines
- PostgreSQL Global Development Group - Database Security
- CIS - Security Benchmarks
Standing on the shoulders of giants. 🙏