Docs restructure, code review, gatherer reliability, JWT key fail-closed
Documentation - Three levels: DOCS/General (overview, configuration), DOCS/Deployment (choose a method, first steps), details per method in Containers/ and System_Services/; new root README and DOCS/README map. - Remove superseded pages (Deployment.md, Deployment_Docker/Native.md, Index.md); split the two scenario guides by section. - Isolate the Timeweb/Hysteria2 records in DEPLOYMENTS/timeweb-hysteria2/ (not linked from DOCS, listed in .graphifyignore). - Add DOCS/code_review/ with a time-stamped analysis of the code base. Gatherer (BUG-02, BUG-03) - Session key (CN, address, connected_since_ts), baseline from the active_sessions snapshot, grace period for sessions missing from the status. - Status file integrity (TITLE/TIME/END) and freshness; a torn read skips the tick. - Cache applied after commit; main loop survives exceptions, backs off, and stops cleanly on SIGTERM/SIGINT; new client rows start with the first frame's totals; five tests. JWT signing key (SEC-01) - No built-in default: Core and Profiler refuse to start with a missing, placeholder or short (< 32) key; shipped config.ini has an empty value. - Same rule in install.sh, update.sh (issues a new key when missing or weak), docker lib/entrypoint; five tests, conftest.py for the test key. Each change has a plan and a summary under DOCS/Changes/. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f95a0b63e6
commit
ad6995bb63
85 files changed
+2805
-1280
No files matched your search
@@ -0,0 +1,118 @@
|
||||
# Containers: update, backup, restore, rollback
|
||||
|
||||
Day-2 operations of the container installation. Every update takes a verified backup first and rolls back automatically on failure. Install: [Containers](README.md).
|
||||
|
||||
## Update
|
||||
|
||||
```bash
|
||||
deploy/docker/update.sh # variant and project from .ovpmon-deploy
|
||||
deploy/docker/update.sh --yes # no questions
|
||||
deploy/docker/update.sh --no-pull # sources already in place / offline (no git pull, no base image refresh)
|
||||
deploy/docker/update.sh --rollback # manual rollback to the newest backup
|
||||
```
|
||||
|
||||
Each phase is logged separately:
|
||||
|
||||
| Phase | What happens | If it fails |
|
||||
|---|---|---|
|
||||
| 0 Preflight | state file, `.env`, compose configuration, running stack, the other variant not running, `db_data` volume exists, free space | nothing was changed |
|
||||
| 1 **Backup** | all five volumes → `backups/<UTC timestamp>/*.tar.gz` through a throwaway `alpine` container (volumes mounted read-only), copy of `.env` (mode 600), record of the current image IDs, `SHA256SUMS`; every archive is verified (`tar -tzf`) | the update is **refused**, nothing was changed |
|
||||
| 2 Sources | `git pull --ff-only` when the directory is a git checkout and `--no-pull` was not given | nothing was changed |
|
||||
| 3 Build | current images are tagged `<name>:previous`, then the new images are built while the old stack keeps running | nothing was changed, the old version still runs |
|
||||
| 4 Stop | the application containers are stopped (volumes are kept); a second, final backup of the volumes is taken now that nothing writes to the databases | automatic rollback |
|
||||
| 5 **Database migration** | a separate step, see below | automatic rollback, nothing is started |
|
||||
| 6 Start | `up -d` with the new images, wait for the health checks | automatic rollback |
|
||||
|
||||
Old backups: the newest 5 are kept; older ones are pruned only after a successful update. Volumes are never deleted and `down -v` is never used. The new `deploy/docker/*.sh` take effect on the next run (the running script is not replaced).
|
||||
|
||||
### Database migration as its own step
|
||||
|
||||
After the containers are stopped and before any new component starts, `update.sh` runs, for each database, a one-off container **from the new image with the same volumes**:
|
||||
|
||||
| Variant | Profiler database | Monitoring database |
|
||||
|---|---|---|
|
||||
| B | `app-profiler` image: `cd /app && python migrate.py` | `app-api` image: `cd /app && python migrate.py` |
|
||||
| A | `ovpmon` image: `cd /app/APP_PROFILER && python migrate.py` | `ovpmon` image: `cd /app/APP_CORE && python migrate.py` |
|
||||
|
||||
For each database it runs `python migrate.py --check` (exit 0 up to date, 2 pending, 1 error or database newer than the code), applies the pending migrations with `python migrate.py` and checks again. The reports are printed. A failure or a "too new" database aborts **before anything is started** and triggers the rollback.
|
||||
|
||||
What the migration does (details: [Database migrations](../../General/Database_Migrations.md)): versioned, additive-only changes (`CREATE ... IF NOT EXISTS`, `ADD COLUMN` with defaults), never a drop or rewrite; before any change an integrity check and a consistent copy `<db>.bak-<UTC timestamp>` next to the database (newest 5 kept); after the change an integrity check and a comparison of row counts; on a mismatch everything is rolled back; a database newer than the application is not touched.
|
||||
|
||||
The migration also runs by itself when a service starts (variant B: profiler and API; variant A: the entrypoint, before `supervisord`), so a plain `docker compose up -d --build` is safe too. `update.sh` only makes it a visible, separate, controlled step.
|
||||
|
||||
### Automatic rollback
|
||||
|
||||
On any failure in phases 4 to 6: the stack is stopped, all five volumes are restored from the backup of this run, the `:previous` images are started (through a generated `compose.previous.yml` in the backup directory) and the result is reported with the backup path. If the rollback itself fails, the message says where the backup is and how to retry (`update.sh --rollback`, or `restore.sh`).
|
||||
|
||||
After a rollback the stack runs on the `:previous` images; the next `update.sh` run builds again and recreates the containers on the new images.
|
||||
|
||||
## Backup, restore, rollback
|
||||
|
||||
### Backup
|
||||
|
||||
```bash
|
||||
deploy/docker/backup.sh # live backup of the five volumes -> backups/<UTC timestamp>/
|
||||
deploy/docker/backup.sh --stop # stops the containers during the copy (consistent SQLite files), starts them again
|
||||
deploy/docker/backup.sh --keep 14 # afterwards keep the newest 14
|
||||
```
|
||||
|
||||
Cron example (nightly, consistent, 14 kept): `30 3 * * * /opt/ovpmon/deploy/docker/backup.sh --stop --keep 14 >> /var/log/ovpmon-backup.log 2>&1`.
|
||||
|
||||
A live backup copies the PKI and configuration reliably; a database file that is written at that very moment may be caught half-way, which `--stop` avoids (and `update.sh` always backs up a stopped stack for its final snapshot). The backup holds private keys, password hashes and the secret: the directory is mode 700, the files mode 600. Store copies off the host and protect them.
|
||||
|
||||
Manual equivalent for one volume (project `ovpmon`):
|
||||
|
||||
```bash
|
||||
mkdir -p backups/manual
|
||||
docker run --rm -v ovpmon_db_data:/data:ro -v "$PWD/backups/manual":/backup alpine \
|
||||
tar -czf /backup/db_data.tar.gz -C /data .
|
||||
```
|
||||
|
||||
### Restore
|
||||
|
||||
```bash
|
||||
deploy/docker/restore.sh backups/20261005T101500Z # asks, stops the stack, restores, prints the start command
|
||||
deploy/docker/restore.sh backups/20261005T101500Z --yes --start
|
||||
```
|
||||
|
||||
It verifies the archives first, saves the current content to `backups/<timestamp>-pre-restore`, empties each volume and fills it from the archive. Volumes are not removed. `.env` is not touched (a difference to the copy in the backup is reported). Manual equivalent:
|
||||
|
||||
```bash
|
||||
docker compose stop # or: -f docker-compose.allinone.yml
|
||||
docker run --rm -v ovpmon_db_data:/data -v "$PWD/backups/20261005T101500Z":/backup:ro alpine \
|
||||
sh -c 'rm -rf /data/* /data/.[!.]* /data/..?* && tar -xzf /backup/db_data.tar.gz -C /data'
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
A single database can also be put back from its migration backup in `db_data`: stop the stack, copy `<db>.bak-<timestamp>` over the database file, start the OLD release (see [Database migrations](../../General/Database_Migrations.md)).
|
||||
|
||||
### Rollback to the previous version
|
||||
|
||||
```bash
|
||||
deploy/docker/update.sh --rollback
|
||||
```
|
||||
|
||||
After confirmation: stop, restore all volumes from the newest complete backup (current content saved first), start the images recorded in that backup. Use it when an update completed but the new version misbehaves. Data created after that backup is lost (it is in the `-pre-restore` copy).
|
||||
|
||||
## Switching between variants
|
||||
|
||||
Both variants use the same volumes, so with the same project name the data can be used by the other variant: stop the running one (`docker compose [-f docker-compose.allinone.yml] stop`), take a backup, run `install.sh --variant <other> --project <same name>`. This path has not been tested in a real run; keep the backup. Starting both at once is refused.
|
||||
|
||||
## What is preserved on update
|
||||
|
||||
| Item | On update |
|
||||
|---|---|
|
||||
| Databases (`db_data`) | Kept. Backed up twice (before and after the stop), migrated additively with their own `<db>.bak-*` copy; restored automatically if the update fails after the stop |
|
||||
| PKI (`ovp_pki`): CA, keys, certificates, CRL | Kept, backed up. The easy-rsa scripts are copied only when the volume does not have them yet |
|
||||
| Client profiles (`ovp_client_config`) | Kept, backed up |
|
||||
| Server configuration (`ovp_config`) | Kept, backed up (the new image does not overwrite it) |
|
||||
| OpenVPN logs and status file (`ovp_logs`) | Kept |
|
||||
| `.env` (secret, ports) | Kept, copied into every backup |
|
||||
| User sessions | Stay valid while `JWT_SECRET` is unchanged |
|
||||
| Images | Replaced; the previous ones stay tagged `<name>:previous` |
|
||||
| Containers | Recreated; running VPN sessions are interrupted and clients reconnect; the OpenVPN process has to be started again (see troubleshooting) |
|
||||
| Container file system, `profiler.log`, `openvpn_gatherer.log` | Not kept (use `docker logs`) |
|
||||
| Backups in `backups/` | The newest 5 kept, older ones pruned after a successful update; `-pre-restore` copies are never pruned automatically |
|
||||
| Volumes | Never deleted by any script; `down -v` is never used |
|
||||
|
||||
Related: [Database migrations](../../General/Database_Migrations.md), [Deployment plan](../../Changes/2026-10-05_Deployment_Scenarios_PLAN.md).
|
||||
@@ -0,0 +1,93 @@
|
||||
# Containers (variants A and B)
|
||||
|
||||
Install the whole suite with Docker: nothing but Docker is needed on the host. This page: choose a variant, check the requirements, install. Next pages: [Operations](Operations.md) (update, backup, rollback), [Reference](Reference.md) (`.env`, ports, volumes), [Troubleshooting](Troubleshooting.md).
|
||||
|
||||
## Quick start
|
||||
|
||||
On a host with Docker (root or a member of the `docker` group):
|
||||
|
||||
```bash
|
||||
git clone <repository> && cd OpenVPN-Monitoring-Simple
|
||||
deploy/docker/install.sh --variant b # or --variant a, see the table below
|
||||
```
|
||||
|
||||
The script prints the URL and the **administrator login and password (shown once)**. Open the URL, then follow [First steps](../First_Steps.md).
|
||||
|
||||
## Variants
|
||||
|
||||
Two variants, both installed and updated by the scripts in `deploy/docker/`:
|
||||
|
||||
| | Variant A: one container | Variant B: one container per component |
|
||||
|---|---|---|
|
||||
| Compose file | `docker-compose.allinone.yml` | `docker-compose.yml` |
|
||||
| Containers | `ovp-allinone` (nginx, gunicorn, gatherer, uvicorn, OpenVPN under `supervisord`) | `ovp-ui`, `ovp-api`, `ovp-gatherer`, `ovp-profiler` |
|
||||
| Image build | `deploy/allinone/Dockerfile` (build context: repository root) | one Dockerfile per component (`APP_UI`, `APP_CORE`, `APP_PROFILER`) |
|
||||
| Choose it when | one host, simplest operation, one thing to start/stop/back up | you want to restart, scale or inspect components separately, or follow the usual one-process-per-container practice |
|
||||
| Trade-off | a failing process is restarted by `supervisord`, the container stays up; one image to rebuild for any change | more moving parts, internal network `ovp-net` |
|
||||
|
||||
Both variants use the **same five named volumes with the same in-container paths**, the same environment variables and the same published ports. Backups look identical.
|
||||
|
||||
> **Only one variant can run per host.** Both publish the same host ports (`80/tcp`, `1194/udp` by default) and use fixed container names (`ovp-*`). The scripts refuse to start a variant while a container of the other one is running.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Docker Engine with the compose plugin (`docker compose`, v2, preferred) or `docker-compose`.
|
||||
- The Docker daemon running and usable by the user that runs the scripts (root, or a member of the `docker` group).
|
||||
- Access to `/dev/net/tun` on the host and the `NET_ADMIN` capability (already set in the compose files).
|
||||
- Free disk space: about 2 GB for images and builds, plus room for backups (the scripts check both).
|
||||
- Internet access for the first build (base images, npm, pip) and for the backup helper image (`alpine:3`). For offline hosts see [Troubleshooting](Troubleshooting.md).
|
||||
- `openssl` is optional (random secret otherwise comes from `/dev/urandom`).
|
||||
|
||||
## Install
|
||||
|
||||
Clone the repository, change into it and run the script (as root or a docker user):
|
||||
|
||||
```bash
|
||||
# Variant B: one container per component
|
||||
deploy/docker/install.sh --variant b
|
||||
|
||||
# Variant A: everything in one container
|
||||
deploy/docker/install.sh --variant a
|
||||
|
||||
# Options
|
||||
deploy/docker/install.sh --variant b --project ovpmon --http-port 8080 --vpn-port 1194 --admin-user admin
|
||||
```
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--variant a\|b` | required |
|
||||
| `--project NAME` | compose project name = prefix of the volume names (default `ovpmon`: volumes `ovpmon_db_data`, ...) |
|
||||
| `--http-port N` | host port of the UI (written to `.env` as `OVPMON_HTTP_PORT`, default 80) |
|
||||
| `--vpn-port N` | host UDP port of OpenVPN (`OVPMON_VPN_PORT`, default 1194) |
|
||||
| `--admin-user NAME` | login of the first administrator (default `admin`) |
|
||||
|
||||
What `install.sh` does:
|
||||
|
||||
1. **Preflight:** docker and compose, running daemon, the other variant is not running, no foreign container with the same names, ports free, free disk space.
|
||||
2. **`.env`** next to the compose files, only if it does not exist: mode 600, random `JWT_SECRET`, initial administrator with a generated 24-character password. An existing `.env` is never overwritten (`--http-port` / `--vpn-port` only set their own keys in it).
|
||||
3. **Build, start** (`docker compose up -d`), write the state file `.ovpmon-deploy` (variant and project; used by `update.sh`, `backup.sh`, `restore.sh`), wait up to 3 minutes for the health checks.
|
||||
4. **Initial administrator:** when the users table is not empty, `OVPMON_INITIAL_ADMIN_*` are removed from `.env` and the container that reads them is recreated (variant B: `app-api`, variant A: `ovpmon`). If the table cannot be read or is empty, the lines stay in `.env` and a warning says so.
|
||||
5. **Result:** URL, ports, and the administrator login and password. **The password is shown once** and stored nowhere else. `JWT_SECRET` is never printed.
|
||||
|
||||
Running it again is safe: it rebuilds and starts, keeps `.env`, and makes no new administrator.
|
||||
|
||||
Then follow [First steps](../First_Steps.md) (sign in, initialize the PKI, start the VPN server). Put TLS in front of the UI (see [Security](Troubleshooting.md#security)).
|
||||
|
||||
### Without the script
|
||||
|
||||
```bash
|
||||
cat > .env <<EOT
|
||||
JWT_SECRET=$(openssl rand -hex 32)
|
||||
OVPMON_INITIAL_ADMIN_USER=admin
|
||||
OVPMON_INITIAL_ADMIN_PASSWORD=<strong password>
|
||||
EOT
|
||||
chmod 600 .env
|
||||
docker compose up -d --build # variant B
|
||||
docker compose -f docker-compose.allinone.yml up -d --build # variant A
|
||||
```
|
||||
|
||||
After the first start remove the two `OVPMON_INITIAL_ADMIN_*` lines from `.env` and recreate `app-api` (B) or `ovpmon` (A).
|
||||
|
||||
## Next
|
||||
|
||||
[First steps](../First_Steps.md) · [Operations](Operations.md) · [Reference](Reference.md) · [Troubleshooting](Troubleshooting.md) · [Choose another method](../README.md)
|
||||
@@ -0,0 +1,49 @@
|
||||
# Containers: reference
|
||||
|
||||
Configuration (`.env`), ports and volumes of the container installation. Install: [Containers](README.md).
|
||||
|
||||
## `.env` reference
|
||||
|
||||
| Variable | Required | Default | Meaning |
|
||||
|---|---|---|---|
|
||||
| `JWT_SECRET` | yes | none (compose refuses to start) | Signing key of both APIs (`OVPMON_API_SECRET_KEY`). At least 32 characters, no `change-me`/`changeme`: `install.sh`, `update.sh` and the all-in-one container refuse a weak value. Changing it logs every user out. Keep the same value across updates |
|
||||
| `OVPMON_INITIAL_ADMIN_USER`, `OVPMON_INITIAL_ADMIN_PASSWORD` | first start only | empty | Seed for the first user, used only while the users table is empty. Removed by `install.sh` afterwards |
|
||||
| `OVPMON_CORS_ORIGINS` | no | empty (off) | Comma-separated extra origins; the UI is same-origin behind nginx |
|
||||
| `OVPMON_HTTP_PORT` | no | `80` | Host port of the UI |
|
||||
| `OVPMON_VPN_PORT` | no | `1194` | Host UDP port of OpenVPN (the container side is always 1194) |
|
||||
|
||||
Variables of the scripts (environment of the shell, not `.env`): `OVPMON_BACKUP_DIR` (backup root, default `./backups`), `OVPMON_BACKUP_IMAGE` (helper image, default `alpine:3`), `OVPMON_HEALTH_TIMEOUT` (seconds, default 180), `OVPMON_MIN_FREE_MB` (docker data, default 2048), `OVPMON_MIN_FREE_BACKUP_MB` (backups, default 1024).
|
||||
|
||||
`OVPMON_VPN_PORT` changes only the host side of the mapping. If you change the OpenVPN port in the server settings of the UI, the client profiles carry that port; keep the two consistent.
|
||||
|
||||
## Ports
|
||||
|
||||
| Port | Published | Purpose |
|
||||
|---|---|---|
|
||||
| `${OVPMON_HTTP_PORT:-80}/tcp` | yes | UI and reverse proxy to both APIs (plain HTTP) |
|
||||
| `${OVPMON_VPN_PORT:-1194}/udp` | yes | OpenVPN |
|
||||
| `5001` (monitoring API), `8000` (profiler API) | no | variant B: `expose`d on `ovp-net` only; variant A: listen on `127.0.0.1` inside the container |
|
||||
|
||||
## Volumes: what is stored where
|
||||
|
||||
| Volume | Path in the container | Content | Mounted by (B) |
|
||||
|---|---|---|---|
|
||||
| `ovp_logs` | `/var/log/openvpn` | `openvpn-status.log` and OpenVPN logs | gatherer, profiler |
|
||||
| `ovp_config` | `/etc/openvpn` | `server.conf` generated by the profiler | profiler |
|
||||
| `ovp_pki` | `/app/easy-rsa` | easy-rsa scripts and `pki/` (CA, server and client keys and certificates, CRL, `ta.key`, `dh.pem`) | profiler |
|
||||
| `ovp_client_config` | `/app/client-config` | generated client `.ovpn` files | profiler |
|
||||
| `db_data` | `/app/db` | `ovpn_profiler.db`, `openvpn_monitor.db`, migration backups `*.db.bak-*` | gatherer, api, profiler |
|
||||
|
||||
Not stored in volumes (lost when the container is recreated): the container file system, `profiler.log` and `openvpn_gatherer.log` (written into the working directory), supervisor state. Application logs go to `docker logs`.
|
||||
|
||||
Volume names are `<project>_<volume>`; the scripts find them by the compose labels, so any project name works.
|
||||
|
||||
### Layout of variant A
|
||||
|
||||
The code is in `/app/APP_CORE` and `/app/APP_PROFILER`; the volumes are mounted at the same paths as in variant B (`/app/db`, `/app/easy-rsa`, `/app/client-config`, `/etc/openvpn`, `/var/log/openvpn`).
|
||||
|
||||
The profiler resolves `easy-rsa/` and `client-config/` relative to its working directory (`services/pki.py`, `routers/profiles.py`), and stores `client-config/<name>.ovpn` as a relative path in its database. In variant B that directory is `/app`. Variant A keeps it that way: **`supervisord` starts the profiler with working directory `/app`** (`uvicorn --app-dir /app/APP_PROFILER main:app`), so `/app/easy-rsa` and `/app/client-config` are the volumes. No symlinks are used, and the database paths are identical in both variants (so a volume set can be used by either variant). The monitoring API and the gatherer run with working directory `/app/APP_CORE`, where `config.ini` lives; their database path comes from `OVPMON_OPENVPN_MONITOR_DB_PATH=/app/db/openvpn_monitor.db`.
|
||||
|
||||
Processes in `ovp-allinone` (`deploy/allinone/supervisord.conf`, started in this order, all with `autorestart`, logs to stdout/stderr): `gatherer`, `api` (`gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app`), `profiler` (`uvicorn` on `127.0.0.1:8000`, no reload), `nginx`. OpenVPN is started by the profiler API on request (direct start inside containers), as in variant B.
|
||||
|
||||
`deploy/allinone/entrypoint.sh` runs before `supervisord`: secret mapping (`JWT_SECRET` → `OVPMON_API_SECRET_KEY` when only the first is set), `/dev/net/tun`, easy-rsa workspace (copied only when the volume does not have it yet), NAT and MSS rules without duplicates, the nginx configuration rendered from `APP_UI/default.conf.template` for `127.0.0.1`, then the **database migration as an explicit step**: the container does not start if it fails. The services then run with `OVPMON_AUTO_MIGRATE=0` (they only verify the schema).
|
||||
@@ -0,0 +1,30 @@
|
||||
# Containers: troubleshooting and security
|
||||
|
||||
Install: [Containers](README.md). Update and backup: [Operations](Operations.md).
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Cause and action |
|
||||
|---|---|
|
||||
| `port 80/tcp is already in use` | Another service uses the port. Install with `--http-port 8080` or set `OVPMON_HTTP_PORT` in `.env` (same for `OVPMON_VPN_PORT`) |
|
||||
| `container 'ovp-...' of the OTHER variant is running` | Variants A and B cannot run together. Stop the other stack first |
|
||||
| `container 'ovp-ui' ... belongs to compose project 'x'` | A stack of another project uses the fixed names. Use `--project x` or remove that stack |
|
||||
| Health check does not turn healthy | `docker compose ps`, then `docker compose logs --tail 100 <service>` (A: `docker logs ovp-allinone`). The scripts print the last log lines of failing services. The profiler allows 40 s and the all-in-one container 60 s before failures count |
|
||||
| `FATAL: ... newer than this version` / migration "too new" | The database was migrated by a newer release. Do not start the old version on it: update to the newer sources, or restore a matching backup (`update.sh --rollback` or `restore.sh`) |
|
||||
| Migration failed | Nothing was started and the volumes are restored by the automatic rollback. The report names the migration; the database copy `<db>.bak-*` is in `db_data`. Send the report with the problem |
|
||||
| `JWT_SECRET must be set in .env` | `.env` missing or empty value; run `install.sh` or add `JWT_SECRET=$(openssl rand -hex 32)` |
|
||||
| `JWT_SECRET in .env is too short` / `a placeholder/default value` (the all-in-one container: `FATAL: JWT_SECRET is ...`; a service exits with `Refusing to start`) | The signing key is weak (under 32 characters or contains `change-me`/`changeme`). Set `JWT_SECRET=$(openssl rand -hex 32)` in `.env` and run the script again; all users must then sign in again |
|
||||
| `permission denied` on docker | Run as root or add the user to the `docker` group. Backups belong to the user that runs the scripts |
|
||||
| Permission errors on bind mounts on SELinux hosts | Backup and restore bind-mount `backups/` into a container; label the directory for containers (`chcon -Rt container_file_t backups`) |
|
||||
| Cannot pull `alpine:3` (offline) | Make an image with `sh`, `tar` and `sha256sum` available locally and set `OVPMON_BACKUP_IMAGE`; use `--no-pull` with `update.sh` |
|
||||
| `/dev/net/tun` missing | Load the module on the host (`modprobe tun`); the compose files map the device |
|
||||
| VPN does not start after an update | The containers were recreated and the profiler starts OpenVPN only on request: start the server in the UI. Check that the server configuration exists (`ovp_config` volume) |
|
||||
| The UI answers 502 right after start | The APIs are still starting; wait for the health checks |
|
||||
|
||||
## Security
|
||||
|
||||
- Put **TLS in front** of the UI (reverse proxy or a certificate in nginx): the container serves plain HTTP. See [Nginx configuration](../System_Services/Nginx_Configuration.md).
|
||||
- `.env` holds the signing secret: mode 600, owned by the operator, never committed (`.gitignore` lists it). The scripts never print `JWT_SECRET`; the generated administrator password is shown once and removed from `.env` after the first start.
|
||||
- Backups contain the PKI (CA and server private keys), the databases (password hashes, 2FA secrets) and a copy of `.env`: keep them mode 700/600 and store off-host copies encrypted.
|
||||
- The profiler container is privileged for networking (`NET_ADMIN`, TUN). Variant A runs everything in that one container; its APIs listen on `127.0.0.1` only, so only nginx (80) and OpenVPN (1194/udp) are reachable.
|
||||
- No secrets in logs: the scripts only log names and paths; the services log the source of the secret, not its value.
|
||||
@@ -0,0 +1,36 @@
|
||||
# First steps after the install
|
||||
|
||||
The same for every installation method. About ten minutes. You need the URL and the administrator login and password printed by the install script.
|
||||
|
||||
| # | Where in the UI | What to do |
|
||||
|---|---|---|
|
||||
| 1 | Login page | Open the URL: containers `http://<host>[:port]`, system services `https://<host>:8088` (the certificate is self-signed: check the fingerprint printed by the installer, then accept). Sign in with the printed login and password |
|
||||
| 2 | **Account Settings** | Change the username and the password; enable two-factor authentication |
|
||||
| 3 | **PKI** | Check the parameters, press **Initialize PKI**. It runs in the background with progress on the page (key generation takes a while). The **VPN** menu stays locked until it is done |
|
||||
| 4 | **VPN** | Set the server parameters (port, VPN network, routes, DNS) and press **Apply Configuration**: this writes the OpenVPN `server.conf` |
|
||||
| 5 | **Server Process** | Press **Start Service**. The page shows the state of OpenVPN |
|
||||
| 6 | **Certificates** | **Create New Client**, then download its `.ovpn` file (the download icon in the row). Give the file to the user |
|
||||
| 7 | the host | Open the ports and set up NAT (below) |
|
||||
| 8 | a client | Import the `.ovpn` file into an OpenVPN client and connect. The client appears on **Clients** and **Analytics** |
|
||||
|
||||
## The network side (step 7)
|
||||
|
||||
| Method | What is done for you | What you do |
|
||||
|---|---|---|
|
||||
| Containers | forwarding, NAT and MSS rules are set inside the container | publish `80/tcp` (or your `--http-port`) and the VPN `udp` port; put TLS in front of the UI |
|
||||
| System services | `net.ipv4.ip_forward=1` is set; the firewall is **not** touched | open the HTTPS port (`8088`) and the VPN port; NAT for the clients: [Firewall](System_Services/Firewall.md) (`deploy/native/firewall.sh`) |
|
||||
|
||||
If you change the OpenVPN port in the **VPN** page, the client profiles carry the new port; with containers keep it consistent with `OVPMON_VPN_PORT`.
|
||||
|
||||
## If something does not work
|
||||
|
||||
| Symptom | Look at |
|
||||
|---|---|
|
||||
| The page does not open | the install script's final summary and health checks; [Containers](Containers/Troubleshooting.md) or [System services](System_Services/Troubleshooting.md) |
|
||||
| **VPN** menu is locked | the PKI is not initialized yet (step 3) |
|
||||
| Server does not start | the VPN page was not applied (step 4); then the log: `docker logs` or `/var/log/openvpn/` / `journalctl -u openvpn-server@server` |
|
||||
| The client connects but has no Internet | forwarding or NAT is missing (step 7) |
|
||||
|
||||
## What next
|
||||
|
||||
Regular backups ([containers](Containers/Operations.md), [system services](System_Services/Operations.md)), updates (same pages), TLS and host hardening ([Nginx](System_Services/Nginx_Configuration.md), [hardening](System_Services/Troubleshooting.md#host-hardening-recommended-not-done-by-the-scripts)), [security model](../General/Security_Architecture.md).
|
||||
@@ -0,0 +1,42 @@
|
||||
# Installation
|
||||
|
||||
Two ways to install, both with scripts that check the host, generate the secrets, start everything and print the first administrator login. Pick one; the steps **after** the install are the same: [First steps](First_Steps.md).
|
||||
|
||||
## Choose a method
|
||||
|
||||
| | [Containers](Containers/README.md) | [System services](System_Services/README.md) |
|
||||
|---|---|---|
|
||||
| Choose it when | the host has Docker, or you want the simplest operation | no containers wanted; Alpine, Debian or Ubuntu host |
|
||||
| Needs on the host | Docker Engine with the compose plugin, `/dev/net/tun` | root, Internet access, Alpine 3.23 / Debian 12 / Ubuntu 24.04 |
|
||||
| Install command | `deploy/docker/install.sh --variant a\|b` | `deploy/native/install.sh --prefix DIR` |
|
||||
| Variants | **A**: everything in one container; **B**: one container per component | one per OS (the script detects it) |
|
||||
| Web UI address | `http://<host>` (port 80, change with `--http-port`); put TLS in front | `https://<host>:8088` (self-signed certificate, change with `--https-port`) |
|
||||
| VPN port | `1194/udp` (`--vpn-port`) | `1194/udp` by default, set in the UI |
|
||||
| Free space | about 2 GB | about 1 GB |
|
||||
| Update, backup, rollback | `update.sh`, `backup.sh`, `restore.sh` in `deploy/docker/` | `update.sh`, `backup.sh`, `restore.sh` in `deploy/native/` |
|
||||
| Details | [Containers](Containers/README.md) | [System services](System_Services/README.md) |
|
||||
|
||||
Not sure? If Docker is already on the host, use **Containers, variant A**; otherwise **System services**.
|
||||
|
||||
Use **one method per host**: both use the VPN port `1194/udp` by default. For containers, only one variant can run at a time.
|
||||
|
||||
## The same in both methods
|
||||
|
||||
- Run the script as root (or, for containers, as a member of the `docker` group) from a clone of this repository.
|
||||
- The script prints the URL and the **administrator password once**; it is stored nowhere else. No default account exists.
|
||||
- Containers: running `install.sh` again is safe, it keeps `.env` and the data. System services: after a **failed** install, run it again to resume; a finished installation is changed only with `update.sh`.
|
||||
- Updates always take a verified backup first and roll back automatically if something fails.
|
||||
- The scripts do **not** open firewall ports and do not harden SSH. Open the UI port and the VPN port yourself; NAT for the VPN clients: [Firewall](System_Services/Firewall.md) (containers set their own NAT rules).
|
||||
|
||||
## After the install
|
||||
|
||||
[First steps](First_Steps.md): sign in, secure the account, initialize the PKI, configure and start the VPN server, create the first client profile.
|
||||
|
||||
## Other pages
|
||||
|
||||
| Topic | Page |
|
||||
|---|---|
|
||||
| Configuration variables | [General: Configuration](../General/Configuration.md) |
|
||||
| Nginx and TLS for the UI | [Nginx configuration](System_Services/Nginx_Configuration.md) |
|
||||
| Database schema changes on update | [Database migrations](../General/Database_Migrations.md) |
|
||||
| Security model | [Security architecture](../General/Security_Architecture.md) |
|
||||
@@ -1,261 +0,0 @@
|
||||
# Scenario 1: installation in containers
|
||||
|
||||
Two variants, both installed and updated by the scripts in `deploy/docker/`:
|
||||
|
||||
| | Variant A: one container | Variant B: one container per component |
|
||||
|---|---|---|
|
||||
| Compose file | `docker-compose.allinone.yml` | `docker-compose.yml` |
|
||||
| Containers | `ovp-allinone` (nginx, gunicorn, gatherer, uvicorn, OpenVPN under `supervisord`) | `ovp-ui`, `ovp-api`, `ovp-gatherer`, `ovp-profiler` |
|
||||
| Image build | `deploy/allinone/Dockerfile` (build context: repository root) | one Dockerfile per component (`APP_UI`, `APP_CORE`, `APP_PROFILER`) |
|
||||
| Choose it when | one host, simplest operation, one thing to start/stop/back up | you want to restart, scale or inspect components separately, or follow the usual one-process-per-container practice |
|
||||
| Trade-off | a failing process is restarted by `supervisord`, the container stays up; one image to rebuild for any change | more moving parts, internal network `ovp-net` |
|
||||
|
||||
Both variants use the **same five named volumes with the same in-container paths**, the same environment variables and the same published ports. Backups look identical.
|
||||
|
||||
> **Only one variant can run per host.** Both publish the same host ports (`80/tcp`, `1194/udp` by default) and use fixed container names (`ovp-*`). The scripts refuse to start a variant while a container of the other one is running.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Docker Engine with the compose plugin (`docker compose`, v2, preferred) or `docker-compose`.
|
||||
- The Docker daemon running and usable by the user that runs the scripts (root, or a member of the `docker` group).
|
||||
- Access to `/dev/net/tun` on the host and the `NET_ADMIN` capability (already set in the compose files).
|
||||
- Free disk space: about 2 GB for images and builds, plus room for backups (the scripts check both).
|
||||
- Internet access for the first build (base images, npm, pip) and for the backup helper image (`alpine:3`). For offline hosts see *Troubleshooting*.
|
||||
- `openssl` is optional (random secret otherwise comes from `/dev/urandom`).
|
||||
|
||||
## Install
|
||||
|
||||
Clone the repository, change into it and run the script (as root or a docker user):
|
||||
|
||||
```bash
|
||||
# Variant B: one container per component
|
||||
deploy/docker/install.sh --variant b
|
||||
|
||||
# Variant A: everything in one container
|
||||
deploy/docker/install.sh --variant a
|
||||
|
||||
# Options
|
||||
deploy/docker/install.sh --variant b --project ovpmon --http-port 8080 --vpn-port 1194 --admin-user admin
|
||||
```
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--variant a\|b` | required |
|
||||
| `--project NAME` | compose project name = prefix of the volume names (default `ovpmon`: volumes `ovpmon_db_data`, ...) |
|
||||
| `--http-port N` | host port of the UI (written to `.env` as `OVPMON_HTTP_PORT`, default 80) |
|
||||
| `--vpn-port N` | host UDP port of OpenVPN (`OVPMON_VPN_PORT`, default 1194) |
|
||||
| `--admin-user NAME` | login of the first administrator (default `admin`) |
|
||||
|
||||
What `install.sh` does:
|
||||
|
||||
1. **Preflight:** docker and compose, running daemon, the other variant is not running, no foreign container with the same names, ports free, free disk space.
|
||||
2. **`.env`** next to the compose files, only if it does not exist: mode 600, random `JWT_SECRET`, initial administrator with a generated 24-character password. An existing `.env` is never overwritten (`--http-port` / `--vpn-port` only set their own keys in it).
|
||||
3. **Build, start** (`docker compose up -d`), write the state file `.ovpmon-deploy` (variant and project; used by `update.sh`, `backup.sh`, `restore.sh`), wait up to 3 minutes for the health checks.
|
||||
4. **Initial administrator:** when the users table is not empty, `OVPMON_INITIAL_ADMIN_*` are removed from `.env` and the container that reads them is recreated (variant B: `app-api`, variant A: `ovpmon`). If the table cannot be read or is empty, the lines stay in `.env` and a warning says so.
|
||||
5. **Result:** URL, ports, and the administrator login and password. **The password is shown once** and stored nowhere else. `JWT_SECRET` is never printed.
|
||||
|
||||
Running it again is safe: it rebuilds and starts, keeps `.env`, and makes no new administrator.
|
||||
|
||||
Then in the UI: sign in, **PKI Configuration → Initialize PKI**, generate the server configuration and start the VPN server. Put TLS in front of the UI (see *Security*).
|
||||
|
||||
### Without the script
|
||||
|
||||
```bash
|
||||
cat > .env <<EOT
|
||||
JWT_SECRET=$(openssl rand -hex 32)
|
||||
OVPMON_INITIAL_ADMIN_USER=admin
|
||||
OVPMON_INITIAL_ADMIN_PASSWORD=<strong password>
|
||||
EOT
|
||||
chmod 600 .env
|
||||
docker compose up -d --build # variant B
|
||||
docker compose -f docker-compose.allinone.yml up -d --build # variant A
|
||||
```
|
||||
|
||||
After the first start remove the two `OVPMON_INITIAL_ADMIN_*` lines from `.env` and recreate `app-api` (B) or `ovpmon` (A).
|
||||
|
||||
## `.env` reference
|
||||
|
||||
| Variable | Required | Default | Meaning |
|
||||
|---|---|---|---|
|
||||
| `JWT_SECRET` | yes | none (compose refuses to start) | Signing key of both APIs (`OVPMON_API_SECRET_KEY`). Changing it logs every user out. Keep the same value across updates |
|
||||
| `OVPMON_INITIAL_ADMIN_USER`, `OVPMON_INITIAL_ADMIN_PASSWORD` | first start only | empty | Seed for the first user, used only while the users table is empty. Removed by `install.sh` afterwards |
|
||||
| `OVPMON_CORS_ORIGINS` | no | empty (off) | Comma-separated extra origins; the UI is same-origin behind nginx |
|
||||
| `OVPMON_HTTP_PORT` | no | `80` | Host port of the UI |
|
||||
| `OVPMON_VPN_PORT` | no | `1194` | Host UDP port of OpenVPN (the container side is always 1194) |
|
||||
|
||||
Variables of the scripts (environment of the shell, not `.env`): `OVPMON_BACKUP_DIR` (backup root, default `./backups`), `OVPMON_BACKUP_IMAGE` (helper image, default `alpine:3`), `OVPMON_HEALTH_TIMEOUT` (seconds, default 180), `OVPMON_MIN_FREE_MB` (docker data, default 2048), `OVPMON_MIN_FREE_BACKUP_MB` (backups, default 1024).
|
||||
|
||||
`OVPMON_VPN_PORT` changes only the host side of the mapping. If you change the OpenVPN port in the server settings of the UI, the client profiles carry that port; keep the two consistent.
|
||||
|
||||
## Ports
|
||||
|
||||
| Port | Published | Purpose |
|
||||
|---|---|---|
|
||||
| `${OVPMON_HTTP_PORT:-80}/tcp` | yes | UI and reverse proxy to both APIs (plain HTTP) |
|
||||
| `${OVPMON_VPN_PORT:-1194}/udp` | yes | OpenVPN |
|
||||
| `5001` (monitoring API), `8000` (profiler API) | no | variant B: `expose`d on `ovp-net` only; variant A: listen on `127.0.0.1` inside the container |
|
||||
|
||||
## Volumes: what is stored where
|
||||
|
||||
| Volume | Path in the container | Content | Mounted by (B) |
|
||||
|---|---|---|---|
|
||||
| `ovp_logs` | `/var/log/openvpn` | `openvpn-status.log` and OpenVPN logs | gatherer, profiler |
|
||||
| `ovp_config` | `/etc/openvpn` | `server.conf` generated by the profiler | profiler |
|
||||
| `ovp_pki` | `/app/easy-rsa` | easy-rsa scripts and `pki/` (CA, server and client keys and certificates, CRL, `ta.key`, `dh.pem`) | profiler |
|
||||
| `ovp_client_config` | `/app/client-config` | generated client `.ovpn` files | profiler |
|
||||
| `db_data` | `/app/db` | `ovpn_profiler.db`, `openvpn_monitor.db`, migration backups `*.db.bak-*` | gatherer, api, profiler |
|
||||
|
||||
Not stored in volumes (lost when the container is recreated): the container file system, `profiler.log` and `openvpn_gatherer.log` (written into the working directory), supervisor state. Application logs go to `docker logs`.
|
||||
|
||||
Volume names are `<project>_<volume>`; the scripts find them by the compose labels, so any project name works.
|
||||
|
||||
### Layout of variant A
|
||||
|
||||
The code is in `/app/APP_CORE` and `/app/APP_PROFILER`; the volumes are mounted at the same paths as in variant B (`/app/db`, `/app/easy-rsa`, `/app/client-config`, `/etc/openvpn`, `/var/log/openvpn`).
|
||||
|
||||
The profiler resolves `easy-rsa/` and `client-config/` relative to its working directory (`services/pki.py`, `routers/profiles.py`), and stores `client-config/<name>.ovpn` as a relative path in its database. In variant B that directory is `/app`. Variant A keeps it that way: **`supervisord` starts the profiler with working directory `/app`** (`uvicorn --app-dir /app/APP_PROFILER main:app`), so `/app/easy-rsa` and `/app/client-config` are the volumes. No symlinks are used, and the database paths are identical in both variants (so a volume set can be used by either variant). The monitoring API and the gatherer run with working directory `/app/APP_CORE`, where `config.ini` lives; their database path comes from `OVPMON_OPENVPN_MONITOR_DB_PATH=/app/db/openvpn_monitor.db`.
|
||||
|
||||
Processes in `ovp-allinone` (`deploy/allinone/supervisord.conf`, started in this order, all with `autorestart`, logs to stdout/stderr): `gatherer`, `api` (`gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app`), `profiler` (`uvicorn` on `127.0.0.1:8000`, no reload), `nginx`. OpenVPN is started by the profiler API on request (direct start inside containers), as in variant B.
|
||||
|
||||
`deploy/allinone/entrypoint.sh` runs before `supervisord`: secret mapping (`JWT_SECRET` → `OVPMON_API_SECRET_KEY` when only the first is set), `/dev/net/tun`, easy-rsa workspace (copied only when the volume does not have it yet), NAT and MSS rules without duplicates, the nginx configuration rendered from `APP_UI/default.conf.template` for `127.0.0.1`, then the **database migration as an explicit step**: the container does not start if it fails. The services then run with `OVPMON_AUTO_MIGRATE=0` (they only verify the schema).
|
||||
|
||||
## Update
|
||||
|
||||
```bash
|
||||
deploy/docker/update.sh # variant and project from .ovpmon-deploy
|
||||
deploy/docker/update.sh --yes # no questions
|
||||
deploy/docker/update.sh --no-pull # sources already in place / offline (no git pull, no base image refresh)
|
||||
deploy/docker/update.sh --rollback # manual rollback to the newest backup
|
||||
```
|
||||
|
||||
Each phase is logged separately:
|
||||
|
||||
| Phase | What happens | If it fails |
|
||||
|---|---|---|
|
||||
| 0 Preflight | state file, `.env`, compose configuration, running stack, the other variant not running, `db_data` volume exists, free space | nothing was changed |
|
||||
| 1 **Backup** | all five volumes → `backups/<UTC timestamp>/*.tar.gz` through a throwaway `alpine` container (volumes mounted read-only), copy of `.env` (mode 600), record of the current image IDs, `SHA256SUMS`; every archive is verified (`tar -tzf`) | the update is **refused**, nothing was changed |
|
||||
| 2 Sources | `git pull --ff-only` when the directory is a git checkout and `--no-pull` was not given | nothing was changed |
|
||||
| 3 Build | current images are tagged `<name>:previous`, then the new images are built while the old stack keeps running | nothing was changed, the old version still runs |
|
||||
| 4 Stop | the application containers are stopped (volumes are kept); a second, final backup of the volumes is taken now that nothing writes to the databases | automatic rollback |
|
||||
| 5 **Database migration** | a separate step, see below | automatic rollback, nothing is started |
|
||||
| 6 Start | `up -d` with the new images, wait for the health checks | automatic rollback |
|
||||
|
||||
Old backups: the newest 5 are kept; older ones are pruned only after a successful update. Volumes are never deleted and `down -v` is never used. The new `deploy/docker/*.sh` take effect on the next run (the running script is not replaced).
|
||||
|
||||
### Database migration as its own step
|
||||
|
||||
After the containers are stopped and before any new component starts, `update.sh` runs, for each database, a one-off container **from the new image with the same volumes**:
|
||||
|
||||
| Variant | Profiler database | Monitoring database |
|
||||
|---|---|---|
|
||||
| B | `app-profiler` image: `cd /app && python migrate.py` | `app-api` image: `cd /app && python migrate.py` |
|
||||
| A | `ovpmon` image: `cd /app/APP_PROFILER && python migrate.py` | `ovpmon` image: `cd /app/APP_CORE && python migrate.py` |
|
||||
|
||||
For each database it runs `python migrate.py --check` (exit 0 up to date, 2 pending, 1 error or database newer than the code), applies the pending migrations with `python migrate.py` and checks again. The reports are printed. A failure or a "too new" database aborts **before anything is started** and triggers the rollback.
|
||||
|
||||
What the migration does (details: [Database migrations](../General/Database_Migrations.md)): versioned, additive-only changes (`CREATE ... IF NOT EXISTS`, `ADD COLUMN` with defaults), never a drop or rewrite; before any change an integrity check and a consistent copy `<db>.bak-<UTC timestamp>` next to the database (newest 5 kept); after the change an integrity check and a comparison of row counts; on a mismatch everything is rolled back; a database newer than the application is not touched.
|
||||
|
||||
The migration also runs by itself when a service starts (variant B: profiler and API; variant A: the entrypoint, before `supervisord`), so a plain `docker compose up -d --build` is safe too. `update.sh` only makes it a visible, separate, controlled step.
|
||||
|
||||
### Automatic rollback
|
||||
|
||||
On any failure in phases 4 to 6: the stack is stopped, all five volumes are restored from the backup of this run, the `:previous` images are started (through a generated `compose.previous.yml` in the backup directory) and the result is reported with the backup path. If the rollback itself fails, the message says where the backup is and how to retry (`update.sh --rollback`, or `restore.sh`).
|
||||
|
||||
After a rollback the stack runs on the `:previous` images; the next `update.sh` run builds again and recreates the containers on the new images.
|
||||
|
||||
## Backup, restore, rollback
|
||||
|
||||
### Backup
|
||||
|
||||
```bash
|
||||
deploy/docker/backup.sh # live backup of the five volumes -> backups/<UTC timestamp>/
|
||||
deploy/docker/backup.sh --stop # stops the containers during the copy (consistent SQLite files), starts them again
|
||||
deploy/docker/backup.sh --keep 14 # afterwards keep the newest 14
|
||||
```
|
||||
|
||||
Cron example (nightly, consistent, 14 kept): `30 3 * * * /opt/ovpmon/deploy/docker/backup.sh --stop --keep 14 >> /var/log/ovpmon-backup.log 2>&1`.
|
||||
|
||||
A live backup copies the PKI and configuration reliably; a database file that is written at that very moment may be caught half-way, which `--stop` avoids (and `update.sh` always backs up a stopped stack for its final snapshot). The backup holds private keys, password hashes and the secret: the directory is mode 700, the files mode 600. Store copies off the host and protect them.
|
||||
|
||||
Manual equivalent for one volume (project `ovpmon`):
|
||||
|
||||
```bash
|
||||
mkdir -p backups/manual
|
||||
docker run --rm -v ovpmon_db_data:/data:ro -v "$PWD/backups/manual":/backup alpine \
|
||||
tar -czf /backup/db_data.tar.gz -C /data .
|
||||
```
|
||||
|
||||
### Restore
|
||||
|
||||
```bash
|
||||
deploy/docker/restore.sh backups/20261005T101500Z # asks, stops the stack, restores, prints the start command
|
||||
deploy/docker/restore.sh backups/20261005T101500Z --yes --start
|
||||
```
|
||||
|
||||
It verifies the archives first, saves the current content to `backups/<timestamp>-pre-restore`, empties each volume and fills it from the archive. Volumes are not removed. `.env` is not touched (a difference to the copy in the backup is reported). Manual equivalent:
|
||||
|
||||
```bash
|
||||
docker compose stop # or: -f docker-compose.allinone.yml
|
||||
docker run --rm -v ovpmon_db_data:/data -v "$PWD/backups/20261005T101500Z":/backup:ro alpine \
|
||||
sh -c 'rm -rf /data/* /data/.[!.]* /data/..?* && tar -xzf /backup/db_data.tar.gz -C /data'
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
A single database can also be put back from its migration backup in `db_data`: stop the stack, copy `<db>.bak-<timestamp>` over the database file, start the OLD release (see [Database migrations](../General/Database_Migrations.md)).
|
||||
|
||||
### Rollback to the previous version
|
||||
|
||||
```bash
|
||||
deploy/docker/update.sh --rollback
|
||||
```
|
||||
|
||||
After confirmation: stop, restore all volumes from the newest complete backup (current content saved first), start the images recorded in that backup. Use it when an update completed but the new version misbehaves. Data created after that backup is lost (it is in the `-pre-restore` copy).
|
||||
|
||||
## Switching between variants
|
||||
|
||||
Both variants use the same volumes, so with the same project name the data can be used by the other variant: stop the running one (`docker compose [-f docker-compose.allinone.yml] stop`), take a backup, run `install.sh --variant <other> --project <same name>`. This path has not been tested in a real run; keep the backup. Starting both at once is refused.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Cause and action |
|
||||
|---|---|
|
||||
| `port 80/tcp is already in use` | Another service uses the port. Install with `--http-port 8080` or set `OVPMON_HTTP_PORT` in `.env` (same for `OVPMON_VPN_PORT`) |
|
||||
| `container 'ovp-...' of the OTHER variant is running` | Variants A and B cannot run together. Stop the other stack first |
|
||||
| `container 'ovp-ui' ... belongs to compose project 'x'` | A stack of another project uses the fixed names. Use `--project x` or remove that stack |
|
||||
| Health check does not turn healthy | `docker compose ps`, then `docker compose logs --tail 100 <service>` (A: `docker logs ovp-allinone`). The scripts print the last log lines of failing services. The profiler allows 40 s and the all-in-one container 60 s before failures count |
|
||||
| `FATAL: ... newer than this version` / migration "too new" | The database was migrated by a newer release. Do not start the old version on it: update to the newer sources, or restore a matching backup (`update.sh --rollback` or `restore.sh`) |
|
||||
| Migration failed | Nothing was started and the volumes are restored by the automatic rollback. The report names the migration; the database copy `<db>.bak-*` is in `db_data`. Send the report with the problem |
|
||||
| `JWT_SECRET must be set in .env` | `.env` missing or empty value; run `install.sh` or add `JWT_SECRET=$(openssl rand -hex 32)` |
|
||||
| `permission denied` on docker | Run as root or add the user to the `docker` group. Backups belong to the user that runs the scripts |
|
||||
| Permission errors on bind mounts on SELinux hosts | Backup and restore bind-mount `backups/` into a container; label the directory for containers (`chcon -Rt container_file_t backups`) |
|
||||
| Cannot pull `alpine:3` (offline) | Make an image with `sh`, `tar` and `sha256sum` available locally and set `OVPMON_BACKUP_IMAGE`; use `--no-pull` with `update.sh` |
|
||||
| `/dev/net/tun` missing | Load the module on the host (`modprobe tun`); the compose files map the device |
|
||||
| VPN does not start after an update | The containers were recreated and the profiler starts OpenVPN only on request: start the server in the UI. Check that the server configuration exists (`ovp_config` volume) |
|
||||
| The UI answers 502 right after start | The APIs are still starting; wait for the health checks |
|
||||
|
||||
## Security
|
||||
|
||||
- Put **TLS in front** of the UI (reverse proxy or a certificate in nginx): the container serves plain HTTP. See [Nginx configuration](../General/Nginx_Configuration.md).
|
||||
- `.env` holds the signing secret: mode 600, owned by the operator, never committed (`.gitignore` lists it). The scripts never print `JWT_SECRET`; the generated administrator password is shown once and removed from `.env` after the first start.
|
||||
- Backups contain the PKI (CA and server private keys), the databases (password hashes, 2FA secrets) and a copy of `.env`: keep them mode 700/600 and store off-host copies encrypted.
|
||||
- The profiler container is privileged for networking (`NET_ADMIN`, TUN). Variant A runs everything in that one container; its APIs listen on `127.0.0.1` only, so only nginx (80) and OpenVPN (1194/udp) are reachable.
|
||||
- No secrets in logs: the scripts only log names and paths; the services log the source of the secret, not its value.
|
||||
|
||||
## What is preserved on update
|
||||
|
||||
| Item | On update |
|
||||
|---|---|
|
||||
| Databases (`db_data`) | Kept. Backed up twice (before and after the stop), migrated additively with their own `<db>.bak-*` copy; restored automatically if the update fails after the stop |
|
||||
| PKI (`ovp_pki`): CA, keys, certificates, CRL | Kept, backed up. The easy-rsa scripts are copied only when the volume does not have them yet |
|
||||
| Client profiles (`ovp_client_config`) | Kept, backed up |
|
||||
| Server configuration (`ovp_config`) | Kept, backed up (the new image does not overwrite it) |
|
||||
| OpenVPN logs and status file (`ovp_logs`) | Kept |
|
||||
| `.env` (secret, ports) | Kept, copied into every backup |
|
||||
| User sessions | Stay valid while `JWT_SECRET` is unchanged |
|
||||
| Images | Replaced; the previous ones stay tagged `<name>:previous` |
|
||||
| Containers | Recreated; running VPN sessions are interrupted and clients reconnect; the OpenVPN process has to be started again (see troubleshooting) |
|
||||
| Container file system, `profiler.log`, `openvpn_gatherer.log` | Not kept (use `docker logs`) |
|
||||
| Backups in `backups/` | The newest 5 kept, older ones pruned after a successful update; `-pre-restore` copies are never pruned automatically |
|
||||
| Volumes | Never deleted by any script; `down -v` is never used |
|
||||
|
||||
Related: [Database migrations](../General/Database_Migrations.md), [Deployment plan](../Changes/2026-10-05_Deployment_Scenarios_PLAN.md).
|
||||
@@ -1,493 +0,0 @@
|
||||
# Scenario 2: installation as system services (no containers)
|
||||
|
||||
Install and update on **Alpine (OpenRC)**, **Debian** and **Ubuntu** (systemd) with the scripts in `deploy/native/`. Nothing runs in a container. The web UI is part of the repository (`deploy/ui-dist`) and is installed automatically, so the host needs no Node.
|
||||
|
||||
| Script | Purpose |
|
||||
|---|---|
|
||||
| `deploy/native/build-ui.sh` | builds the web UI (Docker, or the local Node without a container) into a tarball and/or into the repository (`--publish`) |
|
||||
| `deploy/native/check-ui.sh` | checks that the committed UI build `deploy/ui-dist` matches the `APP_UI` sources (exit 1 when stale) |
|
||||
| `deploy/native/install.sh` | first installation: packages, user, code, virtualenvs, configuration, services, nginx with TLS, health checks |
|
||||
| `deploy/native/update.sh` | update with a verified backup, a separate database migration step and automatic rollback; `--rollback` for a manual one |
|
||||
| `deploy/native/backup.sh` / `restore.sh` | stand-alone backup (cron friendly) and restore |
|
||||
| `deploy/native/lib.sh` | shared functions and the OS adapter (sourced, not executed) |
|
||||
|
||||
All scripts run as root, support `-h`, log in one style (UTC time stamp, `=== PHASE n ===`) and append every log line to `/var/log/ovpmon-deploy.log`.
|
||||
|
||||
## What is installed
|
||||
|
||||
```
|
||||
Browser --https:8088--> nginx --/--------------> /var/www/ovpmon (UI files)
|
||||
--/api/----------> 127.0.0.1:5001 ovpmon-api (gunicorn, APP_CORE)
|
||||
--/profiles-api/-> 127.0.0.1:8000 ovpmon-profiler (uvicorn, APP_PROFILER)
|
||||
ovpmon-gatherer (APP_CORE): OpenVPN status log -> monitoring database
|
||||
ovpmon-profiler (user ovpmon) --doas--> /usr/local/sbin/ovpmon-helper (root) --> server.conf, CRL, OpenVPN service
|
||||
```
|
||||
|
||||
The three `ovpmon-*` services run as the unprivileged user `ovpmon`. Only the helper acts as root, through six fixed `doas` rules, and it validates everything it installs (see [Privilege separation](../Changes/2026-09-30_Privilege_Separation.md)). The services do not require OpenVPN to be running: the VPN server is created and started from the UI.
|
||||
|
||||
## Supported systems
|
||||
|
||||
| System | Tested version | Service manager | Notes |
|
||||
|---|---|---|---|
|
||||
| Alpine | 3.23 | OpenRC | the original reference platform |
|
||||
| Debian | 12 | systemd | |
|
||||
| Ubuntu | 24.04 LTS | systemd | needs the `universe` repository (`easy-rsa`, `opendoas`) |
|
||||
|
||||
Another version of these systems is refused with a warning unless you pass `--force` to `install.sh` (the update only warns). Other distributions are not supported (a Debian derivative works with `--force` at your own risk).
|
||||
|
||||
## Requirements
|
||||
|
||||
- A host with root access, a working package manager and Internet access (packages, Python packages from PyPI).
|
||||
- `/dev/net/tun` for OpenVPN (a normal VM has it; in containers it must be passed in).
|
||||
- Free space: about 1 GB for the code and virtualenvs (the script checks it), plus room for the backups.
|
||||
- Python 3.9 or newer (Alpine 3.23: 3.12, Debian 12: 3.11, Ubuntu 24.04: 3.12).
|
||||
- Free TCP ports `5001`, `8000` (on `127.0.0.1`) and the HTTPS port (default `8088`).
|
||||
- A UI build: the clone contains one (`deploy/ui-dist`, see below). **The host needs no Node.js** unless you choose `--build-ui`.
|
||||
- GNU tar (on Alpine the package `tar`; the installer adds it).
|
||||
|
||||
## The web UI
|
||||
|
||||
The UI is built from `APP_UI` (Vue/Vite). The repository carries a ready build in `deploy/ui-dist/` together with `SOURCE_HASH`, a SHA-256 over the UI sources it was built from (`APP_UI/src`, `public`, `index.html`, `package.json`, `package-lock.json`, `vite.config.js`, `jsconfig.json`). `install.sh` and `update.sh` find the UI themselves. The directory is outside `APP_UI`, so the container builds are not affected.
|
||||
|
||||
### Three ways to get the UI onto a host
|
||||
|
||||
| Way | Option | When |
|
||||
|---|---|---|
|
||||
| Committed build | none (automatic) | the normal case: `git clone`, `install.sh`, done; no Node, no Docker |
|
||||
| Build on the host | `--build-ui` | the committed build is stale or missing; builds from `APP_UI` now with Docker (when its daemon works) or the host's Node 20.19+ |
|
||||
| Build elsewhere | `--ui-dist FILE\|DIR` | a tarball from `build-ui.sh` or a directory with `index.html`, for example from a CI job or another machine |
|
||||
|
||||
Order used by `install.sh` and `update.sh`: **1.** `--ui-dist` (explicit, always installed), **2.** `--build-ui` (always builds fresh from the sources), **3.** the committed `deploy/ui-dist` of the checkout (automatic), **4.** nothing found: `install.sh` **stops** (it lists the ways out) unless `--no-ui` is given (a placeholder page on purpose); `update.sh` keeps the installed UI. `install.sh` also still accepts `deploy/native/ui-dist.tar.gz` as a last resort below the committed directory. `--ui-dist` and `--build-ui` exclude each other.
|
||||
|
||||
The installed web root records the hash it came from in `/var/www/ovpmon/.ui-source-hash` (`unknown` for archives that were not made by `build-ui.sh`). `update.sh` compares it with the `SOURCE_HASH` of the repository build: equal, the UI is not replaced (and it says so); different or missing (for example a host installed with `--no-ui`), the new UI is staged in phase 3 and swapped in phase 6, with the rest of the update, so it is part of the backup and the automatic rollback. The UI source is decided after `git pull`, so a pulled new build is used in the same run. The old UI is in the backup.
|
||||
|
||||
### Staleness guard
|
||||
|
||||
When the hash of the current `APP_UI` sources differs from `SOURCE_HASH`, the committed build is **older than the sources** (someone changed the UI and did not refresh the build). `install.sh` and `update.sh` then print a loud warning with the two hashes and the remedy, and still use the committed build (it works, it only lacks the latest UI changes). A host that needs the current UI adds `--build-ui`. A build without a valid `SOURCE_HASH` counts as stale.
|
||||
|
||||
### Maintainer routine
|
||||
|
||||
After every change in `APP_UI` (or its `package*.json`, `vite.config.js`), **before committing**:
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh --publish # rebuilds deploy/ui-dist/ and SOURCE_HASH from the current sources
|
||||
deploy/native/check-ui.sh # prints fresh | stale | missing; exit 0 | 1 | 2
|
||||
git add APP_UI deploy/ui-dist
|
||||
```
|
||||
|
||||
`check-ui.sh` also fits a release checklist or a CI step (it changes nothing). `--publish` replaces the content of `deploy/ui-dist/` by a move (the old directory is only deleted after the new one is in place).
|
||||
|
||||
### build-ui.sh
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh # Docker if it works, otherwise local Node -> deploy/native/ui-dist.tar.gz
|
||||
deploy/native/build-ui.sh --docker # node:20-alpine container (OVPMON_NODE_IMAGE or --image to change)
|
||||
deploy/native/build-ui.sh --local # Node >= 20.19 and npm of this machine, no container
|
||||
deploy/native/build-ui.sh --local --node-download # temporary official Node 20, deleted after the build
|
||||
deploy/native/build-ui.sh --publish # refresh deploy/ui-dist/ in the repository
|
||||
deploy/native/build-ui.sh -o /tmp/ui.tar.gz # tarball for another host (also with --publish)
|
||||
deploy/native/build-ui.sh --check # only check that the builder is usable
|
||||
```
|
||||
|
||||
Without `--docker`/`--local` the script uses Docker when its daemon answers, otherwise the local Node. The tarball holds the content of `dist/` and `SOURCE_HASH`. **Nothing is written into the source tree**: a container sees `APP_UI` read-only; `--local` copies it (without `node_modules` and `dist`) into a temporary directory and runs `npm ci` there (`npm install` without a lock file), so the repository gets no `node_modules` and no `dist`.
|
||||
|
||||
`--local` needs Node 20.19 or newer with npm. When it is missing or too old the script prints what to do and stops:
|
||||
|
||||
| System | What to do |
|
||||
|---|---|
|
||||
| Alpine | `apk add nodejs npm` (check `node --version` afterwards) |
|
||||
| Debian / Ubuntu | the distribution's Node is usually too old (Debian 12 and Ubuntu 24.04 ship Node 18): add `--node-download` (needs `apt-get install -y curl xz-utils`), or install Node 20+ with npm from nodejs.org / NodeSource |
|
||||
| anything else | Node 20.19+ from nodejs.org, or build with `--docker` on a machine with Docker |
|
||||
|
||||
`--node-download` fetches `SHASUMS256.txt` from `https://nodejs.org/dist/latest-v20.x/`, picks `node-v20.*-linux-<x64|arm64>.tar.xz`, verifies its SHA-256, unpacks it into a temporary directory (npm cache included), builds with it and deletes everything; nothing is installed on the host. glibc systems only: on Alpine (musl) it refuses and points to `apk add nodejs npm`. It needs `curl`, `tar`, `xz` and access to nodejs.org (`OVPMON_NODE_MAJOR` selects another major version).
|
||||
|
||||
## Install
|
||||
|
||||
Clone the repository on the target host (anywhere **outside** the install directory: the checkout is only the source, e.g. `/root/ovpmon-src`) and run, as root. The UI comes with the clone (`deploy/ui-dist`, see above). The install directory is always asked for: pass `--prefix DIR`, or the script prompts for it (and for a confirmation); there is no default. Recommended: `/opt/OpenVPN-Monitoring-Simple`.
|
||||
|
||||
### Alpine (OpenRC)
|
||||
|
||||
```sh
|
||||
apk add git # only to clone; the script installs the rest
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Debian 12
|
||||
|
||||
```sh
|
||||
apt-get update && apt-get install -y git
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Ubuntu 24.04
|
||||
|
||||
```sh
|
||||
sudo -i
|
||||
apt-get update && apt-get install -y git # make sure the "universe" component is enabled
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--prefix DIR` | install directory, **required**: asked interactively when the option is missing (without a terminal the script stops). Absolute path of letters, digits, `. _ - /`, no trailing `/`; must be new or empty, must not be the repository checkout (or contain it, or lie inside it) and must not be a system directory (`/`, `/opt`, `/root`, `/usr`, `/var`, ...) |
|
||||
| `--ui-dist FILE\|DIR` | UI tarball from `build-ui.sh` or a directory with `index.html`; highest priority |
|
||||
| `--build-ui` | build the UI now from `APP_UI` (Docker, otherwise the host's Node 20.19+) instead of using `deploy/ui-dist` |
|
||||
| `--node-download` | with `--build-ui`: use a temporary official Node 20 (checksum verified, glibc only) |
|
||||
| `--no-ui` | install a placeholder page on purpose; without any UI source and without this option the install stops |
|
||||
| `--https-port N` | HTTPS port of the web UI (default `8088`) |
|
||||
| `--host-name NAME` | DNS name or IP for the certificate and the CORS origin (default: the detected address of the default route) |
|
||||
| `--admin-user NAME` | login of the first administrator (default `admin`) |
|
||||
| `--force` | continue on an untested OS version |
|
||||
|
||||
### Differences between the systems
|
||||
|
||||
| | Alpine 3.23 | Debian 12 / Ubuntu 24.04 |
|
||||
|---|---|---|
|
||||
| Packages | `python3 py3-pip nginx openvpn easy-rsa iptables bash doas openssl curl tar` | `python3 python3-venv python3-pip nginx openvpn easy-rsa iptables opendoas openssl curl ca-certificates tar iproute2` |
|
||||
| Service manager | OpenRC: `rc-service NAME start\|stop\|restart\|status`, `rc-update add NAME default` | systemd: `systemctl start\|stop\|restart\|status NAME`, `systemctl enable NAME` |
|
||||
| Our service files | `/etc/init.d/ovpmon-api`, `-gatherer`, `-profiler` (`supervise-daemon`, `command_user=ovpmon:ovpmon`) | `/etc/systemd/system/ovpmon-*.service` (`User=ovpmon`, `EnvironmentFile=/etc/ovpmon/env`) |
|
||||
| Service logs | `/var/log/ovpmon/ovpmon-<name>.log` | `journalctl -u ovpmon-<name>` |
|
||||
| OpenVPN service | `openvpn`; config `/etc/openvpn/server.conf`, plus the link `/etc/openvpn/openvpn.conf -> server.conf` | `openvpn-server@server`; config `/etc/openvpn/server/server.conf` |
|
||||
| nginx site | `/etc/nginx/http.d/ovpmon.conf` | `/etc/nginx/conf.d/ovpmon.conf` |
|
||||
| doas | package `doas`; our rules in `/etc/doas.d/ovpmon.conf` (own file, as on the existing hosts) | package `opendoas`; our rules as a marked block inside `/etc/doas.conf` |
|
||||
| `ovpmon` user | `adduser -S`, shell `/sbin/nologin` | `useradd --system`, shell `/usr/sbin/nologin` |
|
||||
|
||||
The nginx site does not collide with the distribution defaults: the default server of Alpine and Debian listens on port 80, ours on 8088, and both distribution `nginx.conf` files include the directory above (the installer checks the `include` line).
|
||||
|
||||
### What `install.sh` does
|
||||
|
||||
| Phase | Content |
|
||||
|---|---|
|
||||
| 0 Preflight | root, OS and version, service manager present, no existing installation (otherwise it points to `update.sh`), source checkout complete, UI source found (and built for `--build-ui`; a stale committed build only warns), ports free, free space |
|
||||
| 1 Packages | the table above; GNU tar, Python 3.9+ with `venv` and `sqlite3`, `easy-rsa` checked |
|
||||
| 2 User and directories | user `ovpmon`; `/var/lib/ovpmon` (+ `staging/`), `/var/log/ovpmon`, `/var/log/openvpn` (with `openvpn-status.log` as `root:ovpmon 640`), `/etc/openvpn/scripts`, `/etc/ovpmon` |
|
||||
| 3 Code | `APP_CORE` and `APP_PROFILER` copied to the prefix (without venvs, databases, logs, Dockerfiles), plus the scripts and templates under `deploy/` and `DOCS/General/` (so the install directory can run `update.sh --source ...`); `VERSION` |
|
||||
| 4 Virtualenvs and easy-rsa | two virtualenvs (`pip install -r requirements.txt`, plus `gunicorn` for `APP_CORE`), an import check, the easy-rsa workspace copied from `/usr/share/easy-rsa` into `APP_PROFILER/easy-rsa` (a real directory, never a symlink), code made root-owned and read-only |
|
||||
| 5 Configuration | `/etc/ovpmon/env` (random secret, generated administrator), `/etc/ovpmon/helper.conf`, `/usr/local/sbin/ovpmon-helper`, doas rules and a **self-test** (`ovpmon` runs the helper through doas), forwarding via `/etc/sysctl.d`, OpenVPN prerequisites (Alpine: the `openvpn.conf` link; Debian/Ubuntu: `/etc/openvpn/server/`; the OpenVPN service is **enabled, not started**: there is no `server.conf` yet) |
|
||||
| 6 Services, UI, nginx | the three service definitions installed and enabled, UI files to `/var/www/ovpmon` (validated, swapped in atomically, with `.ui-source-hash`), a self-signed EC certificate (`/etc/ovpmon/tls/`, SAN: host name, detected IP, `127.0.0.1`, `localhost`), the nginx site, nginx enabled and reloaded |
|
||||
| 7 Start and checks | services started; health checks (below) |
|
||||
| 8 Administrator | when a user exists in the monitoring database, the seed is removed from `/etc/ovpmon/env` and `ovpmon-api` is restarted; if the database cannot be read or is empty the seed stays and a warning says so |
|
||||
|
||||
Health checks: the three services are running; `http://127.0.0.1:5001/` answers; `http://127.0.0.1:8000/` returns 200; `https://127.0.0.1:<port>/` (with `-k`) returns 200; `/api/v1/user/me` and `/profiles-api/config` through nginx return 401 without a token.
|
||||
|
||||
The final summary shows the URL, the certificate fingerprint, the paths and the **generated administrator password once**. The state is recorded in `/etc/ovpmon/deploy.state` (prefix, HTTPS port, OS, version, dates). If the script fails it is **safe to run again**: it resumes, keeps the existing secret, certificate, easy-rsa workspace and data.
|
||||
|
||||
Then in the UI: sign in, change the password and enable 2FA, **PKI Configuration -> Initialize PKI**, generate the server configuration, start the VPN server.
|
||||
|
||||
### Without the script (outline)
|
||||
|
||||
Create the `ovpmon` user and the directories, copy the code, build both virtualenvs, write `/etc/ovpmon/env`, `helper.conf` and the doas rules from the templates, install the service definitions (`DOCS/General/systemd/*.service` or `DOCS/General/openrc/ovpmon-*`; replace `/opt/OpenVPN-Monitoring-Simple` if you use another prefix), copy the UI, add the nginx site from `deploy/native/nginx/ovpmon.conf.template` (replace `@HTTPS_PORT@`, `@WEB_ROOT@`, `@TLS_CRT@`, `@TLS_KEY@`). The commands are exactly what `install.sh` runs; reading the script is the shortest reference.
|
||||
|
||||
## Layout: what is where, who owns it
|
||||
|
||||
| Item | Path | Owner, mode |
|
||||
|---|---|---|
|
||||
| Code | `<prefix>/APP_CORE`, `<prefix>/APP_PROFILER` | `root:root`, read-only for others |
|
||||
| Virtualenvs | `<prefix>/APP_CORE/venv`, `<prefix>/APP_PROFILER/venv` | `root:root` |
|
||||
| **PKI** (CA, keys, certificates, CRL) | `<prefix>/APP_PROFILER/easy-rsa` (real directory) | `ovpmon:ovpmon` 750 |
|
||||
| **Client profiles** | `<prefix>/APP_PROFILER/client-config` (real directory) | `ovpmon:ovpmon` 750 |
|
||||
| Profiler log | `<prefix>/APP_PROFILER/profiler.log` | `ovpmon:ovpmon` 640 |
|
||||
| Shipped settings file | `<prefix>/APP_CORE/config.ini`, `<prefix>/APP_PROFILER/config.ini` | `root:root`; the environment file overrides it |
|
||||
| **Databases** | `/var/lib/ovpmon/openvpn_monitor.db`, `ovpn_profiler.db`, migration copies `*.db.bak-*` | `ovpmon:ovpmon` |
|
||||
| Staging of `server.conf` | `/var/lib/ovpmon/staging/` | `ovpmon:ovpmon` 750 |
|
||||
| Service environment | `/etc/ovpmon/env` | `root:root` 600 |
|
||||
| Helper configuration | `/etc/ovpmon/helper.conf` | `root:root` 644 |
|
||||
| TLS certificate and key | `/etc/ovpmon/tls/ovpmon.crt`, `ovpmon.key` | `root:root` (key 600) |
|
||||
| Deployment state | `/etc/ovpmon/deploy.state` | `root:root` 644 |
|
||||
| nftables ruleset of the VPN clients (only after `firewall.sh`) | `/etc/ovpmon/nftables.nft`, service `ovpmon-nft` | `root:root` 644 |
|
||||
| Root helper | `/usr/local/sbin/ovpmon-helper` | `root:root` 755 |
|
||||
| doas rules | Alpine: `/etc/doas.d/ovpmon.conf`; Debian/Ubuntu: block in `/etc/doas.conf` | `root:root` |
|
||||
| OpenVPN configuration | `/etc/openvpn/server.conf` (Alpine) or `/etc/openvpn/server/server.conf`, `/etc/openvpn/crl.pem`, `/etc/openvpn/scripts/` | `root:root` |
|
||||
| OpenVPN logs | `/var/log/openvpn/openvpn.log`, `openvpn-status.log` (`root:ovpmon` 640) | `root` |
|
||||
| Service logs | `/var/log/ovpmon/` (OpenRC) or the journal (systemd) | `ovpmon` / systemd |
|
||||
| UI files | `/var/www/ovpmon` | `root:root` |
|
||||
| Backups | `/var/backups/ovpmon/<UTC timestamp>/` | `root:root` 700 |
|
||||
| Deployment log | `/var/log/ovpmon-deploy.log` | `root:root` 600 |
|
||||
|
||||
The profiler resolves `easy-rsa/` and `client-config/` relative to its working directory (`APP_PROFILER`) and keeps `client-config/<name>.ovpn` as a relative path in its database; therefore both are real directories inside `APP_PROFILER` (a symlinked `client-config` breaks the real-path checks and the `clear_pki` cleanup).
|
||||
|
||||
## Environment file and helper configuration
|
||||
|
||||
`/etc/ovpmon/env` (`root:root` 600) is read by the init system as root and handed to the services. Lines are `KEY=VALUE` without quotes or spaces (systemd and OpenRC read the same file).
|
||||
|
||||
| Variable | Default written by `install.sh` | Meaning |
|
||||
|---|---|---|
|
||||
| `OVPMON_API_SECRET_KEY` | random, 64 hex characters | signing key of both APIs; changing it logs everybody out; keep it across updates |
|
||||
| `OVPMON_API_HOST`, `OVPMON_API_PORT` | `127.0.0.1`, `5001` | informational: gunicorn is started with `-b 127.0.0.1:5001` |
|
||||
| `OVPMON_OPENVPN_MONITOR_DB_PATH` | `/var/lib/ovpmon/openvpn_monitor.db` | monitoring database |
|
||||
| `OVPMON_PROFILER_DB_PATH` | `/var/lib/ovpmon/ovpn_profiler.db` | profiler database |
|
||||
| `OVPMON_OPENVPN_MONITOR_LOG_PATH` | `/var/log/openvpn/openvpn-status.log` | status log read by the gatherer |
|
||||
| `OVPMON_LOGGING_LEVEL` | `INFO` | |
|
||||
| `OVPMON_CORS_ORIGINS` | `https://<host>:<https-port>` | extra allowed origin (the UI is same-origin behind nginx) |
|
||||
| `OVPMON_RUNTIME` | `host` | forces host mode (never "container"), needed when the host itself runs inside a container |
|
||||
| `OVPMON_OPENVPN_SERVICE` | `openvpn` (Alpine) / `openvpn-server@server` | service name for the root (non-helper) path |
|
||||
| `OVPMON_OPENVPN_CONFIG` | `/etc/openvpn/server.conf` / `/etc/openvpn/server/server.conf` | server config path for the root (non-helper) path |
|
||||
| `OVPMON_INITIAL_ADMIN_USER`, `OVPMON_INITIAL_ADMIN_PASSWORD` | generated | seed, only while the users table is empty; removed by `install.sh` after the first start |
|
||||
| `OVPMON_AUTO_MIGRATE` | unset | `0` makes the services refuse to start while migrations are pending |
|
||||
|
||||
With the unprivileged profiler the API only stages `server.conf`; **the helper configuration decides where it is installed and which service is controlled.**
|
||||
|
||||
`/etc/ovpmon/helper.conf` (INI, section `[helper]`, `root:root`, not group/world writable, otherwise the helper refuses to run). Without the file the helper uses the built-in values of the Alpine layout.
|
||||
|
||||
| Key | Alpine (written) | Debian/Ubuntu (written) | Rule |
|
||||
|---|---|---|---|
|
||||
| `install_dir` | `/opt/OpenVPN-Monitoring-Simple` | same | absolute, no `..`; the PKI is `<install_dir>/APP_PROFILER/easy-rsa/pki` |
|
||||
| `service_manager` | `openrc` | `systemd` | `openrc` or `systemd` |
|
||||
| `service_unit` | `openvpn` | `openvpn-server@server` | `^[A-Za-z0-9@._-]{1,64}$`, not starting with `-` or `.` |
|
||||
| `config_path` | `/etc/openvpn/server.conf` | `/etc/openvpn/server/server.conf` | absolute, below `/etc/openvpn/`, ends with `.conf` |
|
||||
| `staged_path` | `/var/lib/ovpmon/staging/server.conf` | same | absolute, below `/var/lib/ovpmon/` |
|
||||
|
||||
OpenRC runs `/sbin/rc-service <unit> <action>`, systemd runs `systemctl <action> <unit>` (fixed argument list, fixed `PATH`). Unknown keys or invalid values make the helper refuse.
|
||||
|
||||
## Firewall, NAT and forwarding
|
||||
|
||||
`install.sh` and `update.sh` **never touch the firewall**. `net.ipv4.ip_forward=1` is set persistently in `/etc/sysctl.d/98-ovpmon-forward.conf`. Opening the ports (UI, VPN) is yours. NAT and packet tuning for the VPN clients are done by a separate opt-in script.
|
||||
|
||||
### `deploy/native/firewall.sh` (nftables)
|
||||
|
||||
Reads the interfaces of this server and applies, for traffic **from the VPN network to every other network**: masquerade, TCP MSS clamping (path MTU tuning) and TTL tuning. Run it as root after the VPN server configuration exists (the VPN network is read from the `server` line of `server.conf`).
|
||||
|
||||
```sh
|
||||
deploy/native/firewall.sh --dry-run # show what was detected and the ruleset; change nothing
|
||||
deploy/native/firewall.sh # apply, ask for confirmation, load at boot
|
||||
deploy/native/firewall.sh status # loaded rules with counters, boot service, detected parameters
|
||||
deploy/native/firewall.sh remove # delete the rules, the ruleset file and the boot service
|
||||
```
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--vpn-net CIDR` | VPN network. Default: `server` line of the OpenVPN config, else the address of the VPN interface |
|
||||
| `--vpn-if NAME` | VPN interface. Default: the interface with an address in the VPN network, else the `dev` line, else `tun*` |
|
||||
| `--out-if A,B` | Only these interfaces (exact names) are "other networks". Default: every interface except `lo` and the VPN interface, so new uplinks (VLAN, `hytun`, a second ISP) need no rerun |
|
||||
| `--ttl N` / `--no-ttl` | TTL of packets leaving towards the other networks (default 64, set after the forwarding decrement) |
|
||||
| `--mss pmtu\|N` / `--no-mss` | TCP MSS of SYN and SYN-ACK in both directions: `pmtu` = MTU of the route of each connection (default), or a fixed value |
|
||||
| `--no-persist` | Running kernel only: no ruleset file, no boot service |
|
||||
| `--yes`, `--force` | No questions; continue on an untested OS version |
|
||||
|
||||
What it creates: only the table `ip ovpmon` (replaced atomically with `nft -f`; other tables and the distribution's `nftables.service` are not touched), the ruleset file `/etc/ovpmon/nftables.nft` and the boot service `ovpmon-nft` (systemd oneshot / OpenRC). The `nftables` package is installed on request only (it is not part of the install packages). IPv4 only.
|
||||
|
||||
Notes:
|
||||
- "Every other network" includes container bridges and tunnels on the host; use `--out-if` to limit it.
|
||||
- The VPN network must not overlap with the network of another interface (the script stops).
|
||||
- The options are not remembered: after a change of the VPN subnet in the UI run the script again with the same options.
|
||||
- The MSS clamp complements `tun-mtu` / `mssfix` of the server settings, it does not replace them. If another nftables table has a `policy drop`, allow the VPN traffic and ICMP "fragmentation needed" (type 3, code 4) there, otherwise path MTU discovery fails.
|
||||
- Old manual rules (`iptables -t nat ... MASQUERADE` for the same network) are reported: remove them when this script is the one to keep.
|
||||
- The filtering policy (INPUT/FORWARD allow/drop, ports, anti-leak) is not part of the script.
|
||||
|
||||
### Manual rules (iptables / nftables)
|
||||
|
||||
Replace `eth0` with the uplink interface and `172.20.1.0/24` with the VPN subnet of the server settings.
|
||||
|
||||
```sh
|
||||
# iptables: services
|
||||
iptables -A INPUT -p tcp --dport 8088 -j ACCEPT # UI (your HTTPS port)
|
||||
iptables -A INPUT -p udp --dport 1194 -j ACCEPT # OpenVPN (your VPN port)
|
||||
# iptables: NAT and forwarding for the VPN clients
|
||||
iptables -t nat -A POSTROUTING -s 172.20.1.0/24 -o eth0 -j MASQUERADE
|
||||
iptables -A FORWARD -i tun+ -o eth0 -j ACCEPT
|
||||
iptables -A FORWARD -i eth0 -o tun+ -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
```
|
||||
|
||||
nftables equivalent:
|
||||
|
||||
```sh
|
||||
nft add table inet ovpmon
|
||||
nft 'add chain inet ovpmon input { type filter hook input priority 0 ; }'
|
||||
nft add rule inet ovpmon input tcp dport 8088 accept
|
||||
nft add rule inet ovpmon input udp dport 1194 accept
|
||||
nft 'add chain inet ovpmon forward { type filter hook forward priority 0 ; }'
|
||||
nft add rule inet ovpmon forward iifname "tun*" oifname "eth0" accept
|
||||
nft add rule inet ovpmon forward iifname "eth0" oifname "tun*" ct state established,related accept
|
||||
nft 'add table ip ovpmon_nat'
|
||||
nft 'add chain ip ovpmon_nat postrouting { type nat hook postrouting priority 100 ; }'
|
||||
nft add rule ip ovpmon_nat postrouting ip saddr 172.20.1.0/24 oifname "eth0" masquerade
|
||||
```
|
||||
|
||||
(Add the `input`/`forward` rules only when your firewall policy is `drop`; a chain with priority 0 and policy accept does not block anything on its own.)
|
||||
|
||||
Persistence:
|
||||
|
||||
| System | Make the rules survive a reboot |
|
||||
|---|---|
|
||||
| Alpine | `rc-service iptables save && rc-update add iptables` (rules in `/etc/iptables/rules-save`); nftables: `rc-update add nftables`, rules in `/etc/nftables.nft` |
|
||||
| Debian / Ubuntu | `apt-get install iptables-persistent`, then `netfilter-persistent save`; nftables: put the rules in `/etc/nftables.conf` and `systemctl enable nftables` |
|
||||
|
||||
## Update
|
||||
|
||||
```sh
|
||||
deploy/native/update.sh # run from the checkout with the new version
|
||||
deploy/native/update.sh --ui-dist /root/ui-dist.tar.gz # install this UI (tarball or directory), always
|
||||
deploy/native/update.sh --build-ui # build the UI from APP_UI on this host and install it
|
||||
deploy/native/update.sh --source /root/ovpmon-src --yes # another checkout, no questions
|
||||
deploy/native/update.sh --no-pull # sources already in place / offline
|
||||
deploy/native/update.sh --rollback # manual rollback to the newest backup
|
||||
```
|
||||
|
||||
Run it from the checkout that holds the new version (the script uses the templates of that checkout). `--prefix` and the HTTPS port come from `/etc/ovpmon/deploy.state`. The update needs access to PyPI for the new virtualenvs.
|
||||
|
||||
Each phase is logged separately:
|
||||
|
||||
| Phase | What happens | If it fails |
|
||||
|---|---|---|
|
||||
| 0 Preflight | installation present, no unfinished install, source checkout complete, an explicit UI source readable (`--build-ui`: builder usable), services state, databases found, free space (backup and new code) | nothing was changed |
|
||||
| 1 **Backup** | verified backup in `/var/backups/ovpmon/<UTC timestamp>/` (see below) | the update is **refused**, nothing was changed |
|
||||
| 2 Sources | `git pull --ff-only` of the source checkout (skipped with `--no-pull` or without git) | nothing was changed |
|
||||
| 3 Prepare | new code copied to `<prefix>.new`, fresh virtualenvs with `pip install -r requirements.txt`, import check; the UI source is decided (after `git pull`: `--ui-dist`, `--build-ui`, the committed build; unchanged hash means no swap) and the new UI is staged next to the web root. **The running system is not touched** | nothing was changed |
|
||||
| 4 Stop and swap | the three application services are stopped (**OpenVPN keeps running**, VPN users stay connected); a final consistent snapshot; each code directory is renamed to `<dir>.old-<time>`, the new one moved in; **PKI, client profiles, `profiler.log`, `config.ini` and any database files below the code directory are moved over, never replaced**; virtualenv paths fixed | automatic rollback |
|
||||
| 5 **Database migration** | its own step, see below | automatic rollback, **nothing is started** |
|
||||
| 6 Files | UI swap (when a new UI was staged); helper; `helper.conf` (when missing); doas rules; service definitions; missing environment keys added (existing values never changed); nginx site; each replaced only when it differs and is managed by these scripts; units reloaded | automatic rollback |
|
||||
| 7 Start | services started, health checks, helper self-test | automatic rollback |
|
||||
| 8 Finish | the old code directories are removed (never one that still holds PKI data), the newest 5 backups kept, state recorded | |
|
||||
|
||||
The new `deploy/native/*.sh` take effect on the next run (the running script is not replaced).
|
||||
|
||||
### Database migration as its own step
|
||||
|
||||
After the services are stopped and the new code is in place, and **before anything is started**, `update.sh` runs for each database, with the **new** code, as user `ovpmon` and with the variables of `/etc/ovpmon/env` loaded:
|
||||
|
||||
| Database | Command (working directory) |
|
||||
|---|---|
|
||||
| Profiler | `APP_PROFILER/venv/bin/python migrate.py` in `<prefix>/APP_PROFILER` |
|
||||
| Monitoring | `APP_CORE/venv/bin/python migrate.py` in `<prefix>/APP_CORE` |
|
||||
|
||||
For each one: `migrate.py --check` (exit 0 up to date, 2 pending, 1 error or database newer than the code), the migration when 2, and a second check. The reports are printed. A failure or a "too new" database aborts **before any service starts** and triggers the rollback. Migrations are additive, run after an integrity check and a consistent copy `<db>.bak-<UTC timestamp>` next to the database, and are verified afterwards; details in [Database migrations](../General/Database_Migrations.md). The migration also runs by itself when a service starts, so a manual file replacement is safe too; `update.sh` only makes it a visible, controlled step.
|
||||
|
||||
### Backup (phase 1, `backup.sh`)
|
||||
|
||||
```sh
|
||||
deploy/native/backup.sh # backup into /var/backups/ovpmon/<UTC timestamp>/
|
||||
deploy/native/backup.sh --stop # services stopped during the copy, started afterwards
|
||||
deploy/native/backup.sh --keep 14 # afterwards keep the newest 14
|
||||
```
|
||||
|
||||
Cron example (nightly, 14 kept): `30 3 * * * /opt/OpenVPN-Monitoring-Simple/deploy/native/backup.sh --keep 14 >> /var/log/ovpmon-backup.log 2>&1`.
|
||||
|
||||
| Content | File in the backup |
|
||||
|---|---|
|
||||
| both databases, consistent copies from the SQLite backup API (integrity-checked, owner and mode kept) | `db/monitor.db`, `db/profiler.db` |
|
||||
| `/etc/ovpmon` (environment, helper configuration, certificate, state) | `etc-ovpmon.tar.gz` |
|
||||
| `/etc/openvpn` (`server.conf`, `crl.pem`, scripts, `ipp.txt`) | `etc-openvpn.tar.gz` |
|
||||
| PKI `APP_PROFILER/easy-rsa` | `easy-rsa.tar.gz` |
|
||||
| client profiles `APP_PROFILER/client-config` | `client-config.tar.gz` |
|
||||
| `APP_CORE` and `APP_PROFILER` including the virtualenvs (needed for rollback) | `code.tar.gz` |
|
||||
| helper, service definitions, nginx site, sysctl file, doas file (Alpine) | `system.tar.gz` |
|
||||
| doas block (Debian/Ubuntu) | `doas-block.txt` |
|
||||
| UI files | `ui.tar.gz` |
|
||||
| checksums, description, completion marker | `SHA256SUMS`, `MANIFEST`, `COMPLETE` |
|
||||
|
||||
Every archive is verified (`tar -tzf`), the checksums are checked and each database copy passes `PRAGMA integrity_check` before `COMPLETE` is written; **only a `COMPLETE` backup is ever used**. `update.sh` backs up twice: in phase 1, and again as a final snapshot once the services are stopped (the code archive is reused). The backup holds private keys, password hashes and the signing secret: the directory is mode 700, the files mode 600. Keep copies off the host.
|
||||
|
||||
### Restore
|
||||
|
||||
```sh
|
||||
deploy/native/restore.sh /var/backups/ovpmon/20261005T101500Z # asks, stops, saves the current state, restores
|
||||
deploy/native/restore.sh /var/backups/ovpmon/20261005T101500Z --yes --start
|
||||
```
|
||||
|
||||
It verifies the backup, stops the three application services, saves the **current state** to `/var/backups/ovpmon/<time>-pre-restore` (`OVPMON_NO_SAFETY_BACKUP=1` skips this), then restores code, databases, `/etc/ovpmon`, `/etc/openvpn`, PKI, client profiles, helper, service definitions, nginx site, UI and doas rules. A replaced database is kept as `<db>.failed-<time>`. OpenVPN is not stopped. On a new host run `install.sh` first, then `restore.sh`.
|
||||
|
||||
Manual equivalent (services stopped, paths for the default prefix):
|
||||
|
||||
```sh
|
||||
B=/var/backups/ovpmon/20261005T101500Z
|
||||
( cd $B && sha256sum -c SHA256SUMS )
|
||||
tar -xzpf $B/code.tar.gz -C /opt/OpenVPN-Monitoring-Simple # after moving the current APP_CORE and APP_PROFILER aside
|
||||
tar -xzpf $B/easy-rsa.tar.gz -C /opt/OpenVPN-Monitoring-Simple/APP_PROFILER
|
||||
tar -xzpf $B/client-config.tar.gz -C /opt/OpenVPN-Monitoring-Simple/APP_PROFILER
|
||||
cp -p $B/db/profiler.db /var/lib/ovpmon/ovpn_profiler.db # the backup was made with the sqlite backup API
|
||||
cp -p $B/db/monitor.db /var/lib/ovpmon/openvpn_monitor.db
|
||||
tar -xzpf $B/etc-ovpmon.tar.gz -C / && tar -xzpf $B/etc-openvpn.tar.gz -C /
|
||||
tar -xzpf $B/system.tar.gz -C / # helper, service definitions, nginx site
|
||||
```
|
||||
|
||||
A single database can also be put back from its migration copy `<db>.bak-<time>` in `/var/lib/ovpmon`: stop the services, copy it over the database, start the OLD release.
|
||||
|
||||
### Automatic rollback and `--rollback`
|
||||
|
||||
On any failure from phase 4 on: the services are stopped, **code, databases, `/etc/ovpmon`, `/etc/openvpn`, helper, doas rules, service definitions, nginx site and UI files are restored from the backup of this run**, the services are started and checked, and the result is reported with the backup path.
|
||||
|
||||
How the code is restored: the current (new or half-swapped) code directories are renamed to `<dir>.rollback-<time>`, `code.tar.gz` is extracted (old code **and old virtualenvs**, so no Internet is needed), and the PKI and client profiles, which the update never replaced, are moved back from the directory that held them. They are restored from `easy-rsa.tar.gz` / `client-config.tar.gz` only if they are missing. The failed databases are kept as `<db>.failed-<time>`. If the rollback itself fails the message says where the backup is and how to retry (`update.sh --rollback` or `restore.sh`).
|
||||
|
||||
`update.sh --rollback` does the same by hand from the newest `COMPLETE` backup after a confirmation, with one difference: PKI and client profiles come from the backup too (one consistent set with the databases), and the current state is saved first to `<time>-pre-restore`. Use it when an update succeeded but the new version misbehaves. Data created after that backup is lost (it is in the `-pre-restore` copy).
|
||||
|
||||
## Existing installations (adoption)
|
||||
|
||||
A host that was set up by hand (the layout of the old guide: code in `/opt/OpenVPN-Monitoring-Simple`, `/etc/ovpmon/env`, init scripts or units, helper and doas rules) can be updated with `update.sh`: it has no state file, so it is adopted and recorded after the first successful update. Files that these scripts do not manage are **left as they are**: init scripts, units, an nginx site and a doas file that do not carry the marker line `managed by ovpmon deploy/native` and differ from the shipped ones are only reported. The helper is replaced (the new one behaves like the old one without `helper.conf`), `helper.conf` is written when missing, and `OVPMON_RUNTIME`, `OVPMON_OPENVPN_SERVICE` and `OVPMON_OPENVPN_CONFIG` are added to the environment file only when absent. If the install directory is a git checkout (the source is the install directory), `git pull` changes the live files, therefore a rollback is armed from phase 2.
|
||||
|
||||
## What is preserved on update
|
||||
|
||||
| Item | On update |
|
||||
|---|---|
|
||||
| Databases | Kept in place, backed up twice (consistent copies), migrated additively with their own `<db>.bak-*` copy; restored automatically if the update fails after the stop |
|
||||
| PKI (`APP_PROFILER/easy-rsa`): CA, keys, certificates, CRL | Moved, never replaced or deleted, backed up |
|
||||
| Client profiles (`APP_PROFILER/client-config`) | Moved, never replaced or deleted, backed up |
|
||||
| `/etc/ovpmon/env` (secret, DB paths) | Kept; only missing keys are added; copied into every backup |
|
||||
| `/etc/ovpmon/helper.conf`, TLS certificate and key | Kept (helper.conf is rewritten only while it carries our marker and differs) |
|
||||
| `/etc/openvpn` (`server.conf`, `crl.pem`, scripts, `ipp.txt`) | Not touched by the update; backed up |
|
||||
| OpenVPN process and VPN sessions | Not stopped or restarted; connected users stay connected |
|
||||
| `config.ini` of both components | Kept; the shipped one of the new version is saved as `config.ini.dist` when it differs |
|
||||
| `profiler.log`, other `*.log` / `*.db` files below the code directories | Kept (moved) |
|
||||
| Code, virtualenvs | **Replaced** (fresh virtualenvs; the old ones are in the backup) |
|
||||
| UI files | Replaced with `--ui-dist` / `--build-ui`, or automatically when the committed build of the source differs from the installed one (`.ui-source-hash`); kept when there is no UI source; the previous ones are in the backup |
|
||||
| Service definitions, nginx site, doas rules, helper | Replaced when they differ and are managed by these scripts; the previous ones are in the backup |
|
||||
| User sessions | Stay valid while the secret is unchanged |
|
||||
| Backups in `/var/backups/ovpmon` | The newest 5 kept, older ones pruned after a successful update; `-pre-restore` copies are never pruned automatically |
|
||||
| Data directories (`/var/lib/ovpmon`, PKI, client profiles) | **Never deleted** by any script |
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Cause and action |
|
||||
|---|---|
|
||||
| `invalid --prefix ...` / `no valid install directory given` | The install directory must be a new or empty dedicated directory, not the repository checkout and not a system directory. Move or clone the repository elsewhere (for example `/root/ovpmon-src`) or choose another directory |
|
||||
| `already installed ... use update.sh` / `an installation already exists` | `install.sh` never installs over an installation. Use `update.sh` (it adopts hand-made installations) |
|
||||
| `installation stopped in phase ...` | Fix the cause and run `install.sh` again: it resumes and keeps secrets, certificate and data |
|
||||
| `not a tested version ... needs --force` | Untested OS version: `install.sh --force` at your own risk |
|
||||
| `ports ... already in use` | Another service uses 5001, 8000 or the HTTPS port: stop it or use `--https-port` |
|
||||
| `pip install failed` | No access to the Python package index (proxy: `pip` honours `HTTPS_PROXY`); on Alpine check that `py3-pip` is installed |
|
||||
| Health check fails | Alpine: `tail /var/log/ovpmon/ovpmon-api.log` (or `-gatherer`, `-profiler`); systemd: `journalctl -u ovpmon-api -n 50`. The scripts print the last lines of a failing service |
|
||||
| `FATAL: ... newer than this version` / migration "too new" | The database was migrated by a newer release. Do not start the old version on it: update to the newer sources or restore a matching backup |
|
||||
| Migration failed | Nothing was started and the rollback restored the databases; the report names the migration, the `<db>.bak-*` copy is in `/var/lib/ovpmon`. Keep the report |
|
||||
| Profiler cannot start/stop OpenVPN, "helper failed" | The self-test warning of the scripts points at it: check the doas rules (`doas -C /etc/doas.conf` or `/etc/doas.d/ovpmon.conf`), `/etc/ovpmon/helper.conf` (must be `root:root` and not group/world writable; `su -s /bin/sh ovpmon -c "doas -n /usr/local/sbin/ovpmon-helper service status"` prints the reason) |
|
||||
| `Configuration rejected` when generating the server config | The helper allowlist refused a directive, see [Privilege separation](../Changes/2026-09-30_Privilege_Separation.md) |
|
||||
| OpenVPN does not start on Debian/Ubuntu | `systemctl status openvpn-server@server`, `journalctl -u openvpn-server@server`; the config must be `/etc/openvpn/server/server.conf` and `/dev/net/tun` must exist |
|
||||
| Clients connect but have no internet | Forwarding or NAT is missing: see the firewall section |
|
||||
| nginx: `conflicting server name` / port in use | Another site uses the same port; change `--https-port` (or the `listen` line of the site and reload) |
|
||||
| Browser warns about the certificate | It is self-signed; check the fingerprint printed by `install.sh`, or install a real certificate under `/etc/ovpmon/tls/` and reload nginx |
|
||||
| `no UI source found` (install stops) | The checkout has no `deploy/ui-dist` (incomplete clone, or the maintainer did not publish it) and no `--ui-dist`. Use `--build-ui` (Docker or Node 20.19+; `--node-download` on Debian/Ubuntu), `--ui-dist FILE\|DIR` from another machine, or `--no-ui` for a placeholder page |
|
||||
| Warning "committed UI build ... is OLDER than the APP_UI sources" | Someone changed `APP_UI` without refreshing the build. Maintainers: `deploy/native/build-ui.sh --publish` and commit `deploy/ui-dist`. On the host: `--build-ui` |
|
||||
| `the installed Node is too old` / `node and npm are not installed` (`--build-ui`, `build-ui.sh --local`) | The message lists the commands for the OS: Alpine `apk add nodejs npm`; Debian/Ubuntu `--node-download` or Node 20+ from nodejs.org |
|
||||
| UI shows the placeholder page | Installed with `--no-ui`: run `deploy/native/update.sh` (installs the UI of the repository), or add `--ui-dist` / `--build-ui` |
|
||||
| `su`/`doas` self-test fails on a minimal container | Containers often lack `/etc/pam.d/doas` or a real init system; the services may still work (check health) |
|
||||
|
||||
## Host hardening (recommended, not done by the scripts)
|
||||
|
||||
- SSH: key-only (`PasswordAuthentication no`, `KbdInteractiveAuthentication no`, `PermitRootLogin prohibit-password`). Cloud-init drop-ins in `/etc/ssh/sshd_config.d/` can override the main file, so put your settings in a file that sorts first, for example `00-hardening.conf`.
|
||||
- fail2ban: jails `sshd` and one for `POST /api/auth/login` (HTTP 401/429/503) on the nginx access log.
|
||||
- Backends are bound to `127.0.0.1`; only the HTTPS port and the VPN port should be reachable from outside.
|
||||
- Keep the system updated (`apk upgrade` / `apt-get upgrade`) and watch the advisories of OpenVPN, nginx and OpenSSH.
|
||||
|
||||
## Verify an installation
|
||||
|
||||
```sh
|
||||
rc-status | grep -E "ovpmon|nginx|openvpn" # Alpine; Debian/Ubuntu: systemctl status 'ovpmon-*' nginx
|
||||
ss -tlnp | grep -E ":(8088|5001|8000) "
|
||||
curl -sk -o /dev/null -w "%{http_code}\n" https://127.0.0.1:8088/ # 200
|
||||
curl -sk -o /dev/null -w "%{http_code}\n" https://127.0.0.1:8088/profiles-api/config # 401 without a token
|
||||
su -s /bin/sh ovpmon -c "doas -n /usr/local/sbin/ovpmon-helper service status" # JSON, not "Operation not permitted"
|
||||
```
|
||||
|
||||
## Security notes
|
||||
|
||||
- Services run as `ovpmon` (no login shell); code and virtualenvs are root-owned and read-only for them. systemd units add `PrivateTmp`, `ProtectHome`, `ProtectSystem=full`, kernel and cgroup protection; `ovpmon-api` and `ovpmon-gatherer` also set `NoNewPrivileges`. `ovpmon-profiler` must **not** (it calls the setuid `doas`), must not use seccomp-based options either (`ProtectKernelTunables`, `ProtectKernelModules`, `RestrictRealtime`, `LockPersonality`, `SystemCallFilter`, ...): for an unprivileged unit systemd then sets NoNewPrivileges implicitly and `doas` fails with "not installed setuid" (check: `grep NoNewPrivs /proc/<main pid>/status` must show 0). It keeps `/etc/openvpn` writable, because the helper runs inside the profiler's mount namespace.
|
||||
- The helper accepts six fixed commands, validates `server.conf` against an allowlist and reads its own root-owned configuration; nothing else runs as root. `ovpmon` owns the PKI including the CA key: a compromised profiler can issue client certificates (VPN access) but cannot become root.
|
||||
- `/etc/ovpmon/env` is `root:root` 600 and never printed; the generated administrator password is shown once and removed from the file after the first start.
|
||||
- Backups contain private keys, password hashes and the secret: mode 700/600, keep off-host copies encrypted.
|
||||
- Both APIs listen on `127.0.0.1`; only nginx (HTTPS) and OpenVPN are reachable. Replace the self-signed certificate when a domain is available; consider restricting the UI by address or reaching it through the VPN.
|
||||
- The scripts do not harden SSH or install fail2ban: see the next section.
|
||||
|
||||
Related: [Database migrations](../General/Database_Migrations.md), [Privilege separation](../Changes/2026-09-30_Privilege_Separation.md), [Scenario 1: containers](Scenario1_Containers.md), [Deployment plan](../Changes/2026-10-05_Deployment_Scenarios_PLAN.md).
|
||||
@@ -0,0 +1,74 @@
|
||||
# System services: firewall, NAT and forwarding
|
||||
|
||||
Install: [System services](README.md).
|
||||
|
||||
`install.sh` and `update.sh` **never touch the firewall**. `net.ipv4.ip_forward=1` is set persistently in `/etc/sysctl.d/98-ovpmon-forward.conf`. Opening the ports (UI, VPN) is yours. NAT and packet tuning for the VPN clients are done by a separate opt-in script.
|
||||
|
||||
## `deploy/native/firewall.sh` (nftables)
|
||||
|
||||
Reads the interfaces of this server and applies, for traffic **from the VPN network to every other network**: masquerade, TCP MSS clamping (path MTU tuning) and TTL tuning. Run it as root after the VPN server configuration exists (the VPN network is read from the `server` line of `server.conf`).
|
||||
|
||||
```sh
|
||||
deploy/native/firewall.sh --dry-run # show what was detected and the ruleset; change nothing
|
||||
deploy/native/firewall.sh # apply, ask for confirmation, load at boot
|
||||
deploy/native/firewall.sh status # loaded rules with counters, boot service, detected parameters
|
||||
deploy/native/firewall.sh remove # delete the rules, the ruleset file and the boot service
|
||||
```
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--vpn-net CIDR` | VPN network. Default: `server` line of the OpenVPN config, else the address of the VPN interface |
|
||||
| `--vpn-if NAME` | VPN interface. Default: the interface with an address in the VPN network, else the `dev` line, else `tun*` |
|
||||
| `--out-if A,B` | Only these interfaces (exact names) are "other networks". Default: every interface except `lo` and the VPN interface, so new uplinks (VLAN, `hytun`, a second ISP) need no rerun |
|
||||
| `--ttl N` / `--no-ttl` | TTL of packets leaving towards the other networks (default 64, set after the forwarding decrement) |
|
||||
| `--mss pmtu\|N` / `--no-mss` | TCP MSS of SYN and SYN-ACK in both directions: `pmtu` = MTU of the route of each connection (default), or a fixed value |
|
||||
| `--no-persist` | Running kernel only: no ruleset file, no boot service |
|
||||
| `--yes`, `--force` | No questions; continue on an untested OS version |
|
||||
|
||||
What it creates: only the table `ip ovpmon` (replaced atomically with `nft -f`; other tables and the distribution's `nftables.service` are not touched), the ruleset file `/etc/ovpmon/nftables.nft` and the boot service `ovpmon-nft` (systemd oneshot / OpenRC). The `nftables` package is installed on request only (it is not part of the install packages). IPv4 only.
|
||||
|
||||
Notes:
|
||||
- "Every other network" includes container bridges and tunnels on the host; use `--out-if` to limit it.
|
||||
- The VPN network must not overlap with the network of another interface (the script stops).
|
||||
- The options are not remembered: after a change of the VPN subnet in the UI run the script again with the same options.
|
||||
- The MSS clamp complements `tun-mtu` / `mssfix` of the server settings, it does not replace them. If another nftables table has a `policy drop`, allow the VPN traffic and ICMP "fragmentation needed" (type 3, code 4) there, otherwise path MTU discovery fails.
|
||||
- Old manual rules (`iptables -t nat ... MASQUERADE` for the same network) are reported: remove them when this script is the one to keep.
|
||||
- The filtering policy (INPUT/FORWARD allow/drop, ports, anti-leak) is not part of the script.
|
||||
|
||||
## Manual rules (iptables / nftables)
|
||||
|
||||
Replace `eth0` with the uplink interface and `172.20.1.0/24` with the VPN subnet of the server settings.
|
||||
|
||||
```sh
|
||||
# iptables: services
|
||||
iptables -A INPUT -p tcp --dport 8088 -j ACCEPT # UI (your HTTPS port)
|
||||
iptables -A INPUT -p udp --dport 1194 -j ACCEPT # OpenVPN (your VPN port)
|
||||
# iptables: NAT and forwarding for the VPN clients
|
||||
iptables -t nat -A POSTROUTING -s 172.20.1.0/24 -o eth0 -j MASQUERADE
|
||||
iptables -A FORWARD -i tun+ -o eth0 -j ACCEPT
|
||||
iptables -A FORWARD -i eth0 -o tun+ -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
```
|
||||
|
||||
nftables equivalent:
|
||||
|
||||
```sh
|
||||
nft add table inet ovpmon
|
||||
nft 'add chain inet ovpmon input { type filter hook input priority 0 ; }'
|
||||
nft add rule inet ovpmon input tcp dport 8088 accept
|
||||
nft add rule inet ovpmon input udp dport 1194 accept
|
||||
nft 'add chain inet ovpmon forward { type filter hook forward priority 0 ; }'
|
||||
nft add rule inet ovpmon forward iifname "tun*" oifname "eth0" accept
|
||||
nft add rule inet ovpmon forward iifname "eth0" oifname "tun*" ct state established,related accept
|
||||
nft 'add table ip ovpmon_nat'
|
||||
nft 'add chain ip ovpmon_nat postrouting { type nat hook postrouting priority 100 ; }'
|
||||
nft add rule ip ovpmon_nat postrouting ip saddr 172.20.1.0/24 oifname "eth0" masquerade
|
||||
```
|
||||
|
||||
(Add the `input`/`forward` rules only when your firewall policy is `drop`; a chain with priority 0 and policy accept does not block anything on its own.)
|
||||
|
||||
Persistence:
|
||||
|
||||
| System | Make the rules survive a reboot |
|
||||
|---|---|
|
||||
| Alpine | `rc-service iptables save && rc-update add iptables` (rules in `/etc/iptables/rules-save`); nftables: `rc-update add nftables`, rules in `/etc/nftables.nft` |
|
||||
| Debian / Ubuntu | `apt-get install iptables-persistent`, then `netfilter-persistent save`; nftables: put the rules in `/etc/nftables.conf` and `systemctl enable nftables` |
|
||||
@@ -0,0 +1,124 @@
|
||||
# Nginx Configuration Guide
|
||||
|
||||
This guide details how to configure Nginx as a reverse proxy for the OpenVPN Monitor & Profiler application. Nginx is **required** in production to serve the frontend and route API requests to the appropriate backend services.
|
||||
|
||||
## Architecture Recap
|
||||
|
||||
- **Frontend (`APP_UI`)**: Static files (HTML, JS, CSS) served from `/var/www/ovpmon` (or similar).
|
||||
- **Core API (`APP_CORE`)**: Python/Flask service running on **127.0.0.1:5001**.
|
||||
- **Profiler API (`APP_PROFILER`)**: Python/FastAPI service running on **127.0.0.1:8000**.
|
||||
|
||||
## 1. Alpine Linux Setup
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
apk add nginx
|
||||
rc-update add nginx default
|
||||
```
|
||||
|
||||
### Configuration
|
||||
Create a new configuration file (e.g., `/etc/nginx/http.d/ovpmon.conf`).
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name your-server-domain.com; # Replace with your IP or Domain
|
||||
|
||||
root /var/www/ovpmon;
|
||||
index index.html;
|
||||
|
||||
# Gzip Compression
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
# 1. Frontend (SPA Routing)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 2. Core Monitoring API (Flask :5001)
|
||||
# Routes: /api/v1/stats, /api/auth, etc.
|
||||
location /api/v1/ {
|
||||
proxy_pass http://127.0.0.1:5001/api/v1/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
location /api/auth/ {
|
||||
proxy_pass http://127.0.0.1:5001/api/auth/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
# 3. Profiler Management API (FastAPI :8000)
|
||||
# Routes: /api/profiles, /api/config, etc.
|
||||
# Note: We capture /api/ but exclude /api/v1 (handled above)
|
||||
location /api/ {
|
||||
# Ensure this doesn't conflict with /api/v1. Nginx matching order:
|
||||
# Longest prefix matches first. So /api/v1/ wins over /api/.
|
||||
proxy_pass http://127.0.0.1:8000/api/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Apply Changes
|
||||
```bash
|
||||
rc-service nginx restart
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Debian / Ubuntu Setup
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install nginx
|
||||
```
|
||||
|
||||
### Configuration
|
||||
1. Create a configuration file in `/etc/nginx/sites-available/ovpmon`:
|
||||
*(Use the same Nginx configuration block provided in the Alpine section above)*
|
||||
|
||||
2. Enable the site:
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/ovpmon /etc/nginx/sites-enabled/
|
||||
sudo rm /etc/nginx/sites-enabled/default # Optional: Remove default site
|
||||
```
|
||||
|
||||
3. Test and Restart:
|
||||
```bash
|
||||
sudo nginx -t
|
||||
sudo systemctl restart nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Deployment Checklist
|
||||
|
||||
1. **Frontend Build**:
|
||||
Ensure you have built the UI and copied the files to your web root:
|
||||
```bash
|
||||
cd APP_UI
|
||||
npm run build
|
||||
sudo mkdir -p /var/www/ovpmon
|
||||
sudo cp -r dist/* /var/www/ovpmon/
|
||||
```
|
||||
|
||||
2. **Permissions**:
|
||||
Ensure Nginx can read the web files:
|
||||
```bash
|
||||
sudo chown -R nginx:nginx /var/www/ovpmon # Alpine
|
||||
# OR
|
||||
sudo chown -R www-data:www-data /var/www/ovpmon # Debian/Ubuntu
|
||||
```
|
||||
|
||||
3. **SELinux (RedHat/CentOS only)**:
|
||||
If using SELinux, allow Nginx to make network connections:
|
||||
```bash
|
||||
setsebool -P httpd_can_network_connect 1
|
||||
```
|
||||
@@ -0,0 +1,125 @@
|
||||
# System services: update, backup, restore, rollback
|
||||
|
||||
Day-2 operations. Every update takes a verified backup first and rolls back automatically on failure. Install: [System services](README.md).
|
||||
|
||||
## Update
|
||||
|
||||
```sh
|
||||
deploy/native/update.sh # run from the checkout with the new version
|
||||
deploy/native/update.sh --ui-dist /root/ui-dist.tar.gz # install this UI (tarball or directory), always
|
||||
deploy/native/update.sh --build-ui # build the UI from APP_UI on this host and install it
|
||||
deploy/native/update.sh --source /root/ovpmon-src --yes # another checkout, no questions
|
||||
deploy/native/update.sh --no-pull # sources already in place / offline
|
||||
deploy/native/update.sh --rollback # manual rollback to the newest backup
|
||||
```
|
||||
|
||||
Run it from the checkout that holds the new version (the script uses the templates of that checkout). `--prefix` and the HTTPS port come from `/etc/ovpmon/deploy.state`. The update needs access to PyPI for the new virtualenvs.
|
||||
|
||||
Each phase is logged separately:
|
||||
|
||||
| Phase | What happens | If it fails |
|
||||
|---|---|---|
|
||||
| 0 Preflight | installation present, no unfinished install, source checkout complete, an explicit UI source readable (`--build-ui`: builder usable), services state, databases found, free space (backup and new code) | nothing was changed |
|
||||
| 1 **Backup** | verified backup in `/var/backups/ovpmon/<UTC timestamp>/` (see below) | the update is **refused**, nothing was changed |
|
||||
| 2 Sources | `git pull --ff-only` of the source checkout (skipped with `--no-pull` or without git) | nothing was changed |
|
||||
| 3 Prepare | new code copied to `<prefix>.new`, fresh virtualenvs with `pip install -r requirements.txt`, import check; the UI source is decided (after `git pull`: `--ui-dist`, `--build-ui`, the committed build; unchanged hash means no swap) and the new UI is staged next to the web root. **The running system is not touched** | nothing was changed |
|
||||
| 4 Stop and swap | the three application services are stopped (**OpenVPN keeps running**, VPN users stay connected); a final consistent snapshot; each code directory is renamed to `<dir>.old-<time>`, the new one moved in; **PKI, client profiles, `profiler.log`, `config.ini` and any database files below the code directory are moved over, never replaced**; virtualenv paths fixed | automatic rollback |
|
||||
| 5 **Database migration** | its own step, see below | automatic rollback, **nothing is started** |
|
||||
| 6 Files | UI swap (when a new UI was staged); helper; `helper.conf` (when missing); doas rules; service definitions; missing environment keys added (existing values never changed); nginx site; each replaced only when it differs and is managed by these scripts; units reloaded | automatic rollback |
|
||||
| 7 Start | services started, health checks, helper self-test | automatic rollback |
|
||||
| 8 Finish | the old code directories are removed (never one that still holds PKI data), the newest 5 backups kept, state recorded | |
|
||||
|
||||
The new `deploy/native/*.sh` take effect on the next run (the running script is not replaced).
|
||||
|
||||
### Database migration as its own step
|
||||
|
||||
After the services are stopped and the new code is in place, and **before anything is started**, `update.sh` runs for each database, with the **new** code, as user `ovpmon` and with the variables of `/etc/ovpmon/env` loaded:
|
||||
|
||||
| Database | Command (working directory) |
|
||||
|---|---|
|
||||
| Profiler | `APP_PROFILER/venv/bin/python migrate.py` in `<prefix>/APP_PROFILER` |
|
||||
| Monitoring | `APP_CORE/venv/bin/python migrate.py` in `<prefix>/APP_CORE` |
|
||||
|
||||
For each one: `migrate.py --check` (exit 0 up to date, 2 pending, 1 error or database newer than the code), the migration when 2, and a second check. The reports are printed. A failure or a "too new" database aborts **before any service starts** and triggers the rollback. Migrations are additive, run after an integrity check and a consistent copy `<db>.bak-<UTC timestamp>` next to the database, and are verified afterwards; details in [Database migrations](../../General/Database_Migrations.md). The migration also runs by itself when a service starts, so a manual file replacement is safe too; `update.sh` only makes it a visible, controlled step.
|
||||
|
||||
### Backup (phase 1, `backup.sh`)
|
||||
|
||||
```sh
|
||||
deploy/native/backup.sh # backup into /var/backups/ovpmon/<UTC timestamp>/
|
||||
deploy/native/backup.sh --stop # services stopped during the copy, started afterwards
|
||||
deploy/native/backup.sh --keep 14 # afterwards keep the newest 14
|
||||
```
|
||||
|
||||
Cron example (nightly, 14 kept): `30 3 * * * /opt/OpenVPN-Monitoring-Simple/deploy/native/backup.sh --keep 14 >> /var/log/ovpmon-backup.log 2>&1`.
|
||||
|
||||
| Content | File in the backup |
|
||||
|---|---|
|
||||
| both databases, consistent copies from the SQLite backup API (integrity-checked, owner and mode kept) | `db/monitor.db`, `db/profiler.db` |
|
||||
| `/etc/ovpmon` (environment, helper configuration, certificate, state) | `etc-ovpmon.tar.gz` |
|
||||
| `/etc/openvpn` (`server.conf`, `crl.pem`, scripts, `ipp.txt`) | `etc-openvpn.tar.gz` |
|
||||
| PKI `APP_PROFILER/easy-rsa` | `easy-rsa.tar.gz` |
|
||||
| client profiles `APP_PROFILER/client-config` | `client-config.tar.gz` |
|
||||
| `APP_CORE` and `APP_PROFILER` including the virtualenvs (needed for rollback) | `code.tar.gz` |
|
||||
| helper, service definitions, nginx site, sysctl file, doas file (Alpine) | `system.tar.gz` |
|
||||
| doas block (Debian/Ubuntu) | `doas-block.txt` |
|
||||
| UI files | `ui.tar.gz` |
|
||||
| checksums, description, completion marker | `SHA256SUMS`, `MANIFEST`, `COMPLETE` |
|
||||
|
||||
Every archive is verified (`tar -tzf`), the checksums are checked and each database copy passes `PRAGMA integrity_check` before `COMPLETE` is written; **only a `COMPLETE` backup is ever used**. `update.sh` backs up twice: in phase 1, and again as a final snapshot once the services are stopped (the code archive is reused). The backup holds private keys, password hashes and the signing secret: the directory is mode 700, the files mode 600. Keep copies off the host.
|
||||
|
||||
### Restore
|
||||
|
||||
```sh
|
||||
deploy/native/restore.sh /var/backups/ovpmon/20261005T101500Z # asks, stops, saves the current state, restores
|
||||
deploy/native/restore.sh /var/backups/ovpmon/20261005T101500Z --yes --start
|
||||
```
|
||||
|
||||
It verifies the backup, stops the three application services, saves the **current state** to `/var/backups/ovpmon/<time>-pre-restore` (`OVPMON_NO_SAFETY_BACKUP=1` skips this), then restores code, databases, `/etc/ovpmon`, `/etc/openvpn`, PKI, client profiles, helper, service definitions, nginx site, UI and doas rules. A replaced database is kept as `<db>.failed-<time>`. OpenVPN is not stopped. On a new host run `install.sh` first, then `restore.sh`.
|
||||
|
||||
Manual equivalent (services stopped, paths for the default prefix):
|
||||
|
||||
```sh
|
||||
B=/var/backups/ovpmon/20261005T101500Z
|
||||
( cd $B && sha256sum -c SHA256SUMS )
|
||||
tar -xzpf $B/code.tar.gz -C /opt/OpenVPN-Monitoring-Simple # after moving the current APP_CORE and APP_PROFILER aside
|
||||
tar -xzpf $B/easy-rsa.tar.gz -C /opt/OpenVPN-Monitoring-Simple/APP_PROFILER
|
||||
tar -xzpf $B/client-config.tar.gz -C /opt/OpenVPN-Monitoring-Simple/APP_PROFILER
|
||||
cp -p $B/db/profiler.db /var/lib/ovpmon/ovpn_profiler.db # the backup was made with the sqlite backup API
|
||||
cp -p $B/db/monitor.db /var/lib/ovpmon/openvpn_monitor.db
|
||||
tar -xzpf $B/etc-ovpmon.tar.gz -C / && tar -xzpf $B/etc-openvpn.tar.gz -C /
|
||||
tar -xzpf $B/system.tar.gz -C / # helper, service definitions, nginx site
|
||||
```
|
||||
|
||||
A single database can also be put back from its migration copy `<db>.bak-<time>` in `/var/lib/ovpmon`: stop the services, copy it over the database, start the OLD release.
|
||||
|
||||
### Automatic rollback and `--rollback`
|
||||
|
||||
On any failure from phase 4 on: the services are stopped, **code, databases, `/etc/ovpmon`, `/etc/openvpn`, helper, doas rules, service definitions, nginx site and UI files are restored from the backup of this run**, the services are started and checked, and the result is reported with the backup path.
|
||||
|
||||
How the code is restored: the current (new or half-swapped) code directories are renamed to `<dir>.rollback-<time>`, `code.tar.gz` is extracted (old code **and old virtualenvs**, so no Internet is needed), and the PKI and client profiles, which the update never replaced, are moved back from the directory that held them. They are restored from `easy-rsa.tar.gz` / `client-config.tar.gz` only if they are missing. The failed databases are kept as `<db>.failed-<time>`. If the rollback itself fails the message says where the backup is and how to retry (`update.sh --rollback` or `restore.sh`).
|
||||
|
||||
`update.sh --rollback` does the same by hand from the newest `COMPLETE` backup after a confirmation, with one difference: PKI and client profiles come from the backup too (one consistent set with the databases), and the current state is saved first to `<time>-pre-restore`. Use it when an update succeeded but the new version misbehaves. Data created after that backup is lost (it is in the `-pre-restore` copy).
|
||||
|
||||
## Existing installations (adoption)
|
||||
|
||||
A host that was set up by hand (the layout of the old guide: code in `/opt/OpenVPN-Monitoring-Simple`, `/etc/ovpmon/env`, init scripts or units, helper and doas rules) can be updated with `update.sh`: it has no state file, so it is adopted and recorded after the first successful update. Files that these scripts do not manage are **left as they are**: init scripts, units, an nginx site and a doas file that do not carry the marker line `managed by ovpmon deploy/native` and differ from the shipped ones are only reported. The helper is replaced (the new one behaves like the old one without `helper.conf`), `helper.conf` is written when missing, and `OVPMON_RUNTIME`, `OVPMON_OPENVPN_SERVICE` and `OVPMON_OPENVPN_CONFIG` are added to the environment file only when absent. If the install directory is a git checkout (the source is the install directory), `git pull` changes the live files, therefore a rollback is armed from phase 2.
|
||||
|
||||
## What is preserved on update
|
||||
|
||||
| Item | On update |
|
||||
|---|---|
|
||||
| Databases | Kept in place, backed up twice (consistent copies), migrated additively with their own `<db>.bak-*` copy; restored automatically if the update fails after the stop |
|
||||
| PKI (`APP_PROFILER/easy-rsa`): CA, keys, certificates, CRL | Moved, never replaced or deleted, backed up |
|
||||
| Client profiles (`APP_PROFILER/client-config`) | Moved, never replaced or deleted, backed up |
|
||||
| `/etc/ovpmon/env` (secret, DB paths) | Kept; only missing keys are added; copied into every backup |
|
||||
| `/etc/ovpmon/helper.conf`, TLS certificate and key | Kept (helper.conf is rewritten only while it carries our marker and differs) |
|
||||
| `/etc/openvpn` (`server.conf`, `crl.pem`, scripts, `ipp.txt`) | Not touched by the update; backed up |
|
||||
| OpenVPN process and VPN sessions | Not stopped or restarted; connected users stay connected |
|
||||
| `config.ini` of both components | Kept; the shipped one of the new version is saved as `config.ini.dist` when it differs |
|
||||
| `profiler.log`, other `*.log` / `*.db` files below the code directories | Kept (moved) |
|
||||
| Code, virtualenvs | **Replaced** (fresh virtualenvs; the old ones are in the backup) |
|
||||
| UI files | Replaced with `--ui-dist` / `--build-ui`, or automatically when the committed build of the source differs from the installed one (`.ui-source-hash`); kept when there is no UI source; the previous ones are in the backup |
|
||||
| Service definitions, nginx site, doas rules, helper | Replaced when they differ and are managed by these scripts; the previous ones are in the backup |
|
||||
| User sessions | Stay valid while the secret is unchanged |
|
||||
| Backups in `/var/backups/ovpmon` | The newest 5 kept, older ones pruned after a successful update; `-pre-restore` copies are never pruned automatically |
|
||||
| Data directories (`/var/lib/ovpmon`, PKI, client profiles) | **Never deleted** by any script |
|
||||
@@ -0,0 +1,158 @@
|
||||
# System services (Alpine, Debian, Ubuntu)
|
||||
|
||||
Install the suite as system services without containers. This page: what gets installed, supported systems, requirements, install per OS, verification. Next pages: [Operations](Operations.md) (update, backup, rollback), [Reference](Reference.md) (paths, environment, helper), [Web UI](Web_UI.md), [Firewall](Firewall.md), [Nginx](Nginx_Configuration.md), [Services](Service_Management.md), [Troubleshooting](Troubleshooting.md).
|
||||
|
||||
## Quick start
|
||||
|
||||
As root on Alpine 3.23, Debian 12 or Ubuntu 24.04 (the script installs all other packages and asks for the install directory):
|
||||
|
||||
```sh
|
||||
# Debian/Ubuntu: apt-get update && apt-get install -y git Alpine: apk add git
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
The script prints the URL (`https://<host>:8088/`), the certificate fingerprint and the **administrator login and password (shown once)**. Open the URL, then follow [First steps](../First_Steps.md). Details per system are below.
|
||||
|
||||
## Scripts
|
||||
|
||||
Install and update on **Alpine (OpenRC)**, **Debian** and **Ubuntu** (systemd) with the scripts in `deploy/native/`. Nothing runs in a container. The web UI is part of the repository (`deploy/ui-dist`) and is installed automatically, so the host needs no Node.
|
||||
|
||||
| Script | Purpose |
|
||||
|---|---|
|
||||
| `deploy/native/build-ui.sh` | builds the web UI (Docker, or the local Node without a container) into a tarball and/or into the repository (`--publish`) |
|
||||
| `deploy/native/check-ui.sh` | checks that the committed UI build `deploy/ui-dist` matches the `APP_UI` sources (exit 1 when stale) |
|
||||
| `deploy/native/install.sh` | first installation: packages, user, code, virtualenvs, configuration, services, nginx with TLS, health checks |
|
||||
| `deploy/native/update.sh` | update with a verified backup, a separate database migration step and automatic rollback; `--rollback` for a manual one |
|
||||
| `deploy/native/backup.sh` / `restore.sh` | stand-alone backup (cron friendly) and restore |
|
||||
| `deploy/native/lib.sh` | shared functions and the OS adapter (sourced, not executed) |
|
||||
|
||||
All scripts run as root, support `-h`, log in one style (UTC time stamp, `=== PHASE n ===`) and append every log line to `/var/log/ovpmon-deploy.log`.
|
||||
|
||||
## What is installed
|
||||
|
||||
```
|
||||
Browser --https:8088--> nginx --/--------------> /var/www/ovpmon (UI files)
|
||||
--/api/----------> 127.0.0.1:5001 ovpmon-api (gunicorn, APP_CORE)
|
||||
--/profiles-api/-> 127.0.0.1:8000 ovpmon-profiler (uvicorn, APP_PROFILER)
|
||||
ovpmon-gatherer (APP_CORE): OpenVPN status log -> monitoring database
|
||||
ovpmon-profiler (user ovpmon) --doas--> /usr/local/sbin/ovpmon-helper (root) --> server.conf, CRL, OpenVPN service
|
||||
```
|
||||
|
||||
The three `ovpmon-*` services run as the unprivileged user `ovpmon`. Only the helper acts as root, through six fixed `doas` rules, and it validates everything it installs (see [Privilege separation](../../Changes/2026-09-30_Privilege_Separation.md)). The services do not require OpenVPN to be running: the VPN server is created and started from the UI.
|
||||
|
||||
## Supported systems
|
||||
|
||||
| System | Tested version | Service manager | Notes |
|
||||
|---|---|---|---|
|
||||
| Alpine | 3.23 | OpenRC | the original reference platform |
|
||||
| Debian | 12 | systemd | |
|
||||
| Ubuntu | 24.04 LTS | systemd | needs the `universe` repository (`easy-rsa`, `opendoas`) |
|
||||
|
||||
Another version of these systems is refused with a warning unless you pass `--force` to `install.sh` (the update only warns). Other distributions are not supported (a Debian derivative works with `--force` at your own risk).
|
||||
|
||||
## Requirements
|
||||
|
||||
- A host with root access, a working package manager and Internet access (packages, Python packages from PyPI).
|
||||
- `/dev/net/tun` for OpenVPN (a normal VM has it; in containers it must be passed in).
|
||||
- Free space: about 1 GB for the code and virtualenvs (the script checks it), plus room for the backups.
|
||||
- Python 3.9 or newer (Alpine 3.23: 3.12, Debian 12: 3.11, Ubuntu 24.04: 3.12).
|
||||
- Free TCP ports `5001`, `8000` (on `127.0.0.1`) and the HTTPS port (default `8088`).
|
||||
- A UI build: the clone contains one (`deploy/ui-dist`, see [Web UI](Web_UI.md)). **The host needs no Node.js** unless you choose `--build-ui`.
|
||||
- GNU tar (on Alpine the package `tar`; the installer adds it).
|
||||
|
||||
## Install
|
||||
|
||||
Clone the repository on the target host (anywhere **outside** the install directory: the checkout is only the source, e.g. `/root/ovpmon-src`) and run, as root. The UI comes with the clone (`deploy/ui-dist`, see [Web UI](Web_UI.md)). The install directory is always asked for: pass `--prefix DIR`, or the script prompts for it (and for a confirmation); there is no default. Recommended: `/opt/OpenVPN-Monitoring-Simple`.
|
||||
|
||||
### Alpine (OpenRC)
|
||||
|
||||
```sh
|
||||
apk add git # only to clone; the script installs the rest
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Debian 12
|
||||
|
||||
```sh
|
||||
apt-get update && apt-get install -y git
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
### Ubuntu 24.04
|
||||
|
||||
```sh
|
||||
sudo -i
|
||||
apt-get update && apt-get install -y git # make sure the "universe" component is enabled
|
||||
git clone <repository> /root/ovpmon-src && cd /root/ovpmon-src
|
||||
deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple
|
||||
```
|
||||
|
||||
Options:
|
||||
|
||||
| Option | Meaning |
|
||||
|---|---|
|
||||
| `--prefix DIR` | install directory, **required**: asked interactively when the option is missing (without a terminal the script stops). Absolute path of letters, digits, `. _ - /`, no trailing `/`; must be new or empty, must not be the repository checkout (or contain it, or lie inside it) and must not be a system directory (`/`, `/opt`, `/root`, `/usr`, `/var`, ...) |
|
||||
| `--ui-dist FILE\|DIR` | UI tarball from `build-ui.sh` or a directory with `index.html`; highest priority |
|
||||
| `--build-ui` | build the UI now from `APP_UI` (Docker, otherwise the host's Node 20.19+) instead of using `deploy/ui-dist` |
|
||||
| `--node-download` | with `--build-ui`: use a temporary official Node 20 (checksum verified, glibc only) |
|
||||
| `--no-ui` | install a placeholder page on purpose; without any UI source and without this option the install stops |
|
||||
| `--https-port N` | HTTPS port of the web UI (default `8088`) |
|
||||
| `--host-name NAME` | DNS name or IP for the certificate and the CORS origin (default: the detected address of the default route) |
|
||||
| `--admin-user NAME` | login of the first administrator (default `admin`) |
|
||||
| `--force` | continue on an untested OS version |
|
||||
|
||||
### Differences between the systems
|
||||
|
||||
| | Alpine 3.23 | Debian 12 / Ubuntu 24.04 |
|
||||
|---|---|---|
|
||||
| Packages | `python3 py3-pip nginx openvpn easy-rsa iptables bash doas openssl curl tar` | `python3 python3-venv python3-pip nginx openvpn easy-rsa iptables opendoas openssl curl ca-certificates tar iproute2` |
|
||||
| Service manager | OpenRC: `rc-service NAME start\|stop\|restart\|status`, `rc-update add NAME default` | systemd: `systemctl start\|stop\|restart\|status NAME`, `systemctl enable NAME` |
|
||||
| Our service files | `/etc/init.d/ovpmon-api`, `-gatherer`, `-profiler` (`supervise-daemon`, `command_user=ovpmon:ovpmon`) | `/etc/systemd/system/ovpmon-*.service` (`User=ovpmon`, `EnvironmentFile=/etc/ovpmon/env`) |
|
||||
| Service logs | `/var/log/ovpmon/ovpmon-<name>.log` | `journalctl -u ovpmon-<name>` |
|
||||
| OpenVPN service | `openvpn`; config `/etc/openvpn/server.conf`, plus the link `/etc/openvpn/openvpn.conf -> server.conf` | `openvpn-server@server`; config `/etc/openvpn/server/server.conf` |
|
||||
| nginx site | `/etc/nginx/http.d/ovpmon.conf` | `/etc/nginx/conf.d/ovpmon.conf` |
|
||||
| doas | package `doas`; our rules in `/etc/doas.d/ovpmon.conf` (own file, as on the existing hosts) | package `opendoas`; our rules as a marked block inside `/etc/doas.conf` |
|
||||
| `ovpmon` user | `adduser -S`, shell `/sbin/nologin` | `useradd --system`, shell `/usr/sbin/nologin` |
|
||||
|
||||
The nginx site does not collide with the distribution defaults: the default server of Alpine and Debian listens on port 80, ours on 8088, and both distribution `nginx.conf` files include the directory above (the installer checks the `include` line).
|
||||
|
||||
### What `install.sh` does
|
||||
|
||||
| Phase | Content |
|
||||
|---|---|
|
||||
| 0 Preflight | root, OS and version, service manager present, no existing installation (otherwise it points to `update.sh`), source checkout complete, UI source found (and built for `--build-ui`; a stale committed build only warns), ports free, free space |
|
||||
| 1 Packages | the table above; GNU tar, Python 3.9+ with `venv` and `sqlite3`, `easy-rsa` checked |
|
||||
| 2 User and directories | user `ovpmon`; `/var/lib/ovpmon` (+ `staging/`), `/var/log/ovpmon`, `/var/log/openvpn` (with `openvpn-status.log` as `root:ovpmon 640`), `/etc/openvpn/scripts`, `/etc/ovpmon` |
|
||||
| 3 Code | `APP_CORE` and `APP_PROFILER` copied to the prefix (without venvs, databases, logs, Dockerfiles), plus the scripts and templates under `deploy/` and `DOCS/General/` (so the install directory can run `update.sh --source ...`); `VERSION` |
|
||||
| 4 Virtualenvs and easy-rsa | two virtualenvs (`pip install -r requirements.txt`, plus `gunicorn` for `APP_CORE`), an import check, the easy-rsa workspace copied from `/usr/share/easy-rsa` into `APP_PROFILER/easy-rsa` (a real directory, never a symlink), code made root-owned and read-only |
|
||||
| 5 Configuration | `/etc/ovpmon/env` (random secret, generated administrator), `/etc/ovpmon/helper.conf`, `/usr/local/sbin/ovpmon-helper`, doas rules and a **self-test** (`ovpmon` runs the helper through doas), forwarding via `/etc/sysctl.d`, OpenVPN prerequisites (Alpine: the `openvpn.conf` link; Debian/Ubuntu: `/etc/openvpn/server/`; the OpenVPN service is **enabled, not started**: there is no `server.conf` yet) |
|
||||
| 6 Services, UI, nginx | the three service definitions installed and enabled, UI files to `/var/www/ovpmon` (validated, swapped in atomically, with `.ui-source-hash`), a self-signed EC certificate (`/etc/ovpmon/tls/`, SAN: host name, detected IP, `127.0.0.1`, `localhost`), the nginx site, nginx enabled and reloaded |
|
||||
| 7 Start and checks | services started; health checks (below) |
|
||||
| 8 Administrator | when a user exists in the monitoring database, the seed is removed from `/etc/ovpmon/env` and `ovpmon-api` is restarted; if the database cannot be read or is empty the seed stays and a warning says so |
|
||||
|
||||
Health checks: the three services are running; `http://127.0.0.1:5001/` answers; `http://127.0.0.1:8000/` returns 200; `https://127.0.0.1:<port>/` (with `-k`) returns 200; `/api/v1/user/me` and `/profiles-api/config` through nginx return 401 without a token.
|
||||
|
||||
The final summary shows the URL, the certificate fingerprint, the paths and the **generated administrator password once**. The state is recorded in `/etc/ovpmon/deploy.state` (prefix, HTTPS port, OS, version, dates). If the script fails it is **safe to run again**: it resumes, keeps the existing secret, certificate, easy-rsa workspace and data.
|
||||
|
||||
Then in the UI: sign in, change the password and enable 2FA, **PKI Configuration -> Initialize PKI**, generate the server configuration, start the VPN server.
|
||||
|
||||
### Without the script (outline)
|
||||
|
||||
Create the `ovpmon` user and the directories, copy the code, build both virtualenvs, write `/etc/ovpmon/env`, `helper.conf` and the doas rules from the templates, install the service definitions (`DOCS/General/systemd/*.service` or `DOCS/General/openrc/ovpmon-*`; replace `/opt/OpenVPN-Monitoring-Simple` if you use another prefix), copy the UI, add the nginx site from `deploy/native/nginx/ovpmon.conf.template` (replace `@HTTPS_PORT@`, `@WEB_ROOT@`, `@TLS_CRT@`, `@TLS_KEY@`). The commands are exactly what `install.sh` runs; reading the script is the shortest reference.
|
||||
|
||||
## Verify an installation
|
||||
|
||||
```sh
|
||||
rc-status | grep -E "ovpmon|nginx|openvpn" # Alpine; Debian/Ubuntu: systemctl status 'ovpmon-*' nginx
|
||||
ss -tlnp | grep -E ":(8088|5001|8000) "
|
||||
curl -sk -o /dev/null -w "%{http_code}\n" https://127.0.0.1:8088/ # 200
|
||||
curl -sk -o /dev/null -w "%{http_code}\n" https://127.0.0.1:8088/profiles-api/config # 401 without a token
|
||||
su -s /bin/sh ovpmon -c "doas -n /usr/local/sbin/ovpmon-helper service status" # JSON, not "Operation not permitted"
|
||||
```
|
||||
|
||||
## Next
|
||||
|
||||
[First steps](../First_Steps.md) · [Web UI](Web_UI.md) · [Operations](Operations.md) · [Reference](Reference.md) · [Firewall](Firewall.md) · [Troubleshooting](Troubleshooting.md) · [Choose another method](../README.md)
|
||||
@@ -0,0 +1,75 @@
|
||||
# System services: reference
|
||||
|
||||
Paths and owners, the environment file, the root helper configuration and security notes. Install: [System services](README.md).
|
||||
|
||||
## Layout: what is where, who owns it
|
||||
|
||||
| Item | Path | Owner, mode |
|
||||
|---|---|---|
|
||||
| Code | `<prefix>/APP_CORE`, `<prefix>/APP_PROFILER` | `root:root`, read-only for others |
|
||||
| Virtualenvs | `<prefix>/APP_CORE/venv`, `<prefix>/APP_PROFILER/venv` | `root:root` |
|
||||
| **PKI** (CA, keys, certificates, CRL) | `<prefix>/APP_PROFILER/easy-rsa` (real directory) | `ovpmon:ovpmon` 750 |
|
||||
| **Client profiles** | `<prefix>/APP_PROFILER/client-config` (real directory) | `ovpmon:ovpmon` 750 |
|
||||
| Profiler log | `<prefix>/APP_PROFILER/profiler.log` | `ovpmon:ovpmon` 640 |
|
||||
| Shipped settings file | `<prefix>/APP_CORE/config.ini`, `<prefix>/APP_PROFILER/config.ini` | `root:root`; the environment file overrides it |
|
||||
| **Databases** | `/var/lib/ovpmon/openvpn_monitor.db`, `ovpn_profiler.db`, migration copies `*.db.bak-*` | `ovpmon:ovpmon` |
|
||||
| Staging of `server.conf` | `/var/lib/ovpmon/staging/` | `ovpmon:ovpmon` 750 |
|
||||
| Service environment | `/etc/ovpmon/env` | `root:root` 600 |
|
||||
| Helper configuration | `/etc/ovpmon/helper.conf` | `root:root` 644 |
|
||||
| TLS certificate and key | `/etc/ovpmon/tls/ovpmon.crt`, `ovpmon.key` | `root:root` (key 600) |
|
||||
| Deployment state | `/etc/ovpmon/deploy.state` | `root:root` 644 |
|
||||
| nftables ruleset of the VPN clients (only after `firewall.sh`) | `/etc/ovpmon/nftables.nft`, service `ovpmon-nft` | `root:root` 644 |
|
||||
| Root helper | `/usr/local/sbin/ovpmon-helper` | `root:root` 755 |
|
||||
| doas rules | Alpine: `/etc/doas.d/ovpmon.conf`; Debian/Ubuntu: block in `/etc/doas.conf` | `root:root` |
|
||||
| OpenVPN configuration | `/etc/openvpn/server.conf` (Alpine) or `/etc/openvpn/server/server.conf`, `/etc/openvpn/crl.pem`, `/etc/openvpn/scripts/` | `root:root` |
|
||||
| OpenVPN logs | `/var/log/openvpn/openvpn.log`, `openvpn-status.log` (`root:ovpmon` 640) | `root` |
|
||||
| Service logs | `/var/log/ovpmon/` (OpenRC) or the journal (systemd) | `ovpmon` / systemd |
|
||||
| UI files | `/var/www/ovpmon` | `root:root` |
|
||||
| Backups | `/var/backups/ovpmon/<UTC timestamp>/` | `root:root` 700 |
|
||||
| Deployment log | `/var/log/ovpmon-deploy.log` | `root:root` 600 |
|
||||
|
||||
The profiler resolves `easy-rsa/` and `client-config/` relative to its working directory (`APP_PROFILER`) and keeps `client-config/<name>.ovpn` as a relative path in its database; therefore both are real directories inside `APP_PROFILER` (a symlinked `client-config` breaks the real-path checks and the `clear_pki` cleanup).
|
||||
|
||||
## Environment file and helper configuration
|
||||
|
||||
`/etc/ovpmon/env` (`root:root` 600) is read by the init system as root and handed to the services. Lines are `KEY=VALUE` without quotes or spaces (systemd and OpenRC read the same file).
|
||||
|
||||
| Variable | Default written by `install.sh` | Meaning |
|
||||
|---|---|---|
|
||||
| `OVPMON_API_SECRET_KEY` | random, 64 hex characters | signing key of both APIs; at least 32 characters, no `change-me`/`changeme` (the APIs refuse to start otherwise); changing it logs everybody out; keep it across updates. `update.sh` issues a new random key when it is missing or weak and resets all sessions |
|
||||
| `OVPMON_API_HOST`, `OVPMON_API_PORT` | `127.0.0.1`, `5001` | informational: gunicorn is started with `-b 127.0.0.1:5001` |
|
||||
| `OVPMON_OPENVPN_MONITOR_DB_PATH` | `/var/lib/ovpmon/openvpn_monitor.db` | monitoring database |
|
||||
| `OVPMON_PROFILER_DB_PATH` | `/var/lib/ovpmon/ovpn_profiler.db` | profiler database |
|
||||
| `OVPMON_OPENVPN_MONITOR_LOG_PATH` | `/var/log/openvpn/openvpn-status.log` | status log read by the gatherer |
|
||||
| `OVPMON_LOGGING_LEVEL` | `INFO` | |
|
||||
| `OVPMON_CORS_ORIGINS` | `https://<host>:<https-port>` | extra allowed origin (the UI is same-origin behind nginx) |
|
||||
| `OVPMON_RUNTIME` | `host` | forces host mode (never "container"), needed when the host itself runs inside a container |
|
||||
| `OVPMON_OPENVPN_SERVICE` | `openvpn` (Alpine) / `openvpn-server@server` | service name for the root (non-helper) path |
|
||||
| `OVPMON_OPENVPN_CONFIG` | `/etc/openvpn/server.conf` / `/etc/openvpn/server/server.conf` | server config path for the root (non-helper) path |
|
||||
| `OVPMON_INITIAL_ADMIN_USER`, `OVPMON_INITIAL_ADMIN_PASSWORD` | generated | seed, only while the users table is empty; removed by `install.sh` after the first start |
|
||||
| `OVPMON_AUTO_MIGRATE` | unset | `0` makes the services refuse to start while migrations are pending |
|
||||
|
||||
With the unprivileged profiler the API only stages `server.conf`; **the helper configuration decides where it is installed and which service is controlled.**
|
||||
|
||||
`/etc/ovpmon/helper.conf` (INI, section `[helper]`, `root:root`, not group/world writable, otherwise the helper refuses to run). Without the file the helper uses the built-in values of the Alpine layout.
|
||||
|
||||
| Key | Alpine (written) | Debian/Ubuntu (written) | Rule |
|
||||
|---|---|---|---|
|
||||
| `install_dir` | `/opt/OpenVPN-Monitoring-Simple` | same | absolute, no `..`; the PKI is `<install_dir>/APP_PROFILER/easy-rsa/pki` |
|
||||
| `service_manager` | `openrc` | `systemd` | `openrc` or `systemd` |
|
||||
| `service_unit` | `openvpn` | `openvpn-server@server` | `^[A-Za-z0-9@._-]{1,64}$`, not starting with `-` or `.` |
|
||||
| `config_path` | `/etc/openvpn/server.conf` | `/etc/openvpn/server/server.conf` | absolute, below `/etc/openvpn/`, ends with `.conf` |
|
||||
| `staged_path` | `/var/lib/ovpmon/staging/server.conf` | same | absolute, below `/var/lib/ovpmon/` |
|
||||
|
||||
OpenRC runs `/sbin/rc-service <unit> <action>`, systemd runs `systemctl <action> <unit>` (fixed argument list, fixed `PATH`). Unknown keys or invalid values make the helper refuse.
|
||||
|
||||
## Security notes
|
||||
|
||||
- Services run as `ovpmon` (no login shell); code and virtualenvs are root-owned and read-only for them. systemd units add `PrivateTmp`, `ProtectHome`, `ProtectSystem=full`, kernel and cgroup protection; `ovpmon-api` and `ovpmon-gatherer` also set `NoNewPrivileges`. `ovpmon-profiler` must **not** (it calls the setuid `doas`), must not use seccomp-based options either (`ProtectKernelTunables`, `ProtectKernelModules`, `RestrictRealtime`, `LockPersonality`, `SystemCallFilter`, ...): for an unprivileged unit systemd then sets NoNewPrivileges implicitly and `doas` fails with "not installed setuid" (check: `grep NoNewPrivs /proc/<main pid>/status` must show 0). It keeps `/etc/openvpn` writable, because the helper runs inside the profiler's mount namespace.
|
||||
- The helper accepts six fixed commands, validates `server.conf` against an allowlist and reads its own root-owned configuration; nothing else runs as root. `ovpmon` owns the PKI including the CA key: a compromised profiler can issue client certificates (VPN access) but cannot become root.
|
||||
- `/etc/ovpmon/env` is `root:root` 600 and never printed; the generated administrator password is shown once and removed from the file after the first start.
|
||||
- Backups contain private keys, password hashes and the secret: mode 700/600, keep off-host copies encrypted.
|
||||
- Both APIs listen on `127.0.0.1`; only nginx (HTTPS) and OpenVPN are reachable. Replace the self-signed certificate when a domain is available; consider restricting the UI by address or reaching it through the VPN.
|
||||
- The scripts do not harden SSH or install fail2ban: see [Host hardening](Troubleshooting.md#host-hardening-recommended-not-done-by-the-scripts).
|
||||
|
||||
Related: [Database migrations](../../General/Database_Migrations.md), [Privilege separation](../../Changes/2026-09-30_Privilege_Separation.md), [Containers](../Containers/README.md), [Deployment plan](../../Changes/2026-10-05_Deployment_Scenarios_PLAN.md).
|
||||
@@ -0,0 +1,31 @@
|
||||
# Service Setup Guide
|
||||
|
||||
The OpenVPN Monitor components run as three system services under the unprivileged user `ovpmon`. `deploy/native/install.sh` installs and enables them (see [System services](README.md)); this page is the day-to-day reference.
|
||||
|
||||
| Service | Command (working directory under the install dir, default `/opt/OpenVPN-Monitoring-Simple`) | Listens |
|
||||
|---|---|---|
|
||||
| `ovpmon-api` | `APP_CORE/venv/bin/python -m gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app` | 127.0.0.1:5001 |
|
||||
| `ovpmon-gatherer` | `APP_CORE/venv/bin/python openvpn_gatherer_v3.py` | - |
|
||||
| `ovpmon-profiler` | `APP_PROFILER/venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8000` | 127.0.0.1:8000 |
|
||||
|
||||
Settings: `/etc/ovpmon/env` (`root:root` 600). The services start after the network and do not depend on OpenVPN.
|
||||
|
||||
## Definitions
|
||||
|
||||
- Alpine (OpenRC): [`openrc/ovpmon-*`](../../General/openrc/INSTALL.md) in `/etc/init.d/` (`supervise-daemon`, `command_user=ovpmon:ovpmon`, environment sourced in `start_pre`, log in `/var/log/ovpmon/`).
|
||||
- Debian / Ubuntu (../../General/systemd): [`systemd/ovpmon-*.service`](../../General/systemd) in `/etc/systemd/system/` (`User=ovpmon`, `EnvironmentFile=/etc/ovpmon/env`, moderate hardening, log in the journal).
|
||||
|
||||
Install them with the scripts (they adjust the install directory); by hand, copy a file, replace `/opt/OpenVPN-Monitoring-Simple` if needed and enable it as below.
|
||||
|
||||
## Commands
|
||||
|
||||
| | OpenRC (Alpine) | systemd (Debian, Ubuntu) |
|
||||
|---|---|---|
|
||||
| Enable at boot | `rc-update add ovpmon-api default` | `systemctl enable ovpmon-api` |
|
||||
| Start / stop / restart | `rc-service ovpmon-api start\|stop\|restart` | `systemctl start\|stop\|restart ovpmon-api` |
|
||||
| Status | `rc-service ovpmon-api status` | `systemctl status ovpmon-api` |
|
||||
| Log | `tail -f /var/log/ovpmon/ovpmon-api.log` | `journalctl -u ovpmon-api -f` |
|
||||
| After editing `/etc/ovpmon/env` | restart the services | restart the services |
|
||||
| After editing a unit file | - | `systemctl daemon-reload` |
|
||||
|
||||
The OpenVPN server itself (`openvpn` on Alpine, `openvpn-server@server` on Debian/Ubuntu) is started and stopped from the UI through the root helper (`doas`); it is not an `ovpmon-*` service.
|
||||
@@ -0,0 +1,36 @@
|
||||
# System services: troubleshooting and host hardening
|
||||
|
||||
Install: [System services](README.md). Update and backup: [Operations](Operations.md).
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Cause and action |
|
||||
|---|---|
|
||||
| `invalid --prefix ...` / `no valid install directory given` | The install directory must be a new or empty dedicated directory, not the repository checkout and not a system directory. Move or clone the repository elsewhere (for example `/root/ovpmon-src`) or choose another directory |
|
||||
| `already installed ... use update.sh` / `an installation already exists` | `install.sh` never installs over an installation. Use `update.sh` (it adopts hand-made installations) |
|
||||
| `installation stopped in phase ...` | Fix the cause and run `install.sh` again: it resumes and keeps secrets, certificate and data |
|
||||
| `OVPMON_API_SECRET_KEY in /etc/ovpmon/env is too short` / `not set` / `a placeholder/default value`; a service exits with `Refusing to start` | The signing key is missing or weak. `install.sh` (resume) stops: set `OVPMON_API_SECRET_KEY=$(openssl rand -hex 32)` in `/etc/ovpmon/env` and run it again. `update.sh` fixes it itself: it issues a new random key before the start and **resets all sessions** (everyone signs in again) |
|
||||
| `not a tested version ... needs --force` | Untested OS version: `install.sh --force` at your own risk |
|
||||
| `ports ... already in use` | Another service uses 5001, 8000 or the HTTPS port: stop it or use `--https-port` |
|
||||
| `pip install failed` | No access to the Python package index (proxy: `pip` honours `HTTPS_PROXY`); on Alpine check that `py3-pip` is installed |
|
||||
| Health check fails | Alpine: `tail /var/log/ovpmon/ovpmon-api.log` (or `-gatherer`, `-profiler`); systemd: `journalctl -u ovpmon-api -n 50`. The scripts print the last lines of a failing service |
|
||||
| `FATAL: ... newer than this version` / migration "too new" | The database was migrated by a newer release. Do not start the old version on it: update to the newer sources or restore a matching backup |
|
||||
| Migration failed | Nothing was started and the rollback restored the databases; the report names the migration, the `<db>.bak-*` copy is in `/var/lib/ovpmon`. Keep the report |
|
||||
| Profiler cannot start/stop OpenVPN, "helper failed" | The self-test warning of the scripts points at it: check the doas rules (`doas -C /etc/doas.conf` or `/etc/doas.d/ovpmon.conf`), `/etc/ovpmon/helper.conf` (must be `root:root` and not group/world writable; `su -s /bin/sh ovpmon -c "doas -n /usr/local/sbin/ovpmon-helper service status"` prints the reason) |
|
||||
| `Configuration rejected` when generating the server config | The helper allowlist refused a directive, see [Privilege separation](../../Changes/2026-09-30_Privilege_Separation.md) |
|
||||
| OpenVPN does not start on Debian/Ubuntu | `systemctl status openvpn-server@server`, `journalctl -u openvpn-server@server`; the config must be `/etc/openvpn/server/server.conf` and `/dev/net/tun` must exist |
|
||||
| Clients connect but have no internet | Forwarding or NAT is missing: see [Firewall](Firewall.md) |
|
||||
| nginx: `conflicting server name` / port in use | Another site uses the same port; change `--https-port` (or the `listen` line of the site and reload) |
|
||||
| Browser warns about the certificate | It is self-signed; check the fingerprint printed by `install.sh`, or install a real certificate under `/etc/ovpmon/tls/` and reload nginx |
|
||||
| `no UI source found` (install stops) | The checkout has no `deploy/ui-dist` (incomplete clone, or the maintainer did not publish it) and no `--ui-dist`. Use `--build-ui` (Docker or Node 20.19+; `--node-download` on Debian/Ubuntu), `--ui-dist FILE\|DIR` from another machine, or `--no-ui` for a placeholder page |
|
||||
| Warning "committed UI build ... is OLDER than the APP_UI sources" | Someone changed `APP_UI` without refreshing the build. Maintainers: `deploy/native/build-ui.sh --publish` and commit `deploy/ui-dist`. On the host: `--build-ui` |
|
||||
| `the installed Node is too old` / `node and npm are not installed` (`--build-ui`, `build-ui.sh --local`) | The message lists the commands for the OS: Alpine `apk add nodejs npm`; Debian/Ubuntu `--node-download` or Node 20+ from nodejs.org |
|
||||
| UI shows the placeholder page | Installed with `--no-ui`: run `deploy/native/update.sh` (installs the UI of the repository), or add `--ui-dist` / `--build-ui` |
|
||||
| `su`/`doas` self-test fails on a minimal container | Containers often lack `/etc/pam.d/doas` or a real init system; the services may still work (check health) |
|
||||
|
||||
## Host hardening (recommended, not done by the scripts)
|
||||
|
||||
- SSH: key-only (`PasswordAuthentication no`, `KbdInteractiveAuthentication no`, `PermitRootLogin prohibit-password`). Cloud-init drop-ins in `/etc/ssh/sshd_config.d/` can override the main file, so put your settings in a file that sorts first, for example `00-hardening.conf`.
|
||||
- fail2ban: jails `sshd` and one for `POST /api/auth/login` (HTTP 401/429/503) on the nginx access log.
|
||||
- Backends are bound to `127.0.0.1`; only the HTTPS port and the VPN port should be reachable from outside.
|
||||
- Keep the system updated (`apk upgrade` / `apt-get upgrade`) and watch the advisories of OpenVPN, nginx and OpenSSH.
|
||||
@@ -0,0 +1,59 @@
|
||||
# System services: the web UI
|
||||
|
||||
How the UI reaches the host (no Node needed by default), the build script and the maintainer routine. Install: [System services](README.md).
|
||||
|
||||
## Overview
|
||||
|
||||
The UI is built from `APP_UI` (Vue/Vite). The repository carries a ready build in `deploy/ui-dist/` together with `SOURCE_HASH`, a SHA-256 over the UI sources it was built from (`APP_UI/src`, `public`, `index.html`, `package.json`, `package-lock.json`, `vite.config.js`, `jsconfig.json`). `install.sh` and `update.sh` find the UI themselves. The directory is outside `APP_UI`, so the container builds are not affected.
|
||||
|
||||
### Three ways to get the UI onto a host
|
||||
|
||||
| Way | Option | When |
|
||||
|---|---|---|
|
||||
| Committed build | none (automatic) | the normal case: `git clone`, `install.sh`, done; no Node, no Docker |
|
||||
| Build on the host | `--build-ui` | the committed build is stale or missing; builds from `APP_UI` now with Docker (when its daemon works) or the host's Node 20.19+ |
|
||||
| Build elsewhere | `--ui-dist FILE\|DIR` | a tarball from `build-ui.sh` or a directory with `index.html`, for example from a CI job or another machine |
|
||||
|
||||
Order used by `install.sh` and `update.sh`: **1.** `--ui-dist` (explicit, always installed), **2.** `--build-ui` (always builds fresh from the sources), **3.** the committed `deploy/ui-dist` of the checkout (automatic), **4.** nothing found: `install.sh` **stops** (it lists the ways out) unless `--no-ui` is given (a placeholder page on purpose); `update.sh` keeps the installed UI. `install.sh` also still accepts `deploy/native/ui-dist.tar.gz` as a last resort below the committed directory. `--ui-dist` and `--build-ui` exclude each other.
|
||||
|
||||
The installed web root records the hash it came from in `/var/www/ovpmon/.ui-source-hash` (`unknown` for archives that were not made by `build-ui.sh`). `update.sh` compares it with the `SOURCE_HASH` of the repository build: equal, the UI is not replaced (and it says so); different or missing (for example a host installed with `--no-ui`), the new UI is staged in phase 3 and swapped in phase 6, with the rest of the update, so it is part of the backup and the automatic rollback. The UI source is decided after `git pull`, so a pulled new build is used in the same run. The old UI is in the backup.
|
||||
|
||||
### Staleness guard
|
||||
|
||||
When the hash of the current `APP_UI` sources differs from `SOURCE_HASH`, the committed build is **older than the sources** (someone changed the UI and did not refresh the build). `install.sh` and `update.sh` then print a loud warning with the two hashes and the remedy, and still use the committed build (it works, it only lacks the latest UI changes). A host that needs the current UI adds `--build-ui`. A build without a valid `SOURCE_HASH` counts as stale.
|
||||
|
||||
### Maintainer routine
|
||||
|
||||
After every change in `APP_UI` (or its `package*.json`, `vite.config.js`), **before committing**:
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh --publish # rebuilds deploy/ui-dist/ and SOURCE_HASH from the current sources
|
||||
deploy/native/check-ui.sh # prints fresh | stale | missing; exit 0 | 1 | 2
|
||||
git add APP_UI deploy/ui-dist
|
||||
```
|
||||
|
||||
`check-ui.sh` also fits a release checklist or a CI step (it changes nothing). `--publish` replaces the content of `deploy/ui-dist/` by a move (the old directory is only deleted after the new one is in place).
|
||||
|
||||
### build-ui.sh
|
||||
|
||||
```sh
|
||||
deploy/native/build-ui.sh # Docker if it works, otherwise local Node -> deploy/native/ui-dist.tar.gz
|
||||
deploy/native/build-ui.sh --docker # node:20-alpine container (OVPMON_NODE_IMAGE or --image to change)
|
||||
deploy/native/build-ui.sh --local # Node >= 20.19 and npm of this machine, no container
|
||||
deploy/native/build-ui.sh --local --node-download # temporary official Node 20, deleted after the build
|
||||
deploy/native/build-ui.sh --publish # refresh deploy/ui-dist/ in the repository
|
||||
deploy/native/build-ui.sh -o /tmp/ui.tar.gz # tarball for another host (also with --publish)
|
||||
deploy/native/build-ui.sh --check # only check that the builder is usable
|
||||
```
|
||||
|
||||
Without `--docker`/`--local` the script uses Docker when its daemon answers, otherwise the local Node. The tarball holds the content of `dist/` and `SOURCE_HASH`. **Nothing is written into the source tree**: a container sees `APP_UI` read-only; `--local` copies it (without `node_modules` and `dist`) into a temporary directory and runs `npm ci` there (`npm install` without a lock file), so the repository gets no `node_modules` and no `dist`.
|
||||
|
||||
`--local` needs Node 20.19 or newer with npm. When it is missing or too old the script prints what to do and stops:
|
||||
|
||||
| System | What to do |
|
||||
|---|---|
|
||||
| Alpine | `apk add nodejs npm` (check `node --version` afterwards) |
|
||||
| Debian / Ubuntu | the distribution's Node is usually too old (Debian 12 and Ubuntu 24.04 ship Node 18): add `--node-download` (needs `apt-get install -y curl xz-utils`), or install Node 20+ with npm from nodejs.org / NodeSource |
|
||||
| anything else | Node 20.19+ from nodejs.org, or build with `--docker` on a machine with Docker |
|
||||
|
||||
`--node-download` fetches `SHASUMS256.txt` from `https://nodejs.org/dist/latest-v20.x/`, picks `node-v20.*-linux-<x64|arm64>.tar.xz`, verifies its SHA-256, unpacks it into a temporary directory (npm cache included), builds with it and deletes everything; nothing is installed on the host. glibc systems only: on Alpine (musl) it refuses and points to `apk add nodejs npm`. It needs `curl`, `tar`, `xz` and access to nodejs.org (`OVPMON_NODE_MAJOR` selects another major version).
|
||||
Reference in new issue
Block a user