|
| 1 | +--- |
| 2 | +review-status: needs-review |
| 3 | +review-date: 2025-06-04 |
| 4 | +reviewer: migration-script |
| 5 | +migration-notes: "Added during 2025 documentation reorganization" |
| 6 | +--- |
| 7 | + |
| 8 | +# Security Recommendations and Performance Tuning |
| 9 | + |
| 10 | +This guide provides essential recommendations for securing your OpenSPP instance and tuning its performance for production environments. It covers database security, firewall setup, SSL/TLS configuration with Nginx, and implementing regular backups. Additionally, it offers tips on performance tuning, including adjusting worker processes, memory limits, and PostgreSQL settings to handle high-load scenarios. |
| 11 | + |
| 12 | +## Security Recommendations |
| 13 | + |
| 14 | +### 1. Database Security Configuration |
| 15 | + |
| 16 | +After initial setup and database creation, it's strongly recommended to: |
| 17 | + |
| 18 | +```bash |
| 19 | +# Edit the configuration |
| 20 | +sudo nano /etc/openspp/odoo.conf |
| 21 | + |
| 22 | +# Set list_db to False for production |
| 23 | +list_db = False |
| 24 | + |
| 25 | +# Restart the service |
| 26 | +sudo systemctl restart openspp |
| 27 | +``` |
| 28 | + |
| 29 | +**Why disable list_db in production:** |
| 30 | +- Prevents unauthorized users from seeing database names |
| 31 | +- Disables database creation/deletion via web interface |
| 32 | +- Reduces attack surface by hiding database management interface |
| 33 | +- Forces direct database URL access (e.g., `http://server:8069/web?db=openspp_prod`) |
| 34 | + |
| 35 | +**When to keep list_db = True:** |
| 36 | +- Development environments |
| 37 | +- Testing environments |
| 38 | +- Initial setup phase |
| 39 | +- When multiple databases need frequent management |
| 40 | + |
| 41 | +### 2. Firewall Configuration |
| 42 | + |
| 43 | +```bash |
| 44 | +# Install UFW firewall |
| 45 | +sudo apt-get install -y ufw |
| 46 | + |
| 47 | +# Allow SSH (adjust port if needed) |
| 48 | +sudo ufw allow 22/tcp |
| 49 | + |
| 50 | +# Allow OpenSPP web interface |
| 51 | +sudo ufw allow 8069/tcp |
| 52 | + |
| 53 | +# Allow OpenSPP longpolling (if using real-time features) |
| 54 | +sudo ufw allow 8072/tcp |
| 55 | + |
| 56 | +# Enable firewall |
| 57 | +sudo ufw enable |
| 58 | +``` |
| 59 | + |
| 60 | +### 3. SSL/TLS with Nginx (Recommended for Production) |
| 61 | + |
| 62 | +```bash |
| 63 | +# Install Nginx |
| 64 | +sudo apt-get install -y nginx certbot python3-certbot-nginx |
| 65 | + |
| 66 | +# Create Nginx configuration |
| 67 | +sudo nano /etc/nginx/sites-available/openspp |
| 68 | +``` |
| 69 | + |
| 70 | +Add this configuration: |
| 71 | +```nginx |
| 72 | +server { |
| 73 | + listen 80; |
| 74 | + server_name your-domain.com; |
| 75 | +
|
| 76 | + # Redirect HTTP to HTTPS |
| 77 | + return 301 https://$server_name$request_uri; |
| 78 | +} |
| 79 | +
|
| 80 | +server { |
| 81 | + listen 443 ssl http2; |
| 82 | + server_name your-domain.com; |
| 83 | +
|
| 84 | + # SSL certificates (will be added by certbot) |
| 85 | + # ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; |
| 86 | + # ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; |
| 87 | +
|
| 88 | + # Proxy settings |
| 89 | + proxy_read_timeout 720s; |
| 90 | + proxy_connect_timeout 720s; |
| 91 | + proxy_send_timeout 720s; |
| 92 | +
|
| 93 | + # Add headers |
| 94 | + proxy_set_header Host $host; |
| 95 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 96 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 97 | + proxy_set_header X-Real-IP $remote_addr; |
| 98 | +
|
| 99 | + # Redirect requests to OpenSPP |
| 100 | + location / { |
| 101 | + proxy_redirect off; |
| 102 | + proxy_pass http://127.0.0.1:8069; |
| 103 | + } |
| 104 | +
|
| 105 | + # Longpolling |
| 106 | + location /longpolling { |
| 107 | + proxy_pass http://127.0.0.1:8072; |
| 108 | + } |
| 109 | +
|
| 110 | + # Static files |
| 111 | + location ~* /web/static/ { |
| 112 | + proxy_cache_valid 200 90m; |
| 113 | + proxy_buffering on; |
| 114 | + expires 864000; |
| 115 | + proxy_pass http://127.0.0.1:8069; |
| 116 | + } |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +Enable the site and get SSL certificate: |
| 121 | +```bash |
| 122 | +# Enable the site |
| 123 | +sudo ln -s /etc/nginx/sites-available/openspp /etc/nginx/sites-enabled/ |
| 124 | +sudo nginx -t |
| 125 | +sudo systemctl reload nginx |
| 126 | + |
| 127 | +# Get SSL certificate |
| 128 | +sudo certbot --nginx -d your-domain.com |
| 129 | +``` |
| 130 | + |
| 131 | +### 4. Regular Backups |
| 132 | + |
| 133 | +Create a backup script: |
| 134 | + |
| 135 | +```bash |
| 136 | +sudo nano /usr/local/bin/openspp-backup.sh |
| 137 | +``` |
| 138 | + |
| 139 | +```bash |
| 140 | +#!/bin/bash |
| 141 | +BACKUP_DIR="/var/backups/openspp" |
| 142 | +DATE=$(date +%Y%m%d_%H%M%S) |
| 143 | +DB_NAME="openspp_prod" |
| 144 | + |
| 145 | +# Create backup directory |
| 146 | +mkdir -p $BACKUP_DIR |
| 147 | + |
| 148 | +# Backup database |
| 149 | +sudo -u postgres pg_dump $DB_NAME | gzip > $BACKUP_DIR/db_${DB_NAME}_${DATE}.sql.gz |
| 150 | + |
| 151 | +# Backup filestore |
| 152 | +tar -czf $BACKUP_DIR/filestore_${DATE}.tar.gz /var/lib/openspp/ |
| 153 | + |
| 154 | +# Keep only last 30 days of backups |
| 155 | +find $BACKUP_DIR -type f -mtime +30 -delete |
| 156 | + |
| 157 | +echo "Backup completed: $DATE" |
| 158 | +``` |
| 159 | + |
| 160 | +Make it executable and schedule: |
| 161 | +```bash |
| 162 | +sudo chmod +x /usr/local/bin/openspp-backup.sh |
| 163 | + |
| 164 | +# Add to crontab (daily at 2 AM) |
| 165 | +echo "0 2 * * * /usr/local/bin/openspp-backup.sh" | sudo crontab - |
| 166 | +``` |
| 167 | + |
| 168 | +## Performance Tuning |
| 169 | + |
| 170 | +For production environments with high load: |
| 171 | + |
| 172 | +1. **Increase workers** (1 worker per CPU core, minimum 2 for queue_job): |
| 173 | + ```ini |
| 174 | + workers = 8 # For 8-core server |
| 175 | + server_wide_modules = base,web,queue_job # Required |
| 176 | + ``` |
| 177 | + |
| 178 | + **Note**: Never set `workers = 0` in production as this disables queue_job async processing. |
| 179 | + |
| 180 | +2. **Adjust memory limits** based on available RAM: |
| 181 | + ```ini |
| 182 | + limit_memory_hard = 8589934592 # 8GB |
| 183 | + limit_memory_soft = 6442450944 # 6GB |
| 184 | + ``` |
| 185 | + |
| 186 | +3. **PostgreSQL tuning**: |
| 187 | + ```bash |
| 188 | + sudo nano /etc/postgresql/16/main/postgresql.conf |
| 189 | + ``` |
| 190 | + |
| 191 | + Adjust: |
| 192 | + ```ini |
| 193 | + shared_buffers = 2GB |
| 194 | + effective_cache_size = 6GB |
| 195 | + maintenance_work_mem = 512MB |
| 196 | + checkpoint_completion_target = 0.9 |
| 197 | + wal_buffers = 16MB |
| 198 | + default_statistics_target = 100 |
| 199 | + random_page_cost = 1.1 |
| 200 | + ``` |
| 201 | + |
| 202 | +4. **Enable caching** with Redis (optional): |
| 203 | + ```bash |
| 204 | + sudo apt-get install -y redis-server |
| 205 | + # Configure in odoo.conf if your OpenSPP version supports it |
| 206 | + ``` |
0 commit comments