5.5 KiB
CyberPanel Secure Installation Guide
Overview
This document describes the secure installation process for CyberPanel that eliminates hardcoded passwords and implements environment-based configuration.
Security Improvements
✅ Fixed Security Vulnerabilities
- Hardcoded Database Passwords - Now generated securely during installation
- Hardcoded Django Secret Key - Now generated using cryptographically secure random generation
- Environment Variables - All sensitive configuration moved to
.envfile - File Permissions -
.envfile set to 600 (owner read/write only)
🔐 Security Features
- Cryptographically Secure Passwords: Uses Python's
secretsmodule for password generation - Environment-based Configuration: Sensitive data stored in
.envfile, not in code - Secure File Permissions: Environment files protected with 600 permissions
- Credential Backup: Automatic backup of credentials for recovery
- Fallback Security: Maintains backward compatibility with fallback method
Installation Process
1. Automatic Secure Installation
The installation script now automatically:
-
Generates secure random passwords for:
- MySQL root user
- CyberPanel database user
- Django secret key
-
Creates
.envfile with secure configuration:# Generated during installation SECRET_KEY=your_64_character_secure_key DB_PASSWORD=your_24_character_secure_password ROOT_DB_PASSWORD=your_24_character_secure_password -
Creates
.env.backupfile for credential recovery -
Sets secure file permissions (600) on all environment files
2. Manual Installation (if needed)
If you need to manually generate environment configuration:
cd /usr/local/CyberCP
python install/env_generator.py /usr/local/CyberCP
File Structure
/usr/local/CyberCP/
├── .env # Main environment configuration (600 permissions)
├── .env.backup # Credential backup (600 permissions)
├── .env.template # Template for manual configuration
├── .gitignore # Prevents .env files from being committed
└── CyberCP/
└── settings.py # Updated to use environment variables
Security Best Practices
✅ Do's
- Keep
.envand.env.backupfiles secure - Record credentials from
.env.backupand delete the file after installation - Use strong, unique passwords for production deployments
- Regularly rotate database passwords
- Monitor access to environment files
❌ Don'ts
- Never commit
.envfiles to version control - Don't share
.envfiles via insecure channels - Don't use default passwords in production
- Don't leave
.env.backupfiles on the system after recording credentials
Recovery
Lost Credentials
If you lose your database credentials:
-
Check if
.env.backupfile exists:sudo cat /usr/local/CyberCP/.env.backup -
If backup doesn't exist, you'll need to reset MySQL passwords using MySQL recovery procedures
Regenerate Environment
To regenerate environment configuration:
cd /usr/local/CyberCP
sudo python install/env_generator.py /usr/local/CyberCP
Configuration Options
Environment Variables
| Variable | Description | Default |
|---|---|---|
SECRET_KEY |
Django secret key | Generated (64 chars) |
DB_PASSWORD |
CyberPanel DB password | Generated (24 chars) |
ROOT_DB_PASSWORD |
MySQL root password | Generated (24 chars) |
DEBUG |
Debug mode | False |
ALLOWED_HOSTS |
Allowed hosts | localhost,127.0.0.1,hostname |
Custom Configuration
To use custom passwords during installation:
python install/env_generator.py /usr/local/CyberCP "your_root_password" "your_db_password"
Troubleshooting
Installation Fails
If the new secure installation fails:
- Check installation logs for error messages
- The system will automatically fallback to the original installation method
- Verify Python dependencies are installed:
pip install python-dotenv
Environment Loading Issues
If Django can't load environment variables:
-
Ensure
.envfile exists and has correct permissions:ls -la /usr/local/CyberCP/.env # Should show: -rw------- 1 root root -
Install python-dotenv if missing:
pip install python-dotenv
Migration from Old Installation
Existing Installations
For existing CyberPanel installations with hardcoded passwords:
-
Backup current configuration:
cp /usr/local/CyberCP/CyberCP/settings.py /usr/local/CyberCP/CyberCP/settings.py.backup -
Generate new environment configuration:
cd /usr/local/CyberCP python install/env_generator.py /usr/local/CyberCP -
Update settings.py (already done in new installations):
- The settings.py file now supports environment variables
- It will fallback to hardcoded values if .env is not available
-
Test the configuration:
cd /usr/local/CyberCP python manage.py check
Support
For issues with the secure installation:
- Check the installation logs
- Verify file permissions
- Ensure all dependencies are installed
- Review the fallback installation method if needed
Security Notice: This installation method significantly improves security by eliminating hardcoded credentials. Always ensure proper file permissions and secure handling of environment files.