Skip to content

Harden LAN/API mutation trust boundary - #591

Closed
frahlg wants to merge 1 commit into
masterfrom
agent/lan-api-trust-boundary
Closed

frahlg wants to merge 1 commit into
masterfrom
agent/lan-api-trust-boundary

Conversation

@frahlg

@frahlg frahlg commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

What changed

  • add one fail-closed request policy across bootstrap, boot phase, normal API operation, and the development proxy
  • cover every unsafe HTTP method plus semantically active GET/HEAD requests that start discovery, begin OAuth, or force an external update check
  • retain the provider OAuth callback as an explicit cross-site exception authorized by short-lived single-use state and PKCE
  • remove wildcard CORS and reject browser cross-origin or cross-site protected requests using Origin, Host, Sec-Fetch-Site, and the actual client address
  • require JSON request bodies to declare an application JSON content type
  • require an opt-in FTW_API_TOKEN Bearer credential for protected requests addressed through public IPs or fully qualified hostnames
  • preserve documented loopback/private-LAN UI and non-browser client flows, with a local recovery path
  • cover bootstrap, battery, EV, update, restore, restart, active reads, all unsafe methods, proxy CORS, token handling, and Host spoofing with positive and negative tests

HTTP surface audit

The central policy wraps the complete Core handler before bootstrap/normal handler swapping, so new Core routes inherit it automatically. The separate CalDAV listener remains independently fail-closed behind its mandatory protocol authentication; applying the JSON API middleware there would break valid CalDAV methods and bodies. The updater control socket is Unix-domain-only and remains outside this LAN/API change.

Why

The LAN API previously returned wildcard CORS headers and had no central trust boundary for state-changing endpoints. Browser-originated cross-site requests could therefore reach privileged controls, while exposure beyond the trusted LAN had no mutation credential gate.

Operator impact

Existing loopback and private-LAN clients continue to work without a token when both the addressed host and actual client are local. Public/FQDN protected requests fail closed unless FTW_API_TOKEN is configured and supplied as a Bearer token.

The built-in browser UI does not store API tokens. Browser deployments on public/FQDN origins must use an operator-managed authenticated HTTPS reverse proxy that injects the Bearer header. Read-only dashboard data is not covered by this migration token and FTW must not be exposed directly to the public internet. Recovery remains available through localhost, a private IP, or .local.

Future remote expansion point

This PR implements no tunnel, passkey, naming, or machine-identity provider. It documents the central request policy as the future proof-verification point for a simple outbound-only design: local FTW passkey verification, a resolved hardware-backed or software-fallback P-256 machine identity as authoritative site identity and tunnel challenge signer, one long-lived TLS connection with a small versioned stream-multiplex contract, short-lived site-and-scope-bound proofs, and read-only access first. Relay state is limited to rotatable domain alias mapping, public site identity, routing/status, and timestamps; it stores no user credential. No cloud account authentication, shared tunnel credential, peer-to-peer/NAT-traversal layer, or browser-managed site directory is introduced. Core safety remains authoritative for every later mutation.

Gateway names are never selectable: adjective-color-animal is derived deterministically from the stable gateway ID with exact compatibility for existing Sourceful Energy Gateways. Names and DNS aliases are not authenticators. Compatible hardware must use its existing non-exportable P-256 key plus normalized 18-hex serial identity; other hosts persist a software P-256 identity with the same public-key/signature wire contract and stable-ID format. The future access layer may depend only on public identity and a narrow signer, never a private-key file representation.

Integration gate with #592

#592 currently creates a dedicated file-backed ftw-site-controller.key and explicitly separates it from the existing gateway identity. That provider choice conflicts with the secure-element-first identity invariant above. Later integration must retain the useful narrow signer contract while resolving identity selection, exact legacy name mapping, stable-ID normalization/fallback derivation, and recovery/rotation in a focused identity ADR. #591 deliberately does not resolve or import #592's implementation.

Validation

  • focused: go test ./internal/api ./cmd/ftw
  • make verify-all
  • pre-commit make verify
  • pre-push make verify-all
  • Linux and macOS Compose migration/configuration validation
  • cross-compiles: linux/arm64, linux/amd64, windows/amd64

@frahlg
frahlg force-pushed the agent/lan-api-trust-boundary branch from 03f1a75 to 1a2e9a3 Compare July 20, 2026 07:22

frahlg commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

Superseded by the semantic P0 integration in #602. The access boundary is now on master and published in v1.5.0-beta.1; this PR should not be merged again.

@frahlg frahlg closed this Jul 20, 2026
@frahlg
frahlg deleted the agent/lan-api-trust-boundary branch August 7, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant