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
@@ -1,14 +1,39 @@
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Monitor API (Flask under gunicorn, APP_CORE).
|
||||
# Install: deploy/native/install.sh renders this template (install dir, if not the default) into
|
||||
# /etc/systemd/system/ovpmon-api.service. Manual use: copy it there, `systemctl daemon-reload`,
|
||||
# `systemctl enable --now ovpmon-api`. Guide: DOCS/Deployment/Scenario2_System_Services.md
|
||||
#
|
||||
# Settings come from /etc/ovpmon/env (root:root 600; systemd reads it as root before the user switch).
|
||||
# The service does not depend on openvpn: the VPN server is started from the UI through the root helper.
|
||||
[Unit]
|
||||
Description=OpenVPN Monitor API
|
||||
Description=OpenVPN Monitor API (gunicorn)
|
||||
After=network.target
|
||||
Wants=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/ovpmon/APP_CORE
|
||||
ExecStart=/opt/ovpmon/venv/bin/python /opt/ovpmon/APP_CORE/openvpn_api_v3.py
|
||||
User=ovpmon
|
||||
Group=ovpmon
|
||||
EnvironmentFile=/etc/ovpmon/env
|
||||
WorkingDirectory=/opt/OpenVPN-Monitoring-Simple/APP_CORE
|
||||
ExecStart=/opt/OpenVPN-Monitoring-Simple/APP_CORE/venv/bin/python -m gunicorn -w 2 -b 127.0.0.1:5001 openvpn_api_v3:app
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
RestartSec=3
|
||||
|
||||
# Hardening: code and virtualenv are root-owned and read-only for the service
|
||||
NoNewPrivileges=yes
|
||||
PrivateTmp=yes
|
||||
ProtectHome=yes
|
||||
ProtectSystem=full
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictRealtime=yes
|
||||
LockPersonality=yes
|
||||
# Write access: databases (and their migration backups) and logs
|
||||
ReadWritePaths=/var/lib/ovpmon /var/log/ovpmon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,14 +1,35 @@
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Monitor gatherer (reads the OpenVPN status log into the monitoring database, APP_CORE).
|
||||
# Install: see ovpmon-api.service. Settings come from /etc/ovpmon/env.
|
||||
# The gatherer starts and keeps running while OpenVPN is down (it waits for the status log).
|
||||
[Unit]
|
||||
Description=OpenVPN Monitor Gatherer
|
||||
After=network.target
|
||||
Wants=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/ovpmon/APP_CORE
|
||||
ExecStart=/opt/ovpmon/venv/bin/python /opt/ovpmon/APP_CORE/openvpn_gatherer_v3.py
|
||||
User=ovpmon
|
||||
Group=ovpmon
|
||||
EnvironmentFile=/etc/ovpmon/env
|
||||
WorkingDirectory=/opt/OpenVPN-Monitoring-Simple/APP_CORE
|
||||
ExecStart=/opt/OpenVPN-Monitoring-Simple/APP_CORE/venv/bin/python openvpn_gatherer_v3.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
RestartSec=3
|
||||
|
||||
# Hardening: code and virtualenv are root-owned and read-only for the service
|
||||
NoNewPrivileges=yes
|
||||
PrivateTmp=yes
|
||||
ProtectHome=yes
|
||||
ProtectSystem=full
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictRealtime=yes
|
||||
LockPersonality=yes
|
||||
# Write access: monitoring database (and its migration backups) and logs
|
||||
ReadWritePaths=/var/lib/ovpmon /var/log/ovpmon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,15 +1,44 @@
|
||||
# managed by ovpmon deploy/native (install.sh / update.sh replace this file only while this marker line is present)
|
||||
#
|
||||
# OpenVPN Profiler API (FastAPI under uvicorn, APP_PROFILER): PKI (easy-rsa), profiles, server settings.
|
||||
# Install: see ovpmon-api.service. Settings come from /etc/ovpmon/env.
|
||||
#
|
||||
# The profiler runs as the unprivileged user ovpmon. Anything that needs root (install server.conf,
|
||||
# publish the CRL, start/stop OpenVPN) goes through `doas /usr/local/sbin/ovpmon-helper <fixed args>`
|
||||
# (rules: /etc/doas.conf, configuration: /etc/ovpmon/helper.conf). Therefore, unlike the other two
|
||||
# services, this unit must NOT set NoNewPrivileges (doas is setuid) nor any seccomp-based option (see below), must not restrict capabilities,
|
||||
# and must leave /etc/openvpn writable: the helper is a child of this process and inherits its
|
||||
# mount namespace.
|
||||
# Started without --reload and without depending on openvpn.
|
||||
[Unit]
|
||||
Description=OpenVPN Profiler API
|
||||
Description=OpenVPN Profiler API (uvicorn)
|
||||
After=network.target
|
||||
Wants=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/ovpmon/APP_PROFILER
|
||||
# Running directly via python as main.py has uvicorn.run
|
||||
ExecStart=/opt/ovpmon/venv/bin/python /opt/ovpmon/APP_PROFILER/main.py
|
||||
User=ovpmon
|
||||
Group=ovpmon
|
||||
EnvironmentFile=/etc/ovpmon/env
|
||||
WorkingDirectory=/opt/OpenVPN-Monitoring-Simple/APP_PROFILER
|
||||
ExecStart=/opt/OpenVPN-Monitoring-Simple/APP_PROFILER/venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 8000
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
RestartSec=3
|
||||
|
||||
# Hardening (moderate, see the note above)
|
||||
PrivateTmp=yes
|
||||
ProtectHome=yes
|
||||
ProtectSystem=full
|
||||
ProtectControlGroups=yes
|
||||
# Deliberately absent: ProtectKernelTunables, ProtectKernelModules, RestrictRealtime, LockPersonality,
|
||||
# SystemCallFilter, RestrictAddressFamilies, MemoryDenyWriteExecute, RestrictNamespaces. They are enforced with a seccomp filter, and for an
|
||||
# unprivileged unit systemd then sets NoNewPrivileges implicitly, which breaks the setuid doas
|
||||
# ("doas: not installed setuid"). Verify with: grep NoNewPrivs /proc/<main pid>/status (must be 0)
|
||||
# Write access: databases and logs; PKI, client profiles and the profiler log inside the install dir;
|
||||
# /etc/openvpn and /var/log/openvpn for the root helper (a leading "-" ignores a missing path)
|
||||
ReadWritePaths=/var/lib/ovpmon /var/log/ovpmon /opt/OpenVPN-Monitoring-Simple/APP_PROFILER/easy-rsa /opt/OpenVPN-Monitoring-Simple/APP_PROFILER/client-config
|
||||
ReadWritePaths=-/opt/OpenVPN-Monitoring-Simple/APP_PROFILER/profiler.log
|
||||
ReadWritePaths=-/etc/openvpn -/var/log/openvpn
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in new issue
Block a user