From 091b9a031a8370465aada6a61c213136034e74e6 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sat, 21 Nov 2026 18:45:10 -0500 Subject: [PATCH] docs: reconcile README, add ARCHITECTURE.md, and record ADR-0001 - README.md: document gated zoom_start_url, payment_processing guard, 64 KiB cap, single-worker Docker note, and doc links - ARCHITECTURE.md: document component responsibilities, SQLite appointment state machine, and trust boundaries - docs/adr/0001-transient-credentials-and-gated-host-url.md: record decision for browser-memory-only credentials and gated host URL --- ARCHITECTURE.md | 42 +++++++++++++++++++ README.md | 19 ++++++--- ...ransient-credentials-and-gated-host-url.md | 13 ++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 ARCHITECTURE.md create mode 100644 docs/adr/0001-transient-credentials-and-gated-host-url.md diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..59fd5a8 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,42 @@ +# Architecture — `zoom-sched-poc` + +Canonical present-state architecture for the **zoom-sched-poc** proof-of-concept (`feat/zoom-sched-poc`). + +## System Topology + +Single-container Flask + Gunicorn (`--workers 1 --threads 4`) application serving both the static 3-screen presentation UI and the JSON REST API behind a reverse proxy (Traefik). + +```mermaid +flowchart LR + Browser["Browser (3-Screen SPA)
Credentials in tab memory"] -->|HTTPS| Proxy["Reverse Proxy (Traefik)"] + Proxy -->|X-Forwarded-*| Flask["Flask App (ProxyFix + Limiter)
MAX_CONTENT_LENGTH: 64 KiB"] + Flask --> DB[("SQLite WAL
/app/data/appointments.db")] + Flask -->|HTTPS Bearer / Basic| Zoom["Zoom REST & OAuth API"] +``` + +## Module Responsibilities + +| Module | Responsibility | +| :--- | :--- | +| [`app/__init__.py`](app/__init__.py) | App factory (`create_app`), `ProxyFix`, `Flask-Limiter` (`memory://`), `_resolve_appointment`, HTTP routes, and error handlers (`413`, `429`, `ZoomAPIError`). | +| [`app/schemas.py`](app/schemas.py) | Pydantic v2 request/response models; `ZoomCredentials.client_secret` uses `SecretStr`. | +| [`app/db.py`](app/db.py) | SQLite WAL initialization (`init_db`) and atomic state transitions (`create_appointment`, `claim_appointment_for_payment`, `release_payment_claim`, `mark_appointment_confirmed`, `delete_appointment`). | +| [`app/zoom.py`](app/zoom.py) | Zoom Server-to-Server OAuth token exchange, paginated slot conflict detection (`max_pages=20`), meeting creation, and meeting deletion. | +| [`app/templates/index.html`](app/templates/index.html) & [`static/style.css`](static/style.css) | 3-screen smooth-scroll presentation UI with `escapeHtml()` and `safeHttpUrl()` (`http:`/`https:` only). | + +## Appointment State Machine + +```mermaid +stateDiagram-v2 + [*] --> payment_pending: "POST /api/appointments (slot free)" + payment_pending --> payment_processing: "POST /pay atomic claim" + payment_processing --> payment_pending: "Zoom create_meeting fails (release)" + payment_processing --> confirmed: "Zoom meeting created" + payment_pending --> [*]: "DELETE (no Zoom call)" + confirmed --> [*]: "DELETE (deletes Zoom meeting)" +``` + +## Trust Boundaries & Rate Limits +- **Zoom credentials (`account_id`, `client_id`, `client_secret`)** are never written to SQLite, cookies, or disk; they are validated per request on `/api/zoom/verify-credentials`, `/api/appointments`, `/pay`, and `DELETE`. +- **Host ZAK link (`zoom_start_url`)** is omitted on unauthenticated `GET /api/appointments/` and returned only by `POST /pay` after credential verification. +- **Brute-force rate limits** (`Flask-Limiter` `memory://` in a single Gunicorn worker): `60/min` default, `10/min` on `/verify-credentials`, `/pay`, and `DELETE`, `15/min` on `POST /api/appointments`, `20/min` on `GET /api/appointments/`. diff --git a/README.md b/README.md index 4e930f0..0e601e6 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,13 @@ Interactive 3-screen presentation proof-of-concept for **El Corazón como Portal ## Features - **3-screen presentation flow** with automatic smooth scrolling: - 1. **Configuración (Servidor):** Validates Zoom Server-to-Server OAuth credentials in memory (`SecretStr` in Pydantic; never persisted to SQLite or disk). - 2. **Solicitar una Cita (Como cliente):** Checks Zoom upcoming meetings for conflicts (`GET /v2/users/me/meetings`), then creates a `payment_pending` appointment in SQLite and returns `session_id` + `payment_id`. - 3. **Buscar Sesión:** Looks up `session_id` or `payment_id`, simulates payment confirmation, provisions the Zoom meeting (`POST /v2/users/me/meetings`), and displays session links idempotently on repeat lookups. -- **Brute-force protection:** `Flask-Limiter` per-IP rate limits (with `ProxyFix` for Traefik) and 40-bit random `ses_`/`pay_` IDs. + 1. **Configuración (Servidor):** Validates Zoom Server-to-Server OAuth credentials (`POST /api/zoom/verify-credentials`) using `SecretStr` in Pydantic; credentials stay strictly in browser tab memory and are never persisted to SQLite or disk. + 2. **Solicitar una Cita (Como cliente):** Checks Zoom upcoming meetings for time overlaps (`GET /v2/users/me/meetings`, paginated up to 20 pages), persists a `payment_pending` appointment (including `duration_minutes`) in SQLite, and returns `session_id` + `payment_id`. + 3. **Buscar Sesión:** Looks up `session_id` or `payment_id` (`GET /api/appointments/`), lets the presenter confirm mock payment (`POST /api/appointments//pay`) to provision the Zoom meeting (`POST /v2/users/me/meetings`), and handles repeat lookups idempotently. +- **Security & concurrency invariants:** + - Unauthenticated `GET /api/appointments/` omits `zoom_start_url` (host ZAK token); `zoom_start_url` is returned only by `POST /pay` after verifying Zoom credentials. + - Atomic `payment_processing` claim/release prevents duplicate Zoom meetings on concurrent `/pay` requests, and `DELETE` returns `409 Conflict` while a payment is in flight. + - `ProxyFix` + `Flask-Limiter` (`memory://`, single Gunicorn worker `--workers 1 --threads 4`), `MAX_CONTENT_LENGTH` (64 KiB), `safeHttpUrl()` link scheme validation, and 40-bit random `ses_`/`pay_` IDs. ## Local Development @@ -19,12 +22,18 @@ uv run flask --app "app:create_app()" run --debug --port 8000 Run tests: ```bash -uv run pytest +uv run pytest -v ``` ## Single-Container Docker Run +The container runs as non-root `appuser` with `--workers 1 --threads 4` (required for authoritative in-memory rate limiting) and a built-in `HEALTHCHECK` on `/health`. + ```bash docker build -t zoom-sched-poc . docker run -p 8000:8000 -v zoom_sched_data:/app/data zoom-sched-poc ``` + +## Documentation +- [Architecture Overview](./ARCHITECTURE.md) +- [ADR-0001: Transient Credentials and Gated Host URL](./docs/adr/0001-transient-credentials-and-gated-host-url.md) diff --git a/docs/adr/0001-transient-credentials-and-gated-host-url.md b/docs/adr/0001-transient-credentials-and-gated-host-url.md new file mode 100644 index 0000000..d0f3726 --- /dev/null +++ b/docs/adr/0001-transient-credentials-and-gated-host-url.md @@ -0,0 +1,13 @@ +# ADR-0001: Transient Zoom Credentials and Gated Host URL + +- **Status:** Accepted +- **Date:** 2026-11-21 +- **Context:** `zoom-sched-poc` is a public-facing proof-of-concept demo allowing Azu to test end-to-end Zoom scheduling with her own Server-to-Server OAuth app without deploying an authentication gateway (Authelia) or persisting third-party secrets on the homelab server. + +## Decision +1. **Transient browser-memory credentials:** Zoom `account_id`, `client_id`, and `client_secret` are entered in Screen 1, held solely in browser tab memory, and transmitted per request over HTTPS (`SecretStr` in Pydantic). They are never stored in SQLite, session cookies, or server environment files. +2. **Gated `zoom_start_url`:** Unauthenticated `GET /api/appointments/` omits `zoom_start_url` (which embeds a Zoom host ZAK token) and returns only client-safe metadata (`zoom_join_url`, `zoom_meeting_id`). `zoom_start_url` is returned only from `POST /api/appointments//pay` after verifying the caller's Zoom credentials via `zoom.get_access_token`. + +## Consequences +- **Positive:** Eliminates server-side secret storage and prevents anyone holding a `session_id`/`payment_id` from hijacking host controls via unauthenticated `GET` lookup. +- **Negative / Trade-off:** Refreshing the browser tab requires re-entering Zoom credentials in Screen 1, and Screen 3 `BUSCAR` lookup alone does not display the host link unless payment is confirmed in the same flow.