Skip to content
Merged
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ 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.

A confidential request may set `"require_attested_inference": true` in its
encrypted envelope, next to `schema_version`, `request_id`, `issued_at` and
Expand Down
6 changes: 6 additions & 0 deletions apps/gateway/internal/enclave/network/network_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ func ConfigureRouterTransport(*http.Transport) {}
func ConfigureDefaultTransport() error { return nil }

func StartTinfoilTLSBridge() (net.Listener, error) { return nil, nil }

// ListenMetrics is only used inside the enclave; elsewhere metrics listen on
// METRICS_PORT.
func ListenMetrics() (net.Listener, error) {
return nil, fmt.Errorf("metrics over vsock only exist inside the enclave")
}
6 changes: 6 additions & 0 deletions apps/gateway/internal/enclave/network/network_nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func ListenGateway(port uint32) (net.Listener, error) {
return vsock.Listen(port, nil)
}

// ListenMetrics serves metrics on the vsock port the parent forwards to
// Prometheus.
func ListenMetrics() (net.Listener, error) {
return vsock.Listen(profile.MetricsVsockPort, nil)
}

func ConfigureProviderTransport(transport *http.Transport) {
configureProviderTransport(transport)
}
Expand Down
17 changes: 11 additions & 6 deletions apps/gateway/internal/enclave/profile/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ const (
// Port 7000 is used by the Nitro image loader while the enclave boots.
// Keep application traffic on a distinct port to avoid relying on reuse of
// that implementation-owned listener.
BootstrapPort = 7001
GatewayPort = 8080
ParentCID = 3
KMSVsockPort = 8000
MeteringVsockPort = 8444
RouterVsockPort = 8445
BootstrapPort = 7001
GatewayPort = 8080
ParentCID = 3
KMSVsockPort = 8000
MeteringVsockPort = 8444
RouterVsockPort = 8445
// MetricsVsockPort serves Prometheus metrics to the parent, which forwards
// them to the scraper. The parent connects in, so this adds no way out of
// the enclave. Metrics carry model, provider and error labels, never
// request content.
MetricsVsockPort = 9090
SecretBundleSchema = 1
ManifestSchema = 4
)
Expand Down
15 changes: 12 additions & 3 deletions apps/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,20 @@ func main() {
go func() {
metricsAddr := envOr("METRICS_PORT", "9090")
zapLogger.Info("metrics server starting", "port", metricsAddr)
metricsBind := ":" + metricsAddr
if profile.Enabled {
metricsBind = "127.0.0.1:" + metricsAddr
// Inside the enclave the parent forwards this vsock port to
// Prometheus, so the enclave reports the same metrics as any gateway.
listener, err := enclavenetwork.ListenMetrics()
if err != nil {
zapLogger.Error("metrics listener error", "error", err)
return
}
if err := http.Serve(listener, metricsMux); err != nil {
zapLogger.Error("metrics server error", "error", err)
}
return
}
if err := http.ListenAndServe(metricsBind, metricsMux); err != nil {
if err := http.ListenAndServe(":"+metricsAddr, metricsMux); err != nil {
zapLogger.Error("metrics server error", "error", err)
}
}()
Expand Down
Loading