Skip to content

feat(gateway): audit CVM registration and state-changing admin RPCs - #1588

Merged
kvinwang merged 4 commits into
nextfrom
feat/gateway-audit-logs
Nov 15, 2026
Merged

kvinwang merged 4 commits into
nextfrom
feat/gateway-audit-logs

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

The gateway logged some admin changes as ad-hoc info lines without the caller, and others not at all (exit, renew_cert, set_caa, reload_cert, rotate_acme_credentials, remove_*, the port policy and set_instance_ready RPCs, ...). CVM registration was not logged with its identity either.

  • Every state-changing admin RPC (24) logs one line to dstack_gateway::audit: info on success, warn with error if refused, with operation, remote (the caller's address) and a subject naming what it acted on: ids, domains and flags, never DNS tokens, certificate keys or other secrets.
  • RegisterCvm logs cvm registered (with app_id, instance_id, the assigned WireGuard client_ip, remote) or cvm registration refused (with error), once the CVM's app and instance ids are known from its app info or attestation.
  • The ad-hoc lines that only repeated these facts are removed; those that add detail (e.g. what remove_cvm actually removed) stay.

Read-only admin RPCs are not audited; every prpc request's method and caller are already in the request span. Remote addresses behind a TCP proxy come with #1582.

Most of the diff is re-indentation from wrapping each handler body (best viewed with whitespace hidden).

Testing

cargo test -p dstack-gateway --all-features passes (340), as do clippy with the CI flags and cargo fmt --check. With a temporary test calling the handlers on a test gateway state with a remote of 198.51.100.7:4242:

INFO dstack_gateway::audit: admin: node 7 status up operation="set_node_status" remote=Some(Tcp(198.51.100.7:4242))
WARN dstack_gateway::audit: admin refused: node 7 status sideways operation="set_node_status" remote=Some(Tcp(198.51.100.7:4242)) error=invalid status: expected 'up' or 'down'
WARN dstack_gateway::audit: admin refused: domain nope.example operation="delete_zt_domain" remote=Some(Tcp(198.51.100.7:4242)) error=ZT-Domain config not found
WARN dstack_gateway::audit: admin refused: instance abc ready Some(true) operation="set_instance_ready" remote=Some(Tcp(198.51.100.7:4242)) error=instance abc not found

RegisterCvm is not exercised by these tests; it was verified on TDX (below).

Verified on TDX

Run on the tdxlab TDX host with real TDX CVMs (guest OS dstack 0.6.0), from one local build of #1580, #1582, #1585 and #1587 merged with #1583 and #1588: the official 0.6.3 KMS and gateway images with these binaries (and the gateway's new entrypoint.sh). The KMS ran in a CVM with a local key provider and a webhook auth backend (allow all but one app; this KMS's root epoch 0 registered); haproxy with send-proxy-v2 fronted the guest listeners of the KMS and the gateway.

  • Admin RPCs with the token logged to dstack_gateway::audit with the caller's remote: set_node_status and set_tombstone_gc_config as admin: …, and a bad status, an unknown ZT domain and an unknown instance as admin refused: … with the error; Status was not audited.
  • An app CVM's registration logged cvm registered with its app_id, instance_id, client_ip and remote.

The gateway logged some admin changes as ad-hoc lines without the
caller, and others, such as exit, renew_cert, set_caa, remove_cvm or
the port policy RPCs, not at all.

Log each state-changing admin RPC to dstack_gateway::audit with its
operation, a subject (ids, domains and flags; never tokens or keys),
the caller's remote and, if refused, the error. Log RegisterCvm the
same way once the CVM's app and instance ids are known, with the
WireGuard address it was given. The ad-hoc lines these replace go.

Signed-off-by: Kevin Wang <wy721@qq.com>
Signed-off-by: Kevin Wang <wy721@qq.com>
Record a forced exit before the process terminates, include the generated
id of a new DNS credential, name ZT domains by their normalized form, and
say which step failed when create_dns_credential or import_cert fails after
a partial effect.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/gateway-audit-logs branch from 8c3246f to 9656367 Compare November 15, 2026 16:00
@kvinwang
kvinwang merged commit 5b50ffc into next Nov 15, 2026
21 checks passed
@kvinwang
kvinwang deleted the feat/gateway-audit-logs branch November 15, 2026 16:18
kvinwang added a commit that referenced this pull request Nov 16, 2026
tc-gw-internal-009 checks that the gateway refuses the old listener
locations (#1587), restarts it with proxy_protocol on the admin listener
(#1582), and checks the admin audit (#1588) and access (#1589) lines.

Signed-off-by: Kevin Wang <wy721@qq.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