Skip to content

Cross-Cutting Concerns & Shared Infrastructure

3.1 Authentication, Sessions, MFA & RBAC

SurfaceAuth MechanismSession / Token PolicyRBAC / MFAVerified Gaps
Device -> Public IngressMutual 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/CRLSingle device identity per CNcloud/api/telemetry_ingress.py:verify_forwarded_client_certificate does not check cert expiry dates
mTLS Gateway -> Supabase EdgeHMAC-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-serviceNone
Edge / Gateway -> FastAPI /edge-*Shared token header X-Planovi-Edge-Token (PLANOVI_EDGE_SHARED_TOKEN >= 32 chars, constant-time)StatelessService-to-servicemtls_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_proxyStatelessCN allowlistFails 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)None35 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-TokenStatelessShared tokenUses 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: BearerMax 4 IP-bound sessions, 1800 s sliding TTL, 5-strike -> 900 s per-IP lockout, mandatory first-login password changeSingle 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/or company_id + building_id (shared Supabase Planovi multi-tenant schema, added in migration 018). StorageStream authorization (telemetry_ingestion.py, event_ingestion.py, storage_transfer.py) enforces both stream.active_converter_id == converter.id AND matching owner (company_id when either side has one, else facility_id).
  • Row-Level Security (RLS): Zero RLS policies (ENABLE ROW LEVEL SECURITY / CREATE POLICY) exist in cloud/migrations/000..019. Isolation is enforced purely by FastAPI query parameters (company_id filter on GET /api/v1/converters) and stream ownership checks; the shared Supabase DB relies on SECURITY DEFINER on next_edge_converter_serial, fn_sync_edge_converter_to_converters, and ingest_telemetry_record with SET search_path = public.
  • Warehouse / Unassigned Converters: Converters with company_id IS NULL are supported in both fn_sync_edge_converter_to_converters (never synthesizes placeholder public.counters) and ingest_telemetry_record (returns PROCESSED without writing raw_telemetry/counters).

3.3 Branding Rules & i18n

  • 100% Zone 1 (Native Planovi Platform & Hardware UI): Per BRANDING_GUIDE.md and AGENTS.md, this repo has no Zone 2 white-label layer.
    • Dark chrome: #09090B (main), #121215 (secondary), #18181B (elevated), #27272A (border), #F4F4F5 / #A1A1AA text.
    • Light canvas (admin/): #FAFAFA (main), #F4F4F5 (secondary), #FFFFFF (elevated), #E4E4E7 (border), #09090B / #52525B text.
    • Accent: #32CA42 (#28B437 hover) with mandatory #09090B foreground on solid buttons/badges (9.4:1 WCAG AAA); #22A830 for green text/links on light backgrounds.
    • Official SVG/PNG assets in assets/brand/ & admin/assets/brand/, inline planovi-logo-embedded.svg in src/ux/index.html, ANSI banner in src/common/planovi_brand.h.
  • i18n Coverage:
    • admin/: PL (default) + EN (473 paired keys in admin/lib/services/i18n_service.dart, persisted in localStorage['planovi_language_preference']). Has 5 missing keys (chart_legend_pv, chart_legend_cons, th_time, modal_close, no_components_found), 76 unused 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 in watchdog_hw->scratch[0..7]. Heap guards prevent allocator crashes in both web_server.c (2048 B reserve) and mbedtls_platform_freertos.c (4096 B reserve). HTTPS delivery uses stepped backoff (5s..3600s ±10%), 30 s socket timeout, Tier 2/3 Wi-Fi self-healing, 60 s Wi-Fi credential rollback, and 10 min cloud host rollback.
  • Cloud: FastAPI overrides RequestValidationError (422) to strip NaN/Inf values (cloud/app.py:126-138); _process_single_record maps ValidationError -> 422, ValueError -> 403, SQLAlchemyError -> 503 with explicit rollback. mtls_gateway and Supabase Edge apply 20 s upstream timeouts. AlertDispatcher retries Google Chat posts (10 s timeout) on (5, 15, 60, 300, 900, 3600) s backoff. MqttTelemetryBridge retries DB errors on 1 s..30 s exponential backoff before manual ack().
  • Rate Limiting & Maintenance Gates: No HTTP rate limiter exists in cloud/ (only per-IP 5-attempt login lockout on the RP2350 local web server). Converter MAINTENANCE status prevents automatic ONLINE/OFFLINE overwrite by telemetry/events/alert reconciliation.