- Profiler: server_files_missing/require_* helpers; 409 for /server/configure, start/restart and POST /profiles when the PKI is not initialized or server files (honouring fqdn_server) are missing; stop stays allowed; DELETE /system/pki returns 409 while OpenVPN runs; GET /system/init/status adds pki_ready, server_ready, missing. - UI: shared usePkiStatus; VPN menu item locked until the PKI is ready, route guard for /config/vpn, Start/Restart and New Client disabled with hints, lock notice on the VPN page. - Test: one pytest (test_pki_guard.py). - Docs: plan and summary in DOCS/Changes, API reference, README, Index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5.3 KiB
5.3 KiB
Logical protection: server setup depends on PKI (plan, 2026-10-04)
Goal: while the PKI is not initialized, the VPN (server) section is closed, and nothing that needs keys can run. The rule is enforced in the backend (the source of truth) and reflected in the UI.
Dependency analysis
What the server needs: ca.crt, server certificate and key (issued/<fqdn_server>.crt, private/<fqdn_server>.key), dh.pem, ta.key, crl.pem (used when crl_verify is on). server.conf.j2 points to all of them.
| Operation | Needs PKI? | Today | Planned |
|---|---|---|---|
POST /server/configure (build and install server.conf) |
yes, all server files | renders paths to files that do not exist and installs the config | 409 with the list of missing files |
POST /server/process/start, restart |
yes (config + keys) | tries to start; may start with a stale server.conf from an earlier PKI |
409 unless the server files exist; stop stays allowed |
POST /profiles (create client) |
yes (CA) | blocked only while an init job runs | 409 unless the PKI is initialized |
DELETE /profiles/{id} (revoke), download |
CA / existing file | no PKI means no profiles (Clear PKI wipes them) | unchanged |
PUT /config/server (save settings), GET /config |
no (only DB values) | open | open at API level (see decision 1) |
PUT /config/pki |
no | open | open; UI warns that changing the server name after init makes the server certificate name stale |
Monitoring (APP_CORE: Analytics, Clients) |
no | open | unchanged |
Hidden dependencies found:
- Server name:
fqdn_serveris used to build the certificate path. If it is edited after init,server.confwould point to a missing certificate. The check must test the actual files, not just "PKI exists". - Clear PKI leaves
/etc/openvpn/server.confand possibly a running OpenVPN that has lost its keys. After Clear the server must not be startable, and Clear should not pull the keys from under a running server (decision 2). - An init job in progress counts as "not ready".
Steps
1. Backend (APP_PROFILER/)
services/pki.py:server_files_missing(db)returns the list of missing server files (honoursfqdn_server;crl.pemrequired only whencrl_verifyis on);require_pki_ready()helpers raising aPkiNotReadyexception with a clear message.routers/server.py(/server/configure),routers/server_process.py(start,restart),routers/profiles.py(POST /profiles): return409 {"detail": "PKI is not initialized. Initialize PKI first."}(or the list of missing files).GET /system/init/statusgets two fields:pki_ready(initialized, no job running) andserver_ready(all server files present) plusmissing(file names). One endpoint feeds the whole UI.- Decision 2:
DELETE /system/pkireturns409 "Stop OpenVPN first"while the OpenVPN process runs.
2. UI (APP_UI/)
composables/usePkiStatus.js: shared reactive status (pki_ready,server_ready,missing,state),refresh(); loaded after login, on every route change and byPKIConfig.vuewhen init finishes or PKI is cleared (the sidebar updates without reload).- Sidebar (
App.vue): the VPN item stays visible but locked (lock icon, muted, tooltip "Initialize PKI first"); click redirects to the PKI page. - Router guard (
router/index.js):/config/vpnismeta.requiresPki; without a ready PKI the navigation is redirected to/config/pkiwith a toast "Initialize PKI before configuring the server". Direct URL entry is covered by the same guard. ServerManagement.vue: Start/Restart disabled with the hint whenserver_readyis false (Stop stays enabled).Certificates.vue: "New Client" disabled with the hint when the PKI is not initialized.VPNConfig.vue: if the status changes while the page is open (PKI cleared in another tab), the page shows the lock notice instead of the form.- Backend
409messages are shown through the existing toast.
3. Tests (minimal)
- One pytest in
APP_PROFILERwith PKI absent:POST /server/configure,POST /server/process/startandPOST /profilesreturn409;GET /system/init/statusshowspki_ready: false,server_ready: false. With the PKI files created (stub directory) the three calls are no longer409for this reason. No UI tests.
4. Verification (containers, stand port 8089)
- Clear PKI: VPN menu locked,
/config/vpnredirects, Start/Restart and New Client disabled; the same calls through the API return409. - Init PKI: after it finishes the menu unlocks without a page reload; configure, start, create client work.
- Edit the server name after init: configure answers
409naming the missing certificate. - Clear PKI with OpenVPN running:
409(decision 2).
5. Documentation
API_Reference.md(409 cases, new status fields), summaryDOCS/Changes/2026-10-04_PKI_Dependency_Guard.md, README row, Index link.
Decisions for the owner
PUT /config/serverstays open at the API level (it touches only DB values and is not a key operation); the page itself is locked in the UI. Alternative: also answer409there.- Block Clear PKI while OpenVPN is running (recommended) or allow it and only warn.
- VPN menu item: visible and locked (recommended, the user sees why) or hidden.
Out of scope
Automatic stop of OpenVPN, certificate expiry checks, locking the Server Process page as a whole.