Cross-Cutting Concerns & Shared Infrastructure
3.1 Authentication, Sessions, MFA & RBAC
| Surface | Auth Mechanism | Session / Token Policy | RBAC / MFA | Verified Gaps |
|---|---|---|---|---|
| Device -> Public Ingress | Mutual TLS 1.2/1.3 (leaf X.509 signed by Device CA, EKU=CLIENT_AUTH, ca=False, CN == X-Device-Serial) | Stateless per TLS handshake; mtls_gateway validates cert validity dates (not_valid_before/after), Nginx enforces CA/CRL | Single device identity per CN | cloud/api/telemetry_ingress.py:verify_forwarded_client_certificate does not check cert expiry dates |
| mTLS Gateway -> Supabase Edge | HMAC-SHA256 (PLANOVI_GATEWAY_HMAC_SECRET >= 32 chars) over ts\ncn\nserial\ntype\nsha256(body) | ±300 s replay window (verify_jwt = false in supabase/config.toml) | Service-to-service | None |
Edge / Gateway -> FastAPI /edge-* | Shared token header X-Planovi-Edge-Token (PLANOVI_EDGE_SHARED_TOKEN >= 32 chars, constant-time) | Stateless | Service-to-service | mtls_gateway.py:40 has a hardcoded dev fallback string; verify_edge_client does not check require_trusted_proxy |
Admin Policy /api/v1/admin/* | Mutual TLS + PLANOVI_ADMIN_MTLS_CNS allowlist + require_trusted_proxy | Stateless | CN allowlist | Fails closed (503) if PLANOVI_ADMIN_MTLS_CNS or MQTT bridge unset |
FastAPI Fleet API (converters.py, settings.py, activity_logs.py, firmware.py) & Flutter Admin (admin/) | NONE in code (relies strictly on external Nginx IP allowlist deploy/nginx.admin.planovi.conf) | None (AuthService in admin/ is unused mock; require_mfa in settings.py is hardcoded False) | None | 35 management routes (incl. Device CA signing & firmware upload) unauthenticated at app layer; CORS defaults to ["*"] + allow_credentials=True |
VPS Health Webhook (/api/v1/infra/report-status) | X-Status-Auth-Token | Stateless | Shared token | Uses non-constant-time != and hardcoded fallback token in both status.py and check-health.sh |
Converter Local Web UI (src/web/) | Async PBKDF2-HMAC-SHA-256 (100,000 iters, salt = OTP serial) -> 64-hex Authorization: Bearer | Max 4 IP-bound sessions, 1800 s sliding TTL, 5-strike -> 900 s per-IP lockout, mandatory first-login password change | Single effective role (AUTH_ROLE_ADMIN granted to all logins) | POST /api/auth/account runs PBKDF2 synchronously in tcpip_thread; POST /api/auth/password-status lacks IP binding & TTL |
3.2 Multi-Tenancy & Data Isolation
- Scoping Model: Converters belong to
facility_id(legacy converter DB) and/orcompany_id+building_id(shared Supabase Planovi multi-tenant schema, added in migration018).StorageStreamauthorization (telemetry_ingestion.py,event_ingestion.py,storage_transfer.py) enforces bothstream.active_converter_id == converter.idAND matching owner (company_idwhen either side has one, elsefacility_id). - Row-Level Security (RLS): Zero RLS policies (
ENABLE ROW LEVEL SECURITY/CREATE POLICY) exist incloud/migrations/000..019. Isolation is enforced purely by FastAPI query parameters (company_idfilter onGET /api/v1/converters) and stream ownership checks; the shared Supabase DB relies onSECURITY DEFINERonnext_edge_converter_serial,fn_sync_edge_converter_to_converters, andingest_telemetry_recordwithSET search_path = public. - Warehouse / Unassigned Converters: Converters with
company_id IS NULLare supported in bothfn_sync_edge_converter_to_converters(never synthesizes placeholderpublic.counters) andingest_telemetry_record(returnsPROCESSEDwithout writingraw_telemetry/counters).
3.3 Branding Rules & i18n
- 100% Zone 1 (Native Planovi Platform & Hardware UI): Per
BRANDING_GUIDE.mdandAGENTS.md, this repo has no Zone 2 white-label layer.- Dark chrome:
#09090B(main),#121215(secondary),#18181B(elevated),#27272A(border),#F4F4F5/#A1A1AAtext. - Light canvas (
admin/):#FAFAFA(main),#F4F4F5(secondary),#FFFFFF(elevated),#E4E4E7(border),#09090B/#52525Btext. - Accent:
#32CA42(#28B437hover) with mandatory#09090Bforeground on solid buttons/badges (9.4:1 WCAG AAA);#22A830for green text/links on light backgrounds. - Official SVG/PNG assets in
assets/brand/&admin/assets/brand/, inlineplanovi-logo-embedded.svginsrc/ux/index.html, ANSI banner insrc/common/planovi_brand.h.
- Dark chrome:
- i18n Coverage:
admin/: PL (default) + EN (473paired keys inadmin/lib/services/i18n_service.dart, persisted inlocalStorage['planovi_language_preference']). Has 5 missing keys (chart_legend_pv,chart_legend_cons,th_time,modal_close,no_components_found),76unused keys, and scattered untranslated Polish/English strings.src/ux/index.html: Polish only (<html lang="pl">), no English toggle.cloud/: Error details in English; device event descriptions, command status messages, and Supabase admin notifications in Polish.
3.4 Global Error Handling, Logging, Retries, Timeouts & Security Guards
- Firmware: FreeRTOS stack-overflow (
configCHECK_FOR_STACK_OVERFLOW=2), malloc-failed hook, HardFault handler, and 15 s hardware watchdog supervisor capture crash metadata inwatchdog_hw->scratch[0..7]. Heap guards prevent allocator crashes in bothweb_server.c(2048 Breserve) andmbedtls_platform_freertos.c(4096 Breserve). HTTPS delivery uses stepped backoff (5s..3600s ±10%),30 ssocket timeout, Tier 2/3 Wi-Fi self-healing,60 sWi-Fi credential rollback, and10 mincloud host rollback. - Cloud: FastAPI overrides
RequestValidationError(422) to stripNaN/Infvalues (cloud/app.py:126-138);_process_single_recordmapsValidationError -> 422,ValueError -> 403,SQLAlchemyError -> 503with explicit rollback.mtls_gatewayand Supabase Edge apply20 supstream timeouts.AlertDispatcherretries Google Chat posts (10 stimeout) on(5, 15, 60, 300, 900, 3600)s backoff.MqttTelemetryBridgeretries DB errors on1 s..30 sexponential backoff before manualack(). - Rate Limiting & Maintenance Gates: No HTTP rate limiter exists in
cloud/(only per-IP 5-attempt login lockout on the RP2350 local web server). ConverterMAINTENANCEstatus prevents automaticONLINE/OFFLINEoverwrite by telemetry/events/alert reconciliation.