9. Public Ingress Deployment, Local Staging, Diagnostics, Mechanical, QA Tooling & Docs/Mockups
Repository:
Converters (planovi-converter)• Rule Prefix:BR-OPS• Documented Rules: 5 • Open[TEAM_WHY_NEEDED]Questions: 4
1. Business Purpose & Actors
Provides hardened production ingress containers (nginx:1.29-alpine + mtls-gateway), a deterministic local multi-container staging environment (PostgreSQL 17, Mosquitto 2, FastAPI, Nginx mTLS, transactional migration runner), VPS health monitoring and SSH allowlist safety tooling, 12 standalone RP2350 hardware/lab bench firmware targets, an OpenSCAD 35 mm DIN-rail enclosure model, repository integrity/secret/hardware-soak test suites, and the active Astro Starlight local documentation portal.
- Actors: DevOps / Release Engineers (
deploy/,scripts/deploy_public_ingress.ps1,deploy/update_allowed_ip.sh), Hardware QA / Lab Engineers (diagnostics/,staging/,tools/*regression*,tools/run_cloud_e2e.py,tools/run_staging_mtls_matrix.py), Mechanical Engineers (mechanical/enclosure_din.scad), Technical Writers (docs/,tools/build_*_document.py).
2. All Features & End-to-End Flows
- Public mTLS Ingress Stack (
deploy/docker-compose.public-ingress.yml,deploy/Dockerfile.mtls-gateway,deploy/nginx.api.planovi.conf,scripts/deploy_public_ingress.ps1):- Deployment:
scripts/deploy_public_ingress.ps1validates secret lengths (>= 32chars, HMAC secret != Edge token), URL shapes, PEM files, andSUPABASE_PROJECT_REF, optionally deploys Supabase Edge Functioningest-telemetry, runsdocker compose up -d --build, and verifies fail-closed mTLS viatools/validate_public_ingress.py(passes ONLY if unauthenticated request fails TLS handshake or returns Nginx400/495/496"certificate"). - Hardening: Both
mtls-gateway(UID10001:10001) andnginxrunread_only: true,no-new-privileges:true,cap_drop: [ALL], tmpfs mounts, andmtls-gatewayhealthcheck (GET /healthzevery30 s). Nginx listens withproxy_protocol,ssl_verify_client on,client_max_body_size 4k, strips client-suppliedX-Planovi-Client-CN/X-Planovi-Gateway-*, and returns404for all paths other thanPOST /functions/v1/ingest-telemetry.
- Deployment:
- Admin Reverse Proxy & VPS Operations (
deploy/nginx.admin.planovi.conf,deploy/check-health.sh,deploy/update_allowed_ip.sh):nginx.admin.planovi.confserves the Flutter SPA from/var/www/planovi-converter-adminand proxies/api/v1/->127.0.0.1:8000/api/v1/behind IP allowlist (allow <ip>; deny all;).check-health.sh(cron*/5 * * * *) inspects 6 Docker containers and POSTs status to/api/v1/infra/report-status.update_allowed_ip.shrestricts UFW port22/tcpwith an automatic300 s(ROLLBACK_TIMEOUT) background rollback unless--confirmis executed.
- Local Staging Stack & Migration Runner (
staging/,tools/setup_local_staging.py,scripts/staging.ps1):setup_local_staging.pygenerates a local ECDSA P-256 CA (730 d), server cert with LAN IP SAN, admin/ingress/device certs (LAB-0001,LAB-0002), CRL, C headers (planovi_ca_pem.h,staging_lab_credentials*.h), and.staging-runtime/staging.env.staging/migrate_and_seed.pyacquires PostgreSQL advisory lock0x41534C414E4449("ASLANDI"), verifies SHA-256 checksums of all previously applied migrations inplanovi_schema_migrations, enforces exactly oneBEGIN;..COMMIT;per SQL file, applies pending migrations atomically, seedsPLANOVI-STAGINGfacility +LAB-0001/LAB-0002converters, and deactivates legacy fictitious meter'LEM-60 staging'.staging/nginx.conf(:8443,ssl_verify_client on) rewrites/functions/v1/ingest-telemetrydirectly tohttp://backend:8000/api/v1/telemetry/recordto exercise the device HTTPS contract locally without Supabase.
- Standalone Hardware Diagnostics (
diagnostics/— 12EXCLUDE_FROM_ALLtargets):- Non-destructive bench probes (
hardware_diag,lem60_probe,rtc_sd_probe,wifi_dhcp_probe), 50-slave RS-485 simulator (modbus_50_slave_sim), FAT CSV soak loggers (lem60_rtc_sd_logger,lem60_rtc_sd_soak), destructive one-shot SD crypto test (sd_crypto_prepare_test, requiresPLANOVI_SD_CRYPTO_ERASE_AUTHORIZED=1), and reversible lab firmware targets (installer_wifi_lab,otp_lab_mock,otp_bootloader_lab_mock,installer_lab_identity.h).
- Non-destructive bench probes (
- Mechanical, QA Validators, Regression Suites, Docs & Mockups:
mechanical/enclosure_din.scad: Preliminary parametric54 × 90 × 37 mm35 mm DIN-rail enclosure (part = "base"|"lid"|"assembly", 4× M3 heat-set bosses, 2× PG7 glands, antenna clearanceboard_y = 17, external metal DIN clip required).tools/validate_repository.py(UTF-8/conflict check, CMake source parity, 4 MiB flash contiguity, OTP row parity betweenotp_keys.candprovision_otp.py, contiguous migration numbering) &tools/scan_repository_secrets.py(redacted SHA-256[:12] secret scanner across worktree, binaries,.zip/.docx, and git history).- Test suites: 10 compiled host Unity C unit tests (
tests/CMakeLists.txt;test_fifo_buffer.cexcluded pending block mock), 26 Python contract/policy tests (tests/test_*.py), 19 Cloud pytest suites (cloud/tests/), 9-case mTLS negative matrix (tools/run_staging_mtls_matrix.py), and disposable full-stack E2E (tools/run_cloud_e2e.py). docs/: ACTIVE Astro^4.16.1+ Starlight^0.28.2documentation portal (docs/src/content/docs/*, test casesT00–T07, dated hardware test results, DOCX/manual pipelinetools/build_installation_manual.py/build_project_document.py).mockups/planovi-converters/: LEGACY / REFERENCE ONLY — static offline HTML/CSS/JS UI prototype plus an unusedsite-creator-vinext-starter(next/react/vinext/drizzle-orm) scaffold with zero backend or hardware integration.
3. Hard Business Rules, Validations, Calculations & Edge Cases
BR-OPS-01(Fail-Closed Public Ingress Verification):tools/validate_public_ingress.pypasses only if an unauthenticated HTTPS POST without a client cert fails TLS handshake or receives Nginx400/495/496mentioning"certificate"and"nginx".BR-OPS-02(Migration Immutability & Transactionality):staging/migrate_and_seed.pylocks via advisory lock0x41534C414E4449, rejects any applied migration whose file disappeared or whose SHA-256 changed inplanovi_schema_migrations, and rejects any SQL file lacking a single outerBEGIN;..COMMIT;block. (Note: migration019_fix_converter_sync_and_telemetry_rpc.sqlintentionally placesALTER TYPE public.meter_model ADD VALUE IF NOT EXISTS 'chint_dtsu666'outsideBEGIN;..COMMIT;because PostgreSQL forbids using a newly added enum value in the same transaction — verify runner compatibility before running019throughstaging/migrate_and_seed.py!)BR-OPS-03(Lab/Diagnostic Compile Isolation): All 12 files indiagnostics/areEXCLUDE_FROM_ALLtargets inCMakeLists.txt; OTP lab mocks fail compile without explicitPLANOVI_INSTALLER_LABorPLANOVI_BOOTLOADER_QUALIFICATION_LAB; destructive SD erase test requiresPLANOVI_SD_CRYPTO_ERASE_AUTHORIZED=1.BR-OPS-04(OTP & Flash Single-Source-of-Truth Gate):tools/validate_repository.pyparses bothsrc/security/otp_keys.candtools/provision_otp.pyto enforce exact OTP row/size/overlap parity and checkssrc/bootloader/flash_layout.hsums to0x00400000.BR-OPS-05(SSH Lockout Safety Rollback):deploy/update_allowed_ip.shspawns a300 sbackground rollback timer restoring/tmp/ssh_ip_previousUFW rules unless--confirmwrites/tmp/ssh_ip_confirmed.
4. State Machines & Data Lifecycle
- Staging Migration Runner Lifecycle (
staging/migrate_and_seed.py):ACQUIRE_LOCK->CHECK_LEDGER(if empty &008-complete ->ADOPT_LEGACY_000_008) ->VERIFY_CHECKSUMS->APPLY_PENDING_IN_TX->SEED_STAGING_DEVICES->RELEASE_LOCK. - UFW SSH Allowlist Lifecycle (
deploy/update_allowed_ip.sh):PREVIOUS_IP->APPLIED_UNCONFIRMED (300s timer)->CONFIRMED (--confirm)ORAUTO_ROLLED_BACK (timeout).
5. Technical Contract (Inputs -> Processing -> Side Effects)
- Containers:
mtls-nginx(:443,172.30.0.11),mtls-gateway(:8001,172.30.0.10), stagingpostgres:17-alpine(127.0.0.1:55432), stagingmqtt(:8883), stagingbackend(:8000), stagingmtls-proxy(:8443),firmware-builderCLI image. - Files / Scripts:
deploy/*,staging/*,scripts/*,diagnostics/*,mechanical/*,tools/*,tests/*,cloud/tests/*,docs/*,mockups/planovi-converters/*.
6. Cross-Repository Dependencies
scripts/sync-brand.sh->PA-IDEAS/planovi-docs|ghCLI git clone | SyncsBRANDING_GUIDE.md&assets/brand/*.scripts/deploy_public_ingress.ps1-> Supabase Cloud CLI |SUPABASE_ACCESS_TOKEN+SUPABASE_PROJECT_REF| Deploysingest-telemetryEdge Function & secrets.deploy/docker-compose.public-ingress.yml-> External VPS Docker networkvps-network(shared withvps-proxy,converters-api-dev,supabase).
7. Why It Works This Way (Decisions, Trade-offs & Workarounds)
- Read-Only Hardened Edge Containers: Minimizes blast radius on the public
:443mTLS entry point by dropping all Linux capabilities and mounting certs read-only under/run/secrets/. - Confirmed Bugs & Platform Coupling:
staging/verify_schema.py:10-12:.replace("postgresql+asyncpg://", "postgresql://", 1)applies only toASLANDI_DATABASE_URL, NOTPLANOVI_DATABASE_URL(operator precedence bug -> crashesasyncpg.connect()whenPLANOVI_DATABASE_URLuses SQLAlchemy+asyncpgscheme).deploy/check-health.sh:13&deploy/cron-setup.md:34: Hardcoded defaultSTATUS_AUTH_TOKENfallback committed in repo;cron-setup.md:10also contains a broken local Windows file path (C:\Users\Silverxis\...).deploy/nginx.admin.planovi.conf:30: Placeholderallow 1.2.3.4; deny all;.tools/setup_local_staging.py:27-57&staging/Dockerfile:9-11: Unconditionally invokes Windowsssl.enum_certificateslooking specifically for"Norton Web/Mail Shield Root"— fails on macOS, Linux, or Windows machines without Norton.deploy/Dockerfile.firmware-builder:28-29: ClonesFreeRTOS-Kernelfrom unpinned-b maindespite comment statingV11.1.0.deploy/docker-compose.public-ingress.yml:25-29: Hardcodesextra_hostsmapping 4planovi.appdomains to191.218.165.149; lines14-15&20-21set divergent defaultTRUSTED_PROXY_CIDRS(0.0.0.0/0vs172.30.0.0/24,...).- Hardcoded developer/lab specifics:
C:\Users\dawid\...inscripts/staging.ps1:36,52,tools/run_staging_mtls_matrix.py:29,tools/run_cloud_e2e.py:42; lab IP192.168.0.150inscripts/t03_8_lab2_network_isolation.ps1:19. - Migration
019ALTER TYPE ... ADD VALUEoutsideBEGIN;..COMMIT;vsstaging/migrate_and_seed.py’s single-outer-transaction rule (migration_transaction_body).
[TEAM_WHY_NEEDED: Why does deploy/docker-compose.public-ingress.yml:25-29 hardcode extra_hosts -> 191.218.165.149 and why do PLANOVI_TRUSTED_PROXY_CIDRS and ASLANDI_TRUSTED_PROXY_CIDRS have conflicting defaults (0.0.0.0/0 vs specific CIDRs)?][TEAM_WHY_NEEDED: Should tools/setup_local_staging.py make the Windows Norton TLS-inspection CA export optional so macOS/Linux developers can run local staging?][TEAM_WHY_NEEDED: Should deploy/Dockerfile.firmware-builder pin FreeRTOS-Kernel to a specific release tag (e.g., V11.1.0) instead of -b main for reproducible firmware builds?][TEAM_WHY_NEEDED: Can mockups/planovi-converters/ (legacy static prototype + unused Next.js/Vinext starter) be archived or removed?]
8. Debugging, Logs & Common Failure Modes
| Symptom / Error Message | Root Cause in Code | How to Verify / Exact Command | Fix |
|---|---|---|---|
setup_local_staging.py fails on macOS/Linux or non-Norton Windows | export_windows_tls_inspection_ca() requires Windows ssl.enum_certificates + "Norton Web/Mail Shield Root" (tools/setup_local_staging.py:27-57) | Run python3 tools/setup_local_staging.py | Guard Norton CA export behind OS/optional flag |
staging/migrate_and_seed.py rejects migration 019 | migration_transaction_body() requires entire file inside a single BEGIN;..COMMIT;, whereas 019 puts ALTER TYPE ... ADD VALUE before BEGIN; | Run pytest tests/test_migration_runner_contract.py or staging/migrate_and_seed.py | Update migrate_and_seed.py to support pre-transaction ALTER TYPE ... ADD VALUE statements |
staging/verify_schema.py crashes with invalid scheme postgresql+asyncpg | Precedence bug on PLANOVI_DATABASE_URL or ASLANDI_DATABASE_URL.replace(...) (verify_schema.py:10-12) | Run PLANOVI_DATABASE_URL=postgresql+asyncpg://... python3 staging/verify_schema.py | Parenthesize (os.getenv(...) or ...).replace(...) |
validate_public_ingress.py fails | Unauthenticated request was not rejected at TLS/Nginx layer | python3 tools/validate_public_ingress.py --url https://api.planovi.app/functions/v1/ingest-telemetry | Verify ssl_verify_client on; and /run/secrets/planovi-device-ca.pem in nginx.api.planovi.conf |