This guide will help you securely deploy Slimbooks on your Raspberry Pi using Docker.
Your Slimbooks application has been hardened with the following security measures:
- 🔐 Secure Authentication: JWT tokens with configurable expiration
- 🛡️ Rate Limiting: Protection against brute force attacks
- 🔒 Security Headers: Helmet.js for comprehensive security headers
- 🚫 Input Validation: Server-side validation for all inputs
- 🔍 CORS Protection: Configurable cross-origin resource sharing
- 📝 Request Logging: Comprehensive request/response logging
- 🚨 Error Handling: Secure error responses without information leakage
- 📁 File Upload Security: Restricted file types and size limits
- 🔐 Environment Variables: Secure configuration management
- Removed hardcoded JWT secrets - Now uses environment variables
- Restricted CORS policy - No longer allows all origins
- Added rate limiting - Prevents brute force attacks
- Secured database endpoints - Removed dangerous SQL execution endpoints
- Added input validation - Prevents SQL injection and data corruption
- Implemented security headers - Protection against common web attacks
- Disabled debug endpoints - Only available in development mode
- Reduced file upload limits - From 100MB to 10MB for security
- Raspberry Pi with Raspberry Pi OS
- Internet connection
- SSH access to your Pi
# Download and run the setup script
curl -fsSL https://raw.githubusercontent.com/rbenzing/slimbooks/main/scripts/setup-raspberry-pi.sh | bash
# Reboot to ensure all changes take effect
sudo reboot# Clone your repository
cd /opt/slimbooks
git clone https://github.com/rbenzing/slimbooks.git .
# Generate secure secrets
./scripts/generate-secrets.sh
# Review and customize your .env file
nano .env# Run the deployment script
./scripts/deploy.shYour application will be available at http://your-pi-ip:8080
If you prefer to deploy manually or need to customize the process:
# Update system
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
sudo usermod -aG docker $USER
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs# Create application directory
sudo mkdir -p /opt/slimbooks
sudo chown $USER:$USER /opt/slimbooks
cd /opt/slimbooks
# Clone repository
git clone https://github.com/rbenzing/slimbooks.git .
# Create secure environment configuration
cp .env.example .envCRITICAL: Update your .env file with secure secrets:
# Generate secure secrets (64 characters each)
JWT_SECRET=$(openssl rand -base64 64 | tr -d "=+/" | cut -c1-64)
JWT_REFRESH_SECRET=$(openssl rand -base64 64 | tr -d "=+/" | cut -c1-64)
SESSION_SECRET=$(openssl rand -base64 64 | tr -d "=+/" | cut -c1-64)
# Update .env file with these secrets
sed -i "s/CHANGE_THIS_JWT_SECRET_IN_PRODUCTION.*/$JWT_SECRET/" .env
sed -i "s/CHANGE_THIS_REFRESH_SECRET_IN_PRODUCTION.*/$JWT_REFRESH_SECRET/" .env
sed -i "s/CHANGE_THIS_SESSION_SECRET_IN_PRODUCTION.*/$SESSION_SECRET/" .env# Install dependencies and build
npm ci --only=production
npm run build
# Build Docker image
docker build -t slimbooks:latest .
# Start the application
docker-compose up -dKey security-related environment variables in your .env file:
# Security Secrets (MUST be changed in production)
JWT_SECRET=your-64-character-secret-here
JWT_REFRESH_SECRET=your-64-character-refresh-secret-here
SESSION_SECRET=your-64-character-session-secret-here
# CORS Configuration
CORS_ORIGIN=http://your-domain.com:8080
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000 # 15 minutes
RATE_LIMIT_MAX_REQUESTS=100 # 100 requests per window
LOGIN_RATE_LIMIT_MAX_ATTEMPTS=5 # 5 login attempts per window
# Security Features
ENABLE_DEBUG_ENDPOINTS=false # Never enable in production
ENABLE_SAMPLE_DATA=false # Never enable in production
BCRYPT_ROUNDS=12 # Password hashing strengthThe Docker configuration includes:
- Port binding to localhost only:
127.0.0.1:8080:3002 - Read-only filesystem: Container runs with read-only root filesystem
- Non-root user: Application runs as user ID 1001
- Dropped capabilities: All unnecessary Linux capabilities removed
- Resource limits: Memory and CPU limits to prevent resource exhaustion
# Configure UFW firewall
sudo ufw enable
sudo ufw allow 22/tcp # SSH
sudo ufw allow 8080/tcp # Slimbooks applicationThe application includes built-in health checks:
# Check application health
curl http://localhost:8080/api/health
# View application logs
docker-compose logs -f
# Check container status
docker-compose psAutomated daily backups are configured:
# Manual backup
/usr/local/bin/slimbooks-backup
# View backup files
ls -la /opt/slimbooks-backups/Logs are automatically rotated:
- Application logs:
/opt/slimbooks/logs/ - Docker logs: Managed by Docker with size limits
- System logs: Standard syslog rotation
-
Application won't start
# Check logs docker-compose logs # Verify environment configuration docker-compose config
-
Database connection issues
# Check data directory permissions ls -la data/ # Verify SQLite database sqlite3 data/slimbooks.db ".tables"
-
Port conflicts
# Check what's using port 8080 sudo netstat -tulpn | grep 8080 # Change port in docker-compose.yml if needed
# Verify security headers
curl -I http://localhost:8080/
# Test rate limiting
for i in {1..10}; do curl http://localhost:8080/api/health; done
# Check for exposed debug endpoints (should return 404)
curl http://localhost:8080/api/debug/dataBefore going live, ensure:
- JWT secrets are changed from defaults
- CORS_ORIGIN is set to your actual domain
- Debug endpoints are disabled
- Sample data is disabled
- Firewall is configured
- SSL/TLS is configured (if exposing to internet)
- Regular backups are working
- Log monitoring is in place
If you encounter issues:
- Check the logs:
docker-compose logs - Verify your configuration:
docker-compose config - Review this deployment guide
- Check the main README.md for application-specific help
To update your deployment:
# Pull latest changes
git pull
# Rebuild and redeploy
./scripts/deploy.sh