Scenario 2: install and update as system services (Alpine, Debian, Ubuntu)
- deploy/native: install.sh, update.sh (backup, new code prepared aside, stop services, separate DB migration phase, start, automatic rollback; OpenVPN keeps running), backup.sh, restore.sh, build-ui.sh (Node 20 container), lib.sh OS adapter (OpenRC and systemd). - Root helper reads /etc/ovpmon/helper.conf (service manager, unit, config path), validated strictly; process.py/server.py honour OVPMON_RUNTIME, OVPMON_OPENVPN_SERVICE, OVPMON_OPENVPN_CONFIG. Debian/Ubuntu use openvpn-server@server and /etc/openvpn/server/server.conf. - Service definitions rewritten (systemd, OpenRC). Fixes found by real runs: no seccomp-based options in the profiler unit (they imply NoNewPrivileges and break setuid doas); OpenRC start_pre extends PATH instead of replacing it; helper syntax check works on a read-only tree. - Verified in containers with real init systems (Debian 12, Ubuntu 24.04, Alpine 3.23): install, PKI/server config/OpenVPN start, update on pre-versioned databases, rollback, backup/restore. - Test: test_helper_config.py. Docs: Scenario 2 guide, change summary, README, Index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c49d0b9c2
commit
4abd2044f0
26 files changed
+3326
-255
No files matched your search
@@ -51,7 +51,7 @@ Only the directives the template produces, each with checked arguments: `dev tun
|
||||
- The supervisors stay root by design (they only respawn the service user's process).
|
||||
- Helper checks resolve PKI paths at install time; a service-user-owned PKI directory could later swap a file for a symlink before OpenVPN (root) starts. Impact is limited to OpenVPN failing to parse or reading a key/cert-shaped file; keep the PKI directory owned by `ovpmon` only.
|
||||
- CRL checking (`crl_verify`) works with the unprivileged API, see the section below.
|
||||
- systemd deployments: same idea with `User=ovpmon`, a polkit/sudoers rule for the helper's fixed commands, and the same helper (replace `rc-service` with `systemctl`).
|
||||
- systemd deployments (Debian, Ubuntu): implemented, see the section *Helper configuration and systemd* at the end.
|
||||
- Rollback: restore `/etc/init.d/ovpmon-*` from `/root/app-bak/p2/`, `chown -R root:root` the data directories, restart the services (the helper and doas rules can stay).
|
||||
|
||||
## CRL publishing (`crl_verify`)
|
||||
@@ -75,3 +75,9 @@ Results (throw-away second OpenVPN instance on another port/subnet running as `n
|
||||
| `crl_verify=true` via API + `server/configure` | 200; config contains `crl-verify /etc/openvpn/crl.pem`, accepted by the helper; setting restored afterwards, live `server.conf` byte-identical to the original |
|
||||
| Valid client with active CRL check | connects (`Initialization Sequence Completed`) |
|
||||
| Revoke through the API, then reconnect | server sends `certificate revoked`, client is refused; no CRL read errors |
|
||||
|
||||
## Helper configuration and systemd (2026-10-05)
|
||||
|
||||
The helper reads an optional **`/etc/ovpmon/helper.conf`** (INI, section `[helper]`) with keys `install_dir`, `service_manager` (`openrc` or `systemd`), `service_unit`, `config_path`, `staged_path`. Without the file the built-in values apply, which are exactly the previous hard-coded ones (OpenRC `rc-service openvpn`, `/etc/openvpn/server.conf`, PKI below `/opt/OpenVPN-Monitoring-Simple`): existing hosts behave as before. The helper runs through `doas` with a stripped environment, so it reads its own file: it must be a regular file owned by root and not group/world writable, every value is validated strictly (absolute paths without `..`, `config_path` below `/etc/openvpn/`, `staged_path` below `/var/lib/ovpmon/`, unit name `^[A-Za-z0-9@._-]{1,64}$`, fixed set of managers), unknown keys and invalid values make the helper refuse. With `systemd` it runs `systemctl <action> <unit>` (default unit `openvpn-server@server`, fixed argument list and `PATH`); the `/etc/openvpn/openvpn.conf` link is created only for OpenRC. The `doas` rules file is unchanged (on Debian/Ubuntu the package is `opendoas`, rules in `/etc/doas.conf`).
|
||||
|
||||
`APP_PROFILER/services/process.py` honours `OVPMON_RUNTIME=host|container` (explicit override of the container detection) and, for the root (non-helper) path, `OVPMON_OPENVPN_SERVICE` (default `openvpn`) and `OVPMON_OPENVPN_CONFIG` (default `/etc/openvpn/server.conf`). Installation: [Scenario 2](../Deployment/Scenario2_System_Services.md). Test: `APP_PROFILER/test_helper_config.py`.
|
||||
@@ -0,0 +1,52 @@
|
||||
# Scenario 2: system services, Alpine, Debian, Ubuntu (2026-10-05)
|
||||
|
||||
Phase 3 of [Deployment_Scenarios_PLAN](2026-10-05_Deployment_Scenarios_PLAN.md). Guide: [Scenario 2: system services](../Deployment/Scenario2_System_Services.md).
|
||||
|
||||
## What was added
|
||||
|
||||
| Area | Content |
|
||||
|---|---|
|
||||
| `deploy/native/` | `install.sh`, `update.sh`, `backup.sh`, `restore.sh`, `build-ui.sh`, `lib.sh` (OS adapter for Alpine/OpenRC and Debian/Ubuntu/systemd), nginx template |
|
||||
| Install | Packages, `ovpmon` user, code, two virtualenvs, easy-rsa workspace, `/etc/ovpmon/env` (random secret, admin password shown once), root helper + `doas`, service definitions, OpenVPN prerequisites, nginx with TLS on 8088, health checks. The firewall is **not** touched (hints are printed) |
|
||||
| Update (phases) | preflight, **backup** (databases through the SQLite backup API, configuration, PKI, client configs, code with virtualenvs, system files; verified), source update, new code and virtualenvs prepared aside, **stop services (OpenVPN keeps running)** and swap code, **database migration as its own step** with the new code, UI/helper/doas/service files, start and health checks, **automatic rollback** from any failure after the stop |
|
||||
| UI build | `build-ui.sh` builds the UI in a Node 20 container into a tarball; the host needs no Node |
|
||||
| Debian/Ubuntu support in code | Root helper reads `/etc/ovpmon/helper.conf` (install dir, service manager `openrc|systemd`, unit, config path), validated strictly, defaults equal the old Alpine behaviour; `process.py` and `routers/server.py` use `OVPMON_RUNTIME`, `OVPMON_OPENVPN_SERVICE`, `OVPMON_OPENVPN_CONFIG`. Debian/Ubuntu: unit `openvpn-server@server`, config `/etc/openvpn/server/server.conf` |
|
||||
| Service definitions | `DOCS/General/systemd/*.service`, `DOCS/General/openrc/*` rewritten (user `ovpmon`, environment file, real commands, no `--reload`); `Service_Management.md` updated |
|
||||
| Docs | `DOCS/Deployment/Scenario2_System_Services.md`; `Deployment_Native.md` is a pointer |
|
||||
| Test | `APP_PROFILER/test_helper_config.py` (helper configuration, defaults, rejected values, command lines) |
|
||||
|
||||
## Defects found by the real runs and fixed
|
||||
|
||||
| Defect | Fix |
|
||||
|---|---|
|
||||
| The profiler unit set `ProtectKernelTunables` and `ProtectKernelModules`: systemd implements them with seccomp and then sets NoNewPrivileges implicitly, so the setuid `doas` failed with "not installed setuid" and the root helper never ran | Both options removed from the profiler unit; the reason and the check are in the unit and in the guide |
|
||||
| OpenRC scripts replaced `PATH` in `start_pre`, dropping `/lib/rc/bin`: OpenRC itself failed with `ebegin: not found` | `PATH` is extended, not replaced (all three scripts) |
|
||||
| The helper syntax check used `py_compile`, which fails on a read-only source tree | `compile()` without writing a `.pyc` |
|
||||
|
||||
## Verification (containers with a real init: systemd on Debian 12 and Ubuntu 24.04, OpenRC on Alpine 3.23)
|
||||
|
||||
| Check | Debian 12 | Ubuntu 24.04 | Alpine 3.23 |
|
||||
|---|---|---|---|
|
||||
| `install.sh`, health checks, admin seed removed | ok | ok | ok |
|
||||
| PKI init, server config through the root helper, client, note | ok | ok | ok |
|
||||
| OpenVPN started through the helper | `openvpn-server@server` | `openvpn-server@server` | `openvpn` (OpenRC) |
|
||||
| `update.sh` on databases without a version (real data) | ok, migration phase | ok | ok |
|
||||
| OpenVPN untouched by the update | same PID | active | active |
|
||||
| Rollback after an injected failure (broken new Profiler) | ok, data intact | not run | ok, data intact |
|
||||
| `backup.sh`, change, `restore.sh` | not run | ok | not run |
|
||||
| pytest: helper config test and the earlier tests | passed (all five test files) |||
|
||||
|
||||
Test containers, images and the UI archive were removed afterwards.
|
||||
|
||||
## Notes and limits
|
||||
|
||||
- A container is not a host: no real firewall, cgroup and init details can differ. Run the procedure once on a VM of the target OS before production. Test containers needed explicit help (an init process for OpenRC, writable cgroup); these are test artefacts, not product defects.
|
||||
- Ubuntu 22.04 and other Debian or Alpine versions are not tested (the script warns and needs `--force`).
|
||||
- Not tested: BusyBox `su` paths on hosts other than the test image, an upgrade of an existing real Alpine host through `update.sh` (adoption without a state file is implemented, not exercised), a source tree that is itself the install directory.
|
||||
- Updates need access to the Python package index (fresh virtualenvs).
|
||||
- `openvpn-server@server` shows as failed at boot until a `server.conf` exists.
|
||||
- The version in the logs is `unknown` when `git` is not installed or the source is not a checkout.
|
||||
|
||||
## Existing installations
|
||||
|
||||
An existing Alpine host installed by hand can be adopted: `update.sh` records the state on the first run. Keep a copy of `/etc/doas.d/*` and the helper before the first update; the update replaces files that carry the deploy marker and reports, but does not overwrite, files that differ and have none.
|
||||
Reference in new issue
Block a user