Backup and Restore: packages, Local/S3/SFTP/FTP destinations, UI and API

Encrypted packages (databases, PKI, client profiles) with safe restore and
a pre-restore safety copy, usable for server-to-server migration across
container and system-service installs. New Management page, ovp_backups
volume, migrations code in the profiler image, server name in package names.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 09:38:09 +03:00
1 parent d29c261347
commit f8cdcd0fc6
55 files changed
+4401 -37

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ Each component reads `config.ini` (shipped in `APP_CORE/` and `APP_PROFILER/`);
| `OVPMON_PROFILER_DB_PATH` | profiler database |
| `OVPMON_OPENVPN_MONITOR_LOG_PATH` | path of `openvpn-status.log` |
| `OVPMON_LOGGING_LEVEL` | `INFO` / `DEBUG` |
| `OVPMON_BACKUP_LOCAL_ROOT` | root of the local backup destinations (default `/var/lib/ovpmon/backups`; containers: `/app/backups`); other backup variables: [Backup and Restore](../Profiler_Management/Backup_Restore.md) |
## JWT signing key rule
+2
View File
@@ -31,6 +31,8 @@ VPN clients --udp/1194--> OpenVPN
| PKI | CA, server and client keys and certificates, CRL, `ta.key`, `dh.pem` (**secret, back it up**) |
| Client profiles | generated `.ovpn` files |
| `server.conf` | generated by the profiler from the settings in the UI |
| Backup settings (SQLite `ovpmon_backup.db`, next to the profiler DB) | backup destinations (secrets encrypted), passphrase, history; not part of a backup package |
| Local backup packages | `/var/lib/ovpmon/backups` (system services) or volume `ovp_backups` at `/app/backups` (containers); see [Backup and Restore](../Profiler_Management/Backup_Restore.md) |
Exact locations per installation method: [Containers: volumes](../Deployment/Containers/Reference.md), [System services: layout](../Deployment/System_Services/Reference.md). Schema changes on update are handled by [database migrations](Database_Migrations.md).
+12
View File
@@ -63,6 +63,18 @@ This includes:
- **Request**: Add `Authorization: Bearer <token>`.
- **Response**: On `401 Unauthorized`, clear token and redirect to `/login`.
## Backups
The Backup and Restore function ([guide](../Profiler_Management/Backup_Restore.md)) makes a package of the application data. What matters for security:
- **What a package holds:** the CA private key and all issued keys (`pki/`), the monitoring database (administrator password hashes, 2FA secrets), the profiler database and the issued client profiles. Whoever can read a package can impersonate the VPN server and its clients. The JWT signing key and the environment file are **not** in it.
- **Encryption:** with a passphrase (at least 8 characters) the package is encrypted with AES-256-GCM in 1 MiB blocks; the key comes from scrypt (N=2^15) with a random salt; the header is authenticated, so truncation and tampering are detected. **Remote destinations (S3, SFTP, FTP) refuse to work without a passphrase.** A local folder works without it and the page warns. The passphrase is never stored in a package; without it an encrypted package cannot be opened.
- **Secrets of the function:** destination secrets (keys, passwords, SFTP private key) and the package passphrase are stored in `ovpmon_backup.db`, encrypted (Fernet) with a key derived (HKDF-SHA256) from the JWT signing key. The API returns `********` instead of a value and never logs one; error messages carry no secrets. If the signing key changes they cannot be read any more and must be entered again. `ovpmon_backup.db` (mode 600) is not part of a package and is never replaced by a restore.
- **SFTP:** the SSH host key is pinned by its SHA-256 fingerprint. The first Test shows the fingerprint and the administrator confirms it; until then nothing is sent to the server (not even the password) and every operation is refused. Unknown keys are never accepted automatically, and a changed key breaks the connection before credentials are sent. **FTP:** explicit TLS and certificate verification are on by default; plain FTP and an unchecked certificate are explicit, warned choices. S3: TLS by default.
- **Local storage:** the backup root (`/var/lib/ovpmon/backups`, containers `/app/backups`) and its folders are mode 700, packages 600, owner `ovpmon`; folder names are validated, links and paths outside the root are refused. In containers the volume `ovp_backups` is not covered by `deploy/docker/backup.sh`.
- **Restore as a trust boundary:** all routes need the JWT (any administrator can start a restore, and a restore replaces the administrator accounts). The package is unpacked into a temporary directory with an allowlist of names (no absolute paths, `..`, links, devices; size and entry limits), checked against the SHA-256 sums of its manifest and migrated there; the running system is touched only after all that and after a safety copy of the current state. The sums are inside the package: they detect damage, not forgery. **Authenticity comes from encryption** (a forged encrypted package fails the GCM check), so an unencrypted package from a place others can write to must not be restored. During a restore requests that change the PKI, profiles, settings or the OpenVPN process return `409`.
- **Limits:** the passphrase and destination secrets are only as safe as the JWT signing key and the file permissions of the server; a stolen package with its passphrase, or a stolen `.env` with `ovpmon_backup.db`, opens the CA key.
## Verification Plan
### Automated Tests