Skip to content

feat(guest-agent): log every request to the serial console - #1626

Merged
kvinwang merged 3 commits into
nextfrom
feat/guest-agent-access-log
Nov 19, 2026
Merged

kvinwang merged 3 commits into
nextfrom
feat/guest-agent-access-log

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The guest agent leaves no trace of who called which API. Rocket's request tracing does not fit: its request span records the raw URI including the query string, and prpc GET calls take their arguments from the query (GET /GetKey?path=...), so turning it on would put internal call parameters on the host-visible console. It also omits the unix peer credentials and latency, and emits several lines per request.

Fix

An AccessLog fairing on all four listeners (dstack.sock, tappd.sock, external, guest-api) writes one line per request: listener, peer, method, path, status, latency. Stdout already goes to journal+console; the unit's RUST_LOG now enables dstack_guest_agent::access_log=info and leaves everything else at warn.

What is logged:

  • Headers (including Authorization) and bodies are never logged.
  • On the internal sockets (dstack.sock, tappd.sock) the query string is dropped too, because it may hold prpc call arguments such as key paths. external and guest-api keep it: their callers authenticate through the header, and their query parameters (tail, algorithm, json, ...) are not secrets.
  • The path and query are sanitized with sanitize_for_log (control characters blanked, capped at 512 bytes), so a caller cannot forge log lines.
  • On external, the fairing runs before ScopeFairing, so a refused request is logged under the URI it asked for, with 401.
  • The watchdog's loopback /prpc/Worker.Version probe is skipped, so the console doesn't get a line every 15s.

Note: this exposes which internal APIs an app calls, and how often, to whoever can read the serial console. Arguments stay hidden.

Sample output

Captured from dstack-simulator (which runs the same run_server). external was on 127.0.0.1:18090 and guest-api on vsock:0xffffffff:18000. Anonymous scopes were version, info, health, and dashboard. The fmt timestamp/level/target prefix is trimmed.

dstack.sock (/, /v0, /v1), query dropped:

dstack.sock pid=3203049,uid=1001 "GET /Version" 200 375.623µs
dstack.sock pid=3203055,uid=1001 "GET /Info" 200 1.887481ms
dstack.sock pid=3203056,uid=1001 "POST /GetKey" 200 3.745236ms
dstack.sock pid=3203057,uid=1001 "GET /GetKey" 200 2.358016ms        <- called as /GetKey?path=wallet/eth&purpose=signing
dstack.sock pid=3203058,uid=1001 "POST /GetQuote" 200 1.432238ms
dstack.sock pid=3203059,uid=1001 "POST /GetTlsKey" 200 2.984457ms
dstack.sock pid=3203062,uid=1001 "POST /EmitEvent" 400 223.134µs
dstack.sock pid=3203064,uid=1001 "GET /v0/Info" 200 1.540223ms
dstack.sock pid=3203065,uid=1001 "GET /v1/Version" 200 143.97µs
dstack.sock pid=3203066,uid=1001 "POST /v1/GetKey" 400 240.006µs
dstack.sock pid=3203072,uid=1001 "GET /v1/Info" 200 164.241µs
dstack.sock pid=3203073,uid=1001 "GET /NoSuchMethod" 404 136.663µs

tappd.sock (legacy), query dropped:

tappd.sock pid=3203075,uid=1001 "GET /prpc/Tappd.Info" 200 1.653217ms
tappd.sock pid=3203080,uid=1001 "POST /prpc/Tappd.DeriveK256Key" 200 2.191841ms
tappd.sock pid=3203081,uid=1001 "POST /prpc/Tappd.TdxQuote" 200 1.309676ms   <- called with ?json

external, query kept:

external 127.0.0.1:44064 "GET /" 200 1.181788ms
external 127.0.0.1:44072 "GET /prpc/Info?json" 200 1.328959ms
external 127.0.0.1:44092 "GET /prpc/v1/Health" 200 154.999µs
external 127.0.0.1:44102 "GET /metrics" 401 100.321µs
external 127.0.0.1:44106 "GET /logs/app-1?tail=10&text=true" 401 90.929µs
external 127.0.0.1:44116 "GET /prpc/Info" 401 90.328µs              <- invalid bearer token, token not logged
external 127.0.0.1:44132 "GET /prpc/GetAttestationForAppKey?algorithm=secp256k1" 401 86.426µs
external 127.0.0.1:44142 "GET /.env" 401 81.099µs

The GET /prpc/Worker.Version request from loopback in the same run was skipped as the watchdog probe.

guest-api (host over vsock), query kept:

guest-api vsock:1:350720180 "GET /api/Info?json" 200 1.417319ms
guest-api vsock:1:350720181 "GET /api/SysInfo" 200 950.059469ms
guest-api vsock:1:350720182 "GET /api/NetworkInfo" 200 14.416821ms
guest-api vsock:1:350720183 "GET /api/ListContainers?json" 200 235.76527ms

A grep of the access-log lines for the internal arguments (wallet, signing) and for the bearer token finds nothing. Unit tests cover both modes: the query and token stay out by default, and an opted-in listener logs the query but not the token.

@kvinwang
kvinwang enabled auto-merge November 19, 2026 09:14
@kvinwang
kvinwang merged commit 4fa4f9f into next Nov 19, 2026
22 checks passed
@kvinwang
kvinwang deleted the feat/guest-agent-access-log branch November 19, 2026 09:21
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