Skip to content

feat(enclave): run the Router inside the enclave - #31

Open
Marketen wants to merge 2 commits into
feat/enclave-piifrom
feat/enclave-router
Open

Marketen wants to merge 2 commits into
feat/enclave-piifrom
feat/enclave-router

Conversation

@Marketen

@Marketen Marketen commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #28 (PII in the enclave): merge #28 first. Companion infra PR: dappnode/infrastructure#349.

Why

nexus/auto fails on confidential requests today: the Router isn't in the enclave, and sending the prompt to the one on premium-1 would take it out of the enclave. This runs the same Router code inside the enclave, as a fourth process next to Presidio and the Gateway. It works the way the regular Router does: it reads Postgres directly and supports Jev, which nexus/auto uses.

How

Image (Dockerfile.enclave), every input pinned:

Input Pinned by
dappnode-nexus-router Commit 816ad35 (v0.1.53, what premium-1 runs), via BuildKit's git ADD
ONNX Runtime 1.25.0 (what onnxruntime_go v1.30.1 expects) SHA-256 of Microsoft's NuGet package. It equals the SHA-512 NuGet publishes; the GitHub release downloads the Router's own Dockerfile used now return 404
paraphrase-multilingual-MiniLM-L12-v2 model and tokenizer Hugging Face revision e8f8c21 plus SHA-256

The Router is built on Debian trixie, the same release as the Presidio runtime image (glibc 2.41).

Processes (services.yaml)

  • presidio (uid 1001) → gateway (root) → router (uid 1002).
  • The Router's admin API stays off: no ROUTER_ADMIN_TOKEN, so nothing in the enclave writes routing configuration.
  • nexus-enclave-init learns Compose's env_file, with one difference: it waits for a file that does not exist yet.

Secrets

  • ROUTER_DATABASE_URL and TYPESAFE_API_KEY arrive in the KMS-sealed bundle with the Gateway's own.
  • After bootstrap the Gateway writes the Router's share to /run/nexus/router.env (enclave RAM, 0700/0600, root only), and the init starts the Router with it.
  • A missing or malformed database URL stops the Gateway. A cutover's health check then fails, and the playbook rolls back.

Network. The Router has no network of its own; the Gateway relays (internal/enclave/network/relay.go):

  • 127.0.0.1:5432 → parent vsock 8454 → Postgres on premium-1. Queries carry router and model IDs, never prompt text.
  • 127.0.0.1:3128: an HTTP CONNECT proxy, set as the Router's HTTPS_PROXY, that opens tunnels to api.typesafe.ai:443 only, over the measured TypeSafe route (vsock 8452). TLS ends at TypeSafe, so the parent sees ciphertext. Every other host gets 403.

Checks that keep prompts in the enclave

  • In a Nitro build, ROUTER_URL must be http://127.0.0.1:<port> (like PRESIDIO_ANALYZER_URL), and the Router transport dials loopback only.
  • The bundle accepts ROUTER_URL only on loopback, and ROUTER_DATABASE_URL only at the relay address.

Manifest

  • router_vsock_port (8445, which no parent served) is replaced by database_vsock_port (8454).
  • schema_version stays 4. The SDK reads only schema_version, profile, workload, source_revision and ingress, and pins the version, so a bump would break every client for a change none of them reads.

Attested inference. Requests with require_attested_inference still refuse routers: Jev sends the prompt to TypeSafe.

Checked locally

  • go vet and go test -race ./... pass.
  • Nitro-tagged vet and tests pass on Linux, including the new transport test.
  • govulncheck in both builds: no vulnerable code is called. gitleaks finds nothing. The KMS allowlist tests pass.
  • New tests:
    • relays: both directions; bytes sent right behind the CONNECT; refused hosts, ports and methods never dial upstream; unreachable upstream.
    • env file: atomic write, 0600/0700 modes, no line-break injection, URL must point at the relay.
    • init: env_file both spellings, waiting for the file, stopping while waiting, environment over env_file, malformed lines.
    • shipped services.yaml: order, users, URLs, proxy, no admin token.
    • bundle validation, plus a cross-check that the bundle and the Gateway agree on the relay address.
  • Boot test, with --cpus 2 --memory 4g and the local (non-vsock) build. The Gateway's own relay code ran in the container's network namespace with TCP dialers. It reached a local Postgres with every Nexus migration applied.
    • Presidio was healthy in 3.8 s, and the Gateway was up.
    • The init logged router: waiting for /run/nexus/router.env. Once the file appeared (9 s later), the Router connected to Postgres through the relay, loaded the model and was healthy 2.5 s later.
    • Embedding routing: a coding prompt went to test/smart (score 0.34), small talk to test/fast (0.88).
    • Jev routing: the request crossed the proxy and TLS reached api.typesafe.ai, which answered 401 to my fake key. A real Jev answer needs the production key, which I don't hold.
    • The proxy refused api.deepseek.com with 403.
  • Memory
    • Root filesystem: 981 MiB with PII only, 1,468 MiB with the Router (it lives in enclave RAM).
    • Processes idle: Router 613 MiB, Presidio 749, Gateway 23.
    • Under 16 threads of 4,000-character prompts: Router 914 MiB, Presidio 759.
    • That is about 3.2 GB in the enclave, so infrastructure#349 sets 5 GiB.
  • Reproducibility: two --no-cache linux/amd64 builds with rewrite-timestamp gave the identical image manifest sha256:b8bd233e…. I did not compute PCRs with nitro-cli.

Before merging

  • The docker CI job will fail until dappnode/dappnode-nexus-router is public. It builds Dockerfile.enclave, which fetches the Router by git. Marc is making the repository public. Until then, build locally with --build-context router-src=<checkout at 816ad35>.

  • Check the model against premium-1, because the examples' stored embeddings were made with the model premium-1 mounts. The nexus role downloaded it from Hugging Face's unpinned main, once, into /data/dappnode_nexus/router/models:

    sha256sum /data/dappnode_nexus/router/models/model.onnx /data/dappnode_nexus/router/models/tokenizer.json

    Expected:

    • 10f7a088420252b26caf819236ca2c9d2987afd0fc06fec7553b542a5655a05a for model.onnx;
    • 2c3387be76557bd40970cec13153b3bbf80407865484b209e655e5e4729076b8 for tokenizer.json.

    The size matches (470,301,610 bytes). If they differ, pin this PR to premium-1's files instead.

  • Boot it on a real Nitro host. A 1.5 GB image has not run on one.

🤖 Generated with Claude Code

Marketen and others added 2 commits November 27, 2026 09:20
nexus/auto now works on confidential requests: the Router runs as a fourth
process in the enclave, so a prompt is never sent out of it for routing.

- Dockerfile.enclave builds dappnode-nexus-router at the commit the regular
  Router runs (v0.1.53, 816ad35), with ONNX Runtime 1.25.0 from Microsoft's
  NuGet package and the embedding model from a pinned Hugging Face revision,
  all checked by checksum. The image still builds reproducibly.
- services.yaml starts it as uid 1002 after the Gateway, with its admin API
  off. nexus-enclave-init learns Compose's env_file, and waits for the file.
- The Router has no network of its own. The Gateway relays Postgres
  (127.0.0.1:5432 -> parent vsock 8454) and runs a CONNECT proxy
  (127.0.0.1:3128) that opens tunnels to api.typesafe.ai:443 only, for the
  Jev strategy, over the measured TypeSafe route. TLS ends at TypeSafe.
- The Router's secrets (ROUTER_DATABASE_URL, TYPESAFE_API_KEY) come in the
  KMS-sealed bundle. After bootstrap the Gateway writes them to
  /run/nexus/router.env (root only) for the init to pass on.
- Inside the enclave ROUTER_URL must be http://127.0.0.1:<port>, and the
  Router transport dials loopback only. The bundle accepts ROUTER_URL only on
  loopback and ROUTER_DATABASE_URL only at the relay address.
- The manifest drops router_vsock_port (nothing leaves the enclave for the
  Router any more) and declares database_vsock_port. Schema stays 4: clients
  read only schema_version, profile, workload, source_revision and ingress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GitHub secret scanning flagged a dummy test URL as a Postgres connection
string. No check needs a password, so the test URLs carry none.

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.

1 participant