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:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-05 20:30:45 +03:00
1 parent f95a0b63e6
commit ad6995bb63
85 files changed
+2805 -1280

No files matched your search

+42 -60
View File
@@ -1,77 +1,59 @@
# OpenVPN Monitor & Profiler
Web suite for OpenVPN servers: real-time traffic monitoring, history/analytics, PKI and client-profile management, one UI.
Web suite for OpenVPN servers: real-time traffic monitoring, history and analytics, PKI and client-profile management, one UI.
| Component | Dir | Stack | Default port |
| Component | Dir | Stack | Port |
|---|---|---|---|
| UI | `APP_UI/` | Vue 3 + Vite, served by Nginx | 80 (Docker) / 8088 (native, TLS) |
| Monitoring API | `APP_CORE/` | Flask (gunicorn) | 5001 (internal) |
| Data gatherer | `APP_CORE/` | Python daemon | - |
| Profiler API | `APP_PROFILER/` | FastAPI (uvicorn) | 8000 (internal) |
| UI | `APP_UI/` | Vue 3 + Vite, served by Nginx | 80 (containers) / 8088 (system services, HTTPS) |
| Monitoring API + data gatherer | `APP_CORE/` | Flask (gunicorn), Python daemon | 5001, internal |
| Profiler API | `APP_PROFILER/` | FastAPI (uvicorn) | 8000, internal |
Nginx is the only public entry point: `/` UI, `/api/` Monitoring API, `/profiles-api/` Profiler API.
Nginx is the only public entry point. More: [Overview](DOCS/General/Overview.md).
## Quick start
## Get it running
- **Containers:** `deploy/docker/install.sh --variant a|b`, open `http://<host>`. Details: [Scenario 1: containers](DOCS/Deployment/Scenario1_Containers.md) (update, backup, rollback included).
- **System services** (Alpine/OpenRC, Debian and Ubuntu/systemd, no containers): `deploy/native/install.sh --prefix DIR` (the install directory is always asked for; the checkout is only the source; the web UI is installed from `deploy/ui-dist` of the repository); details, update and rollback: [Scenario 2: system services](DOCS/Deployment/Scenario2_System_Services.md).
- **NAT, MSS and TTL for the VPN clients** (nftables, optional): `deploy/native/firewall.sh [--dry-run]` reads the interfaces of the server and sets masquerade, TCP MSS clamping and TTL for traffic from the VPN network to all other networks; see [Firewall, NAT and forwarding](DOCS/Deployment/Scenario2_System_Services.md#firewall-nat-and-forwarding).
1. **Pick a method** ([comparison](DOCS/Deployment/README.md)), clone the repository on the host and run one command as root:
After the first start: sign in, open **PKI Configuration** → **Initialize PKI**, generate the server config, start OpenVPN, create profiles.
| Method | Command | Guide |
|---|---|---|
| Containers (Docker) | `deploy/docker/install.sh --variant a` (`b` = one container per component) | [Containers](DOCS/Deployment/Containers/README.md) |
| System services (Alpine, Debian, Ubuntu) | `deploy/native/install.sh --prefix /opt/OpenVPN-Monitoring-Simple` | [System services](DOCS/Deployment/System_Services/README.md) |
## First login and credentials
Not sure? Docker on the host: containers, variant A. Otherwise: system services.
2. The script prints the URL and the **administrator password once** (no default account exists).
3. Follow [First steps](DOCS/Deployment/First_Steps.md): secure the account, initialize the PKI, configure and start the VPN server, create the first client.
No default user is created. Seed the initial admin with `OVPMON_INITIAL_ADMIN_USER` / `OVPMON_INITIAL_ADMIN_PASSWORD` on first start (empty `users` table only), then remove them. Change the username and password and enable 2FA in **Account**.
## Security defaults
- No built-in account; the username can be changed in **Account** (API `POST /api/auth/change-username`).
- All API routes require a JWT; 2FA-pending tokens are accepted only by `/api/auth/verify-2fa`.
- Server/PKI settings are validated before they reach `server.conf` (ports, networks, routes, DNS, host names, script paths, DN fields); scripts run only from `/etc/openvpn/scripts/`.
- Native deployments: APIs run as user `ovpmon`; a root helper installs the validated `server.conf`, publishes the CRL (`crl_verify`) and controls `openvpn` through `doas` (fixed commands).
- CORS is same-origin only unless `OVPMON_CORS_ORIGINS` is set; TLS on the panel port; brute-force limits on login (Nginx + app, fail2ban jail in the deployment guide).
## Configuration
`config.ini` per component; overridden by `OVPMON_{SECTION}_{KEY}` environment variables.
| Variable | Purpose |
|---|---|
| `OVPMON_API_SECRET_KEY` | JWT secret shared by both APIs (**must be random**) |
| `OVPMON_INITIAL_ADMIN_USER` / `_PASSWORD` | One-time admin seed |
| `OVPMON_CORS_ORIGINS` | Extra allowed CORS origins, comma-separated (empty = same-origin only) |
| `OVPMON_OPENVPN_MONITOR_DB_PATH` | Monitoring DB |
| `OVPMON_PROFILER_DB_PATH` | Profiler DB |
| `OVPMON_OPENVPN_MONITOR_LOG_PATH` | `openvpn-status.log` path |
| `OVPMON_LOGGING_LEVEL` | `INFO` / `DEBUG` |
Optional: NAT, MSS clamping and TTL for the VPN clients on system-service hosts: `deploy/native/firewall.sh --dry-run` ([Firewall](DOCS/Deployment/System_Services/Firewall.md)).
## Documentation
- Index: [DOCS/General/Index.md](DOCS/General/Index.md)
- Deployment: [Docker](DOCS/General/Deployment_Docker.md) · [System services](DOCS/General/Deployment_Native.md) · [Nginx](DOCS/General/Nginx_Configuration.md) · [Service management](DOCS/General/Service_Management.md)
- Deployment records (state, results, reboot test, plans): [DOCS/Operations](DOCS/Operations/README.md)
- Security model: [Security Architecture](DOCS/General/Security_Architecture.md) · root helper and doas rules: [`DOCS/General/privilege-separation/`](DOCS/General/privilege-separation/)
- APIs: [Monitoring](DOCS/Core_Monitoring/API_Reference.md) · [Profiler](DOCS/Profiler_Management/API_Reference.md)
| Level | Where |
|---|---|
| General information | [Overview](DOCS/General/Overview.md) · [Configuration](DOCS/General/Configuration.md) · [Security architecture](DOCS/General/Security_Architecture.md) · [Database migrations](DOCS/General/Database_Migrations.md) |
| Installation methods | [Choose a method](DOCS/Deployment/README.md) · [First steps](DOCS/Deployment/First_Steps.md) |
| Details per method | [Containers](DOCS/Deployment/Containers/README.md) (operations, reference, troubleshooting) · [System services](DOCS/Deployment/System_Services/README.md) (operations, reference, web UI, firewall, nginx, troubleshooting) |
| APIs | [Monitoring](DOCS/Core_Monitoring/API_Reference.md) · [Profiler](DOCS/Profiler_Management/API_Reference.md) · [UI](DOCS/UI/Architecture.md) |
| Changes | [Changes and results](DOCS/Changes/README.md) |
| Code review | [DOCS/code_review/](DOCS/code_review/2026-10-05_1607Z_Codebase_Analysis.md) (state of the code, risks, recommendations; time-stamped) |
## Changes and results
The full map: [DOCS/README.md](DOCS/README.md).
| Date | Change | Document |
|---|---|---|
| 2026-09-30 | Security hardening: path traversal, 2FA token bypass, CORS, log leak, HTTPS, SSH, fail2ban | [Security hardening](DOCS/Changes/2026-09-30_Security_Hardening.md) |
| 2026-09-30 | Admin username change (API + UI), no built-in default admin | [Admin username change](DOCS/Changes/2026-09-30_Admin_Username_Change.md) |
| 2026-09-30 | Validation of server/PKI settings (config injection into the root-written OpenVPN config) | [Settings validation](DOCS/Changes/2026-09-30_Settings_Validation.md) |
| 2026-09-30 | API services run as an unprivileged user; root helper validates and installs the OpenVPN config, publishes the CRL | [Privilege separation](DOCS/Changes/2026-09-30_Privilege_Separation.md) (includes CRL publishing for `crl_verify`) |
| 2026-09-30 | Route OpenVPN clients through a Hysteria2 tunnel to an exit node | [Egress via Hysteria2](DOCS/Changes/2026-09-30_Egress_via_Hysteria2.md) |
| 2026-10-04 | Certificates page: clickable rows, profile details modal with a saved note (`PUT /profiles/{id}/note`) | [Profile notes](DOCS/Changes/2026-10-04_Profile_Notes.md) (includes the compact modal and the note tooltip on the client name) |
| 2026-10-04 | PKI initialization runs in the background: status endpoint, progress on the PKI page, protection against a second start | [Async PKI init](DOCS/Changes/2026-10-04_Async_PKI_Init.md) |
| 2026-10-04 | Toast notifications moved to the bottom-right corner, shared component, light/dark themes | [Toast notifications](DOCS/Changes/2026-10-04_Toast_Notifications.md) |
| 2026-10-04 | Server setup is closed until the PKI is initialized (VPN menu lock, 409 for configure/start/create client, Clear PKI blocked while OpenVPN runs) | [PKI dependency guard](DOCS/Changes/2026-10-04_PKI_Dependency_Guard.md) |
| 2026-10-05 | Database migrations with backup, integrity checks and downgrade protection; standalone `migrate.py` (phase 1 of install/update scenarios) | [Database migrations](DOCS/Changes/2026-10-05_DB_Migrations.md) |
| 2026-10-05 | Scenario 1: container install and update, variant A (one container) and B (per component); backup, restore, automatic rollback | [Scenario 1: containers](DOCS/Deployment/Scenario1_Containers.md) · [change](DOCS/Changes/2026-10-05_Scenario1_Containers.md) |
| 2026-10-05 | Scenario 2: install and update as system services on Alpine, Debian, Ubuntu; helper config for systemd; backup, restore, automatic rollback | [Scenario 2: system services](DOCS/Deployment/Scenario2_System_Services.md) · [change](DOCS/Changes/2026-10-05_Scenario2_System_Services.md) |
| 2026-10-05 | nftables script for system-service installs: masquerade, TCP MSS clamping (path MTU) and TTL for traffic from the VPN network to all other networks; boot service | [Firewall, NAT and forwarding](DOCS/Deployment/Scenario2_System_Services.md#firewall-nat-and-forwarding) · [plan](DOCS/Changes/2026-10-05_NFT_Firewall_PLAN.md) · [change](DOCS/Changes/2026-10-05_NFT_Firewall.md) |
## Security defaults
## Notes
- No built-in account; the first administrator is seeded once at install time. Change the username and password and enable 2FA in **Account Settings**.
- No default signing key: both APIs refuse to start without a random `OVPMON_API_SECRET_KEY` of at least 32 characters (installers generate one).
- All API routes require a JWT; server and PKI settings are validated before they reach `server.conf`.
- System-service installs: the APIs run as the unprivileged user `ovpmon`; a root helper (`doas`, fixed commands) installs the validated `server.conf` and controls OpenVPN.
- CORS is same-origin only unless `OVPMON_CORS_ORIGINS` is set; brute-force limits on login.
- Native deployments run the APIs as user `ovpmon`; OpenVPN config install and service control go through a root helper (`doas`, fixed commands): see [Privilege separation](DOCS/Changes/2026-09-30_Privilege_Separation.md).
- Keep `easy-rsa/`, `client-config/`, databases and `*.env` out of git: they contain private keys and secrets.
Keep `easy-rsa/`, `client-config/`, databases and `*.env` out of git: they contain private keys and secrets.
## Repository layout
| Path | Content |
|---|---|
| `APP_UI/`, `APP_CORE/`, `APP_PROFILER/` | the three components (each has its own short README for development) |
| `deploy/docker/`, `deploy/allinone/`, `docker-compose*.yml` | container installation |
| `deploy/native/`, `deploy/ui-dist/` | system-service installation and the ready web UI build |
| `DOCS/` | documentation |
| `DEPLOYMENTS/` | records of one concrete site (not product documentation) |