Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,30 @@ The Nitro confidential endpoint authenticates before storing replay IDs. Each
account may retain at most 10,000 IDs during the three-minute replay window,
shared across its API keys; excess requests return 429 with
`confidential_request_limit_exceeded`. The process-wide limit remains 100,000.
Live entries are never evicted to admit new requests. Metrics bind to loopback
in Nitro builds and retain their internal-network listener in ordinary builds.
Live entries are never evicted to admit new requests. Nitro builds serve
metrics on vsock port 9090, which the parent forwards to Prometheus; ordinary
builds listen on `METRICS_PORT`. Metrics carry model, provider and error
labels, never request content.

The Nitro enclave runs three processes from one measured image:
`nexus-enclave-init` (the entrypoint), the Presidio PII analyzer and the
Gateway. The init reads `apps/gateway/enclave/services.yaml`, starts Presidio as
an unprivileged user, starts the Gateway once Presidio is healthy, restarts
either if it exits, and stops both on shutdown. The Gateway reaches Presidio on
loopback only: a Nitro build refuses to start if `PRESIDIO_ANALYZER_URL` is not
`http://127.0.0.1:<port>`, so prompt text is never sent out of the enclave for
masking. Analyzer results are cached across requests (`PII_CACHE_ENTRIES`,
default 20,000), keyed by an HMAC-SHA256 of the mode, language and text under
a random per-process key; the cache holds those digests and entity offsets,
never the text.

A confidential request may set `"require_attested_inference": true` in its
encrypted envelope, next to `schema_version`, `request_id`, `issued_at` and
`request`. The enclave then lets only attested code read the prompt: itself
and a provider whose attestation it verifies before sending anything (today,
Tinfoil). It refuses routers such as `nexus/auto`, which send the prompt to
the Router, skips PII masking whatever the key's PII mode (masking sends the
prompt to the analyzer, and the provider can't read it anyway), and never falls
the Router, skips PII masking whatever the key's PII mode (the attested
provider can't read the prompt anyway), and never falls
back to a provider without that verification. The code the Tinfoil enclave
must run is pinned in this binary (`tinfoilsh/confidential-model-router`):
`TINFOIL_CONFIG_REPO` is operator configuration outside the measurements, so
Expand Down
37 changes: 28 additions & 9 deletions apps/gateway/Dockerfile.enclave
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# syntax=docker/dockerfile:1.7@sha256:a57df69d0ea827fb7266491f2813635de6f17269be881f696fbfdf2d83dda33e

# Pin upstream build inputs by digest. Together with SOURCE_DATE_EPOCH and
# The Nitro enclave image: the gateway, nexus-enclave-init and the Presidio PII
# analyzer, so every request a regular gateway can serve is served inside the
# enclave and prompt text never leaves it for masking.
#
# The runtime image is Microsoft's Presidio analyzer pinned by its multi-arch
# index digest, with the two Go binaries added on top. nexus-enclave-init is
# the entrypoint: it starts Presidio as uid 1001 and then the gateway as root
# (the gateway configures the enclave's network), from
# apps/gateway/enclave/services.yaml.
#
# Pin every upstream input by digest. Together with SOURCE_DATE_EPOCH and
# rewrite-timestamp (see deploy/nitro/build-release-assets.sh) this builds
# reproducibly: the same revision yields the same PCR0/PCR1/PCR2 on any x86_64
# machine, so a published release can be independently rebuilt and checked with
Expand All @@ -12,6 +22,9 @@ FROM golang:1.26.11-alpine3.24@sha256:ae52b5bc6ed045a9ed26ab03dc19327a802a9cc9aa
ARG SOURCE_REVISION
ARG AWS_REGION
ARG KMS_KEY_ARN
# Empty builds the non-enclave variant, for running the image locally with
# plain Docker (no vsock, no KMS bootstrap). Releases always use the default.
ARG GO_TAGS=nitro_enclave

WORKDIR /src

Expand All @@ -20,26 +33,32 @@ RUN go mod download

COPY . .

# Reject values that could break linker-flag tokenization.
RUN printf '%s' "$SOURCE_REVISION" | grep -Eq '^[0-9a-f]{40}$'
RUN printf '%s' "$AWS_REGION" | grep -Eq '^[a-z]{2}(-gov)?-[a-z]+-[0-9]+$'
RUN printf '%s' "$KMS_KEY_ARN" | grep -Eq '^arn:(aws|aws-us-gov|aws-cn):kms:[a-z0-9-]+:[0-9]{12}:key/[0-9a-fA-F-]{36}$'

RUN CGO_ENABLED=0 GOOS=linux go build \
-buildvcs=false \
-trimpath \
-tags nitro_enclave \
-tags "$GO_TAGS" \
-ldflags="-s -w -buildid= \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.SourceRevision=${SOURCE_REVISION} \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.AWSRegion=${AWS_REGION} \
-X github.com/dappnode/dappnode-nexus-gateway/apps/gateway/internal/enclave/profile.KMSKeyARN=${KMS_KEY_ARN}" \
-o /out/gateway ./apps/gateway
-o /out/gateway ./apps/gateway \
&& CGO_ENABLED=0 GOOS=linux go build \
-buildvcs=false \
-trimpath \
-tags "$GO_TAGS" \
-ldflags="-s -w -buildid=" \
-o /out/nexus-enclave-init ./apps/gateway/cmd/nexus-enclave-init

# No shell, package manager, or writable application data is included in the
# enclave runtime image. The Go binary is fully static.
FROM scratch
FROM mcr.microsoft.com/presidio-analyzer:2.2.362@sha256:286e3fa7f3a7426e775e8564fe1870f1ba8f999d3ab8bbb8cc46a44355d9d6e9

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
USER root
COPY --from=builder /out/gateway /gateway
COPY --from=builder /out/nexus-enclave-init /nexus-enclave-init
COPY apps/gateway/enclave/services.yaml /etc/nexus/enclave-services.yaml

ENTRYPOINT ["/gateway"]
ENTRYPOINT ["/nexus-enclave-init", "-config", "/etc/nexus/enclave-services.yaml"]
CMD []
Loading
Loading