Files
OpenVPN-Monitoring-Simple/DOCS/Changes/2026-10-04_Async_PKI_Init.md
T

35 lines
2.8 KiB
Markdown
Raw Normal View History

# Async PKI initialization (2026-10-04)
Goal: `Init PKI` can take minutes (DH parameters); it no longer holds an HTTP request. Plan: [Async_PKI_Init_PLAN](2026-10-04_Async_PKI_Init_PLAN.md).
## Changes
| Area | Change |
|---|---|
| API (`APP_PROFILER/routers/system.py`) | `POST /system/init` returns `202 {"state":"running"}` and runs the init in a background thread; `409` if a job is running or the PKI is initialized. New `GET /system/init/status` (`state`, `step`, `initialized`, `started_at`, `finished_at`, `error`). `DELETE /system/pki` and `POST /profiles` return `409` while a job is running |
| Service (`APP_PROFILER/services/pki.py`) | In-memory job state under a lock; the thread uses its own DB session; steps `init-pki`, `ca`, `server-cert`, `dh`, `ta-key`, `crl`; EasyRSA error text is stored in `error` |
| Interrupted runs | A marker file `<easy-rsa>/.pki-init-in-progress` (outside the PKI directory) exists while a job runs and is removed on success. A leftover marker (restart, crash, failed job) means the PKI is incomplete: it is wiped and rebuilt on the next Init. A PKI without the marker and with `ca.crt` counts as initialized and is **never** wiped automatically |
| UI (`APP_UI/src/views/PKIConfig.vue`) | State comes from the server on page load; spinner and step text while running, polling every 3 s; Init, Clear and Save disabled while running; Init disabled with a hint once initialized; success or error message at the end; a `409` on start attaches to the running job; the button locks on click |
| Docs | `DOCS/Profiler_Management/API_Reference.md` |
| Test | `APP_PROFILER/test_async_pki_init.py` (one test with EasyRSA stubs): 202, second start 409, status `running`, Clear 409, then `done` and a further start 409 |
## Verification (containers)
| Check | Result |
|---|---|
| `pytest test_async_pki_init.py` and `test_profile_note.py` in `python:3.12-alpine` | 2 passed |
| Existing complete PKI | status `initialized: true`, Init is a no-op |
| Clear, then Init | `202`, second start `409`, steps `init-pki` → `dh` → `done` (3 s and 54 s in two runs) |
| Partial PKI with the marker (simulated interrupted run) | wiped, rebuilt, marker removed, `initialized: true` |
| Create a client during the run / after it | `409` / `200` |
| UI bundle | `app-ui` builds and contains the status polling; the page behaviour is checked manually |
## Notes
- The Profiler must run as a single process (in-memory job state): `python main.py` in Docker, one `uvicorn` in the native unit. Do not add workers.
- Initialization is not cancelled by a page reload; the page reattaches to the running job.
- Not implemented: cancelling a run, progress percentage, async Clear PKI.
## Existing installations
No manual steps. Rebuild and restart the Profiler (native: `ovpmon-profiler`; Docker: `app-profiler`, `app-ui`). An already initialized PKI is detected as before.