Merge pull request 'Support single-server deployment on Ubuntu' (#12) from feature/single-server-deployment into main
Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
commit
1fbe97d879
13 files changed
+328
-1
No files matched your search
@@ -6,6 +6,8 @@ and resellers. The project is in early development.
|
|||||||
The web panel gives operators a workspace to manage hosting accounts, request
|
The web panel gives operators a workspace to manage hosting accounts, request
|
||||||
Apache configuration previews, and follow their progress.
|
Apache configuration previews, and follow their progress.
|
||||||
See [Local development](docs/development.md) to run it.
|
See [Local development](docs/development.md) to run it.
|
||||||
|
See [Single-server deployment](docs/deployment.md) to install it with Apache,
|
||||||
|
MariaDB, and RabbitMQ.
|
||||||
|
|
||||||
## Planned scope
|
## Planned scope
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
Listen 192.168.10.20:8080
|
||||||
|
|
||||||
|
<VirtualHost 192.168.10.20:8080>
|
||||||
|
ServerName panel.example.net
|
||||||
|
|
||||||
|
RemoteIPHeader X-Forwarded-For
|
||||||
|
RemoteIPInternalProxy 192.168.10.10
|
||||||
|
|
||||||
|
<Location />
|
||||||
|
Require expr "%{CONN_REMOTE_ADDR} == '192.168.10.10'"
|
||||||
|
</Location>
|
||||||
|
|
||||||
|
Include /etc/coulobre/panel-proxy.inc
|
||||||
|
</VirtualHost>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
ProxyRequests Off
|
||||||
|
ProxyPreserveHost On
|
||||||
|
ProxyAddHeaders Off
|
||||||
|
RequestHeader unset X-Forwarded-Protocol
|
||||||
|
RequestHeader unset X-Forwarded-Ssl
|
||||||
|
RequestHeader set X-Forwarded-Proto "https"
|
||||||
|
RequestHeader set X-Forwarded-For "expr=%{REMOTE_ADDR}"
|
||||||
|
|
||||||
|
ProxyPass /static/ !
|
||||||
|
Alias /static/ /var/www/coulobre-panel-static/
|
||||||
|
<Directory /var/www/coulobre-panel-static/>
|
||||||
|
AllowOverride None
|
||||||
|
Options None
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
ProxyPass / "unix:/run/coulobre-panel/panel.sock|http://localhost/"
|
||||||
|
ProxyPassReverse / http://localhost/
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName panel.example.net
|
||||||
|
Redirect permanent / https://panel.example.net/
|
||||||
|
</VirtualHost>
|
||||||
|
|
||||||
|
<VirtualHost *:443>
|
||||||
|
ServerName panel.example.net
|
||||||
|
SSLEngine On
|
||||||
|
SSLCertificateFile /etc/ssl/coulobre-panel/fullchain.pem
|
||||||
|
SSLCertificateKeyFile /etc/ssl/coulobre-panel/privkey.pem
|
||||||
|
|
||||||
|
Include /etc/coulobre/panel-proxy.inc
|
||||||
|
</VirtualHost>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
DJANGO_SETTINGS_MODULE=coulobre.settings
|
||||||
|
COULOBRE_ALLOWED_HOSTS=panel.example.net
|
||||||
|
COULOBRE_HTTPS_PROXY=1
|
||||||
|
COULOBRE_STATIC_ROOT=/var/www/coulobre-panel-static
|
||||||
|
COULOBRE_SECRET_KEY=
|
||||||
|
COULOBRE_DB_NAME=coulobre_panel
|
||||||
|
COULOBRE_DB_USER=coulobre
|
||||||
|
COULOBRE_DB_PASSWORD=
|
||||||
|
COULOBRE_DB_HOST=/run/mysqld/mysqld.sock
|
||||||
|
COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Coulobre Panel Celery scheduler
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target rabbitmq-server.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=exec
|
||||||
|
User=coulobre-panel
|
||||||
|
Group=coulobre-panel
|
||||||
|
EnvironmentFile=/etc/coulobre/panel.env
|
||||||
|
WorkingDirectory=/opt/coulobre
|
||||||
|
StateDirectory=coulobre-panel
|
||||||
|
StateDirectoryMode=0700
|
||||||
|
UMask=0077
|
||||||
|
ExecStart=/opt/coulobre/bin/celery -A coulobre beat --loglevel=INFO --schedule=/var/lib/coulobre-panel/beat-schedule --pidfile=
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
ProtectHome=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Coulobre Panel web service
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target mariadb.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=exec
|
||||||
|
User=coulobre-panel
|
||||||
|
Group=www-data
|
||||||
|
EnvironmentFile=/etc/coulobre/panel.env
|
||||||
|
WorkingDirectory=/opt/coulobre
|
||||||
|
RuntimeDirectory=coulobre-panel
|
||||||
|
RuntimeDirectoryMode=0750
|
||||||
|
UMask=0007
|
||||||
|
ExecStart=/opt/coulobre/bin/gunicorn --bind unix:/run/coulobre-panel/panel.sock --umask 0o007 --no-control-socket --forwarder-headers= coulobre.wsgi:application
|
||||||
|
KillMode=mixed
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
ProtectHome=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Coulobre Panel Celery worker
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target mariadb.service rabbitmq-server.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=exec
|
||||||
|
User=coulobre-panel
|
||||||
|
Group=coulobre-panel
|
||||||
|
EnvironmentFile=/etc/coulobre/panel.env
|
||||||
|
WorkingDirectory=/opt/coulobre
|
||||||
|
UMask=0077
|
||||||
|
ExecStart=/opt/coulobre/bin/celery -A coulobre worker --loglevel=INFO --concurrency=2
|
||||||
|
KillMode=mixed
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
NoNewPrivileges=true
|
||||||
|
PrivateTmp=true
|
||||||
|
ProtectHome=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
# Install Coulobre Panel on one server
|
||||||
|
|
||||||
|
This setup runs the panel, its Celery worker and scheduler, MariaDB, RabbitMQ,
|
||||||
|
and Apache on one Ubuntu server. Use Ubuntu 24.04 or later. Apache serves the
|
||||||
|
panel and its static files and connects to Gunicorn over a Unix socket.
|
||||||
|
|
||||||
|
## Install the package and configure local services
|
||||||
|
|
||||||
|
Run these commands from a Coulobre checkout on the server.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo apt install apache2 mariadb-server rabbitmq-server python3-venv python3-dev \
|
||||||
|
build-essential pkg-config default-libmysqlclient-dev
|
||||||
|
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \
|
||||||
|
--shell /usr/sbin/nologin coulobre-panel
|
||||||
|
sudo python3 -m venv /opt/coulobre
|
||||||
|
sudo /opt/coulobre/bin/pip install '.[server,mariadb]'
|
||||||
|
|
||||||
|
sudo install -d -m 0750 /etc/coulobre
|
||||||
|
sudo install -d -o coulobre-panel -g coulobre-panel -m 0755 /var/www/coulobre-panel-static
|
||||||
|
if ! sudo test -e /etc/coulobre/panel.env; then
|
||||||
|
sudo install -m 0600 deploy/panel.env.example /etc/coulobre/panel.env
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
Generate separate random values for the Django secret key, the database
|
||||||
|
password, and the broker password. Use this command for each value.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -c 'import secrets; print(secrets.token_urlsafe(48))'
|
||||||
|
```
|
||||||
|
|
||||||
|
Start MariaDB and RabbitMQ. In `sudo mariadb`, create the panel database and
|
||||||
|
login. Substitute the generated database password.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo systemctl enable --now mariadb rabbitmq-server
|
||||||
|
```
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE DATABASE coulobre_panel CHARACTER SET utf8mb4;
|
||||||
|
CREATE USER 'coulobre'@'localhost' IDENTIFIED BY 'replace-with-database-password';
|
||||||
|
GRANT ALL PRIVILEGES ON coulobre_panel.* TO 'coulobre'@'localhost';
|
||||||
|
```
|
||||||
|
|
||||||
|
Create a dedicated RabbitMQ virtual host and login. Enter the generated broker
|
||||||
|
password when prompted by `rabbitmqctl add_user`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo rabbitmqctl add_vhost coulobre
|
||||||
|
sudo rabbitmqctl add_user coulobre
|
||||||
|
sudo rabbitmqctl set_permissions -p coulobre coulobre '.*' '.*' '.*'
|
||||||
|
```
|
||||||
|
|
||||||
|
Set `listeners.tcp.1 = 127.0.0.1:5672` in `/etc/rabbitmq/rabbitmq.conf` and
|
||||||
|
restart RabbitMQ to bind its AMQP listener to loopback. Keep MariaDB and
|
||||||
|
RabbitMQ management and cluster ports private. [RabbitMQ listener settings](https://www.rabbitmq.com/docs/networking#listeners)
|
||||||
|
|
||||||
|
Edit `/etc/coulobre/panel.env` with `sudoedit`. Set `COULOBRE_ALLOWED_HOSTS`
|
||||||
|
to the hostname browsers will use, enter the Django secret and the database
|
||||||
|
password, and place the broker password after `coulobre:` in
|
||||||
|
`COULOBRE_BROKER_URL`. The sample connects to MariaDB through its local Unix
|
||||||
|
socket and uses the dedicated RabbitMQ virtual host.
|
||||||
|
|
||||||
|
## Prepare the panel
|
||||||
|
|
||||||
|
Run the Django management commands as the service user with the same
|
||||||
|
environment the systemd services will use.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
panel_manage() {
|
||||||
|
sudo systemd-run --quiet --wait --pipe --collect --uid=coulobre-panel \
|
||||||
|
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||||
|
/opt/coulobre/bin/python -m django "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
panel_manage check --deploy
|
||||||
|
panel_manage migrate --noinput
|
||||||
|
panel_manage collectstatic --noinput
|
||||||
|
|
||||||
|
sudo systemd-run --quiet --pty --collect --uid=coulobre-panel \
|
||||||
|
--property=EnvironmentFile=/etc/coulobre/panel.env \
|
||||||
|
/opt/coulobre/bin/python -m django createsuperuser
|
||||||
|
```
|
||||||
|
|
||||||
|
HTTPS proxy mode enables HSTS for the panel hostname. Django reports `W005`
|
||||||
|
and `W021` for the optional subdomain and browser preload settings.
|
||||||
|
|
||||||
|
## Configure Apache and DNS
|
||||||
|
|
||||||
|
Install the shared Apache directives and enable the modules for your setup.
|
||||||
|
Replace the example hostname in the chosen virtual host with the hostname
|
||||||
|
from `COULOBRE_ALLOWED_HOSTS`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo install -m 0644 deploy/apache/panel-proxy.inc /etc/coulobre/panel-proxy.inc
|
||||||
|
sudo a2enmod headers proxy proxy_http
|
||||||
|
```
|
||||||
|
|
||||||
|
### Public server
|
||||||
|
|
||||||
|
Publish A or AAAA records for the IPv4 and IPv6 addresses that can reach the
|
||||||
|
panel. Allow TCP ports 80 and 443 at the firewall. If the server is behind NAT,
|
||||||
|
use the router's public address in DNS and forward those ports to Apache.
|
||||||
|
Install the TLS virtual host, enable `mod_ssl`, and set the certificate and key
|
||||||
|
paths for the panel hostname.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo a2enmod ssl
|
||||||
|
sudo install -m 0644 deploy/apache/panel-tls.conf.example \
|
||||||
|
/etc/apache2/sites-available/coulobre-panel.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
### LAN only
|
||||||
|
|
||||||
|
Use the same TLS virtual host with a hostname that internal DNS resolves to the
|
||||||
|
server's private address. Use a certificate that clients on the LAN trust, such
|
||||||
|
as one issued by your internal CA. Limit access to the panel's HTTP and HTTPS
|
||||||
|
ports to your private network. On a host with public and private web traffic,
|
||||||
|
use the private address in the panel's virtual hosts in place of `*`.
|
||||||
|
|
||||||
|
### External reverse proxy
|
||||||
|
|
||||||
|
Point the public DNS records at the reverse proxy. Configure it to redirect
|
||||||
|
HTTP to HTTPS, preserve the requested hostname when forwarding, and replace
|
||||||
|
`X-Forwarded-For` with the client address. The origin example uses HTTP on a
|
||||||
|
private network. Use a TLS connection to Apache if the upstream connection
|
||||||
|
crosses an untrusted network.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo a2enmod remoteip
|
||||||
|
sudo install -m 0644 deploy/apache/panel-origin.conf.example \
|
||||||
|
/etc/apache2/sites-available/coulobre-panel.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Set `192.168.10.20` to the private listener address on the Apache host and
|
||||||
|
`192.168.10.10` to the network peer address of your reverse proxy. Use the
|
||||||
|
proxy address in both `RemoteIPInternalProxy` and the `CONN_REMOTE_ADDR`
|
||||||
|
access rule. Restrict the origin port to the proxy at the firewall too. The
|
||||||
|
rule checks the peer connection, so it still applies when Apache recognizes a
|
||||||
|
different visitor IP from the trusted proxy.
|
||||||
|
[Apache client IP handling](https://httpd.apache.org/docs/2.4/mod/mod_remoteip.html)
|
||||||
|
|
||||||
|
Each virtual host sends its HTTPS indicator to Gunicorn itself. The TLS
|
||||||
|
virtual host handles HTTPS at Apache, while the private origin is reserved
|
||||||
|
for the external proxy's HTTPS traffic. Apache passes a single visitor IP
|
||||||
|
based on the connection or a trusted proxy. [Django HTTPS proxy settings](https://docs.djangoproject.com/en/5.2/ref/settings/#secure-proxy-ssl-header)
|
||||||
|
|
||||||
|
The addresses for hosted sites, mail, and authoritative DNS can differ from
|
||||||
|
the panel hostname. Configure the corresponding public DNS records for each
|
||||||
|
service using its reachable address.
|
||||||
|
|
||||||
|
## Start the services
|
||||||
|
|
||||||
|
Install and enable the three units. The panel's socket directory is available
|
||||||
|
to Apache workers. The scheduler stores its state in a private directory and
|
||||||
|
there is one scheduler for the installation.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo install -m 0644 deploy/systemd/*.service /etc/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now coulobre-panel.service coulobre-worker.service coulobre-beat.service
|
||||||
|
|
||||||
|
sudo a2ensite coulobre-panel
|
||||||
|
sudo apache2ctl configtest
|
||||||
|
sudo systemctl reload apache2
|
||||||
|
```
|
||||||
|
|
||||||
|
Sign in with the administrator account. Add a hosting account and request an
|
||||||
|
Apache preview to verify that RabbitMQ, the scheduler, and the worker are
|
||||||
|
connected. Follow their logs with `journalctl`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo journalctl -u coulobre-panel -u coulobre-worker -u coulobre-beat
|
||||||
|
```
|
||||||
@@ -593,6 +593,11 @@ PHP-FPM configurations, and makes an HTTP request with the account's primary
|
|||||||
domain. A passing check confirms PHP execution through the generated socket.
|
domain. A passing check confirms PHP execution through the generated socket.
|
||||||
The container uses its own filesystem and loopback interface.
|
The container uses its own filesystem and loopback interface.
|
||||||
|
|
||||||
|
## Run the installed panel behind Apache
|
||||||
|
|
||||||
|
See [Single-server deployment](deployment.md) for Gunicorn, Apache, and the
|
||||||
|
systemd services for the panel, worker, and scheduler.
|
||||||
|
|
||||||
## MariaDB
|
## MariaDB
|
||||||
|
|
||||||
Create a dedicated MariaDB database and application user. Install the MariaDB or
|
Create a dedicated MariaDB database and application user. Install the MariaDB or
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ coulobre-web-node = "coulobre.web_node:main"
|
|||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = ["ruff>=0.11,<1"]
|
dev = ["ruff>=0.11,<1"]
|
||||||
mariadb = ["mysqlclient>=2.2.1,<3"]
|
mariadb = ["mysqlclient>=2.2.1,<3"]
|
||||||
|
server = ["gunicorn>=27.0.1,<28"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
"coulobre.hosting" = [
|
"coulobre.hosting" = [
|
||||||
|
|||||||
@@ -12,11 +12,19 @@ def required_env(name):
|
|||||||
|
|
||||||
|
|
||||||
SECRET_KEY = required_env("COULOBRE_SECRET_KEY")
|
SECRET_KEY = required_env("COULOBRE_SECRET_KEY")
|
||||||
DEBUG = os.environ.get("COULOBRE_DEBUG") == "1"
|
HTTPS_PROXY = os.environ.get("COULOBRE_HTTPS_PROXY") == "1"
|
||||||
|
DEBUG = not HTTPS_PROXY and os.environ.get("COULOBRE_DEBUG") == "1"
|
||||||
ALLOWED_HOSTS = os.environ.get(
|
ALLOWED_HOSTS = os.environ.get(
|
||||||
"COULOBRE_ALLOWED_HOSTS", "localhost,127.0.0.1,[::1]"
|
"COULOBRE_ALLOWED_HOSTS", "localhost,127.0.0.1,[::1]"
|
||||||
).split(",")
|
).split(",")
|
||||||
|
|
||||||
|
if HTTPS_PROXY:
|
||||||
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
SECURE_SSL_REDIRECT = True
|
||||||
|
SECURE_HSTS_SECONDS = 86400
|
||||||
|
SESSION_COOKIE_SECURE = True
|
||||||
|
CSRF_COOKIE_SECURE = True
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
"coulobre.admin.CoulobreAdminConfig",
|
"coulobre.admin.CoulobreAdminConfig",
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
@@ -85,6 +93,8 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
TIME_ZONE = "UTC"
|
TIME_ZONE = "UTC"
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/static/"
|
||||||
|
STATIC_ROOT = os.environ.get("COULOBRE_STATIC_ROOT") or None
|
||||||
|
WSGI_APPLICATION = "coulobre.wsgi.application"
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
LOGIN_URL = "panel:login"
|
LOGIN_URL = "panel:login"
|
||||||
LOGIN_REDIRECT_URL = "panel:accounts"
|
LOGIN_REDIRECT_URL = "panel:accounts"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coulobre.settings")
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
||||||
Reference in new issue
Block a user