Skip to content

feat(enclave): serve every request inside the TEE gateway - #27

Closed
Marketen wants to merge 3 commits into
mainfrom
feat/tee-serves-everything
Closed

Marketen wants to merge 3 commits into
mainfrom
feat/tee-serves-everything

Conversation

@Marketen

Copy link
Copy Markdown
Contributor

Why

The TEE gateway advertises the same 18 models as the regular gateway but cannot serve them all: nexus/auto and dappnode/qwen3.8-27b return 500, keys with PII masking on are silently not masked (PII_FILTER_ENABLED=false in the enclave), USD prices use a fixed fallback rate, and the enclave's metrics are unreachable. This makes the TEE gateway able to serve every request the regular gateway serves, so the two can run side by side. The regular gateway is unaffected until its own image pin is bumped.

What changes

  • nexus-enclave-init (apps/gateway/cmd/nexus-enclave-init): the enclave entrypoint. It reads a Compose-like file, apps/gateway/enclave/services.yaml, brings up loopback, starts Presidio as uid 1001, starts the gateway once Presidio is healthy, restarts a service that exits (clearing its process group first so a leftover worker cannot hold the port), reaps orphans, and stops everything in reverse order. The gateway itself launches nothing. Services get a minimal environment unless they set inherit_env (Presidio's image sets PORT=3000, which the gateway also reads).
  • Dockerfile.enclave: the runtime image is presidio-analyzer:2.2.362 pinned by digest, with the gateway and init added. Same builder, same reproducibility rules.
  • PII inside the enclave: Nitro builds refuse a PRESIDIO_ANALYZER_URL that is not http://127.0.0.1:<port> and reach the analyzer through a loopback-only transport, so prompt text never leaves the enclave for masking.
  • PII analyzer cache (both builds): an LRU keyed by SHA-256 of mode, language and text (PII_CACHE_ENTRIES, default 20,000). It holds hashes and entity offsets, never text. Chat clients resend the whole conversation every turn, so without it each turn re-analyzes all earlier messages.
  • Egress: measured routes for llm.dappnode.net (DappNode Qwen, 8454) and api.frankfurter.dev (FX, 8455). The FX client now calls api.frankfurter.dev/v1/latest directly; api.frankfurter.app only redirects there.
  • Metrics: Nitro builds serve /metrics on vsock 9090 for the parent to forward to Prometheus. Same metric names, so the existing Grafana dashboard sums both gateways under job="nexus-gateway".

The manifest schema stays at 4, which the webapp verifier checks. require_attested_inference behaviour is unchanged: attested requests still skip PII masking and refuse routers.

Evidence (local, 2 CPUs and 4 GB like the enclave)

Check Result
Boot Gateway healthy 4.5 s after start (Presidio healthy after 4 s)
Memory 742 MiB idle, 868 MiB peak under load, all three processes
Reproducible Two --no-cache amd64 builds with rewrite-timestamp: identical image ID and identical PCR0, PCR1, PCR2
Image 582 MB Docker image, 1.0 GB EIF (was 40 MB)
Supervision Presidio killed: back and healthy in about 1 s, gateway untouched, no zombies. Stop: 0.6 s, reverse order
PII cache, 25-turn agent conversation 1,650 → 126 analyzer calls; masking per turn 578 ms → 40 ms (p50); identical masked output
Tests go test ./... passes. With -tags nitro_enclave on Linux, the same 8 tests fail as on v0.1.73 (they use local test servers the enclave build routes over vsock); no new failures

Deploying (needs the infrastructure PR)

The enclave needs more memory and new parent proxies, so this must ship with the matching infrastructure change: enclave memory 4096 MiB and allocator resize, parent proxies for router/typesafe/minimax/dappnode/frankfurter, a router TLS listener on premium-1, the metrics forwarder, and PII_FILTER_ENABLED/provider keys in the enclave bundle. Release this first, then the infra bump, then the enclave cutover.

Open

  • Presidio latency on the enclave's Xeon 8124M is unmeasured; worth a run on a separate test instance before the production cutover.
  • Boot time with a 1 GB EIF: the infra PR raises the bootstrap retries so a slow Presidio start cannot trigger a rollback.
  • The router stays on premium-1 (reached over vsock 8445). Moving its embedding strategy inside is a follow-up.

🤖 Generated with Claude Code

Marketen and others added 2 commits November 24, 2026 15:40
Run the Presidio PII analyzer inside the gateway enclave, so the TEE gateway
can serve keys with PII masking on without sending prompt text out of the
enclave, and give it the egress, routing and metrics the regular gateway has.

- nexus-enclave-init: a small supervisor that is the enclave entrypoint. It
  reads apps/gateway/enclave/services.yaml (Compose-like), brings up loopback,
  starts Presidio as uid 1001 and then the gateway once Presidio is healthy,
  restarts a service that exits (clearing its process group first), reaps
  orphans, and stops everything in reverse order. The gateway launches
  nothing itself. Services get a minimal environment unless they opt in.
- Dockerfile.enclave: the runtime image is Presidio 2.2.362 pinned by digest
  with the gateway and init on top. Two --no-cache builds still produce the
  same image ID and the same PCR0/1/2.
- PII: a cross-request analyzer cache (LRU keyed by SHA-256 of mode, language
  and text; holds no text). On a 25-turn agent conversation it cuts analyzer
  calls from 1,650 to 126 and masking time per turn from 578 ms to 40 ms, with
  identical output. In Nitro builds the analyzer must be on loopback and is
  reached through a loopback-only transport.
- Egress: measured routes for llm.dappnode.net (DappNode Qwen) and
  api.frankfurter.dev, so the enclave serves every advertised provider and
  shows live USD prices. The FX client calls api.frankfurter.dev directly;
  api.frankfurter.app now only redirects there.
- Metrics: Nitro builds serve /metrics on vsock 9090 for the parent to
  forward to Prometheus, so Grafana sees both gateways under one job.

The manifest schema stays at 4 (the webapp verifier checks it); the new
routes change the manifest content, as any route change does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The enclave serves guest chat like the regular gateway, so it takes the same
output limit from the operator instead of relying on the code default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A plain SHA-256 of a short secret pasted into a prompt could be brute-forced
from a memory dump. Keyed digests under a random per-process key cannot be
matched against guessed texts. Flagged by CodeQL (go/weak-sensitive-data-hashing).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants