Skip to content

feat(gateway): let CVMs prove possession of their WireGuard key - #1615

Merged
kvinwang merged 1 commit into
nextfrom
feat/gateway-wg-key-proof
Nov 18, 2026
Merged

kvinwang merged 1 commit into
nextfrom
feat/gateway-wg-key-proof

Conversation

@kvinwang

@kvinwang kvinwang commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

RegisterCvm took the CVM's WireGuard public key on trust. A CVM that learned another CVM's public key could register with it while the victim's record was recycled; when the victim returned, its newer record lost the key conflict on every node and stayed out of rotation (its own handshakes, credited by key, kept the squatter alive). It could not read the victim's traffic, but it could keep it offline.

  • InfoResponse.wg_public_key returns the node's WireGuard key; RegisterCvmRequest.wg_key_proof carries {gateway_public_key, mac}.
  • Proof: HMAC-SHA256 keyed by HKDF(X25519(client_sk, gateway_pk), "dstack-gateway-wg-key-proof-v1") over length-prefixed client key, gateway key, app id and instance id (from the CVM's RA-TLS cert, which is what the gateway reads). Low-order keys are rejected. Shared code in dstack-gateway-rpc::wg_key_proof.
  • Guest: calls Info before registering and attaches a proof when the gateway returns a key; otherwise registers as before.
  • Gateway policy: one cluster-wide switch in the replicated KV (global/wg_key_proof_config), read with GetWgKeyProofConfig and set at runtime with SetWgKeyProofConfig (audited), read per registration. Off until set. Off: an invalid or missing proof is accepted with a warning/debug log, so the logs show when the fleet is ready. On: a missing or invalid proof is refused. An unreadable record fails closed (proofs required) until an operator overwrites it. Only the registering node verifies; replicated records are unchanged.

Compatibility: old CVMs and old gateways keep working; registration costs one extra Info call. The attack is closed only once every node runs this and the policy requires proofs. If Info and RegisterCvm land on different nodes (a per-request load balancer), the proof names the wrong key: warned when off, refused when on (see docs/dstack-gateway.md).

@kvinwang
kvinwang enabled auto-merge November 18, 2026 09:11
@kvinwang
kvinwang disabled auto-merge November 18, 2026 09:28
@kvinwang
kvinwang enabled auto-merge November 18, 2026 10:53
kvinwang added a commit that referenced this pull request Nov 18, 2026
Import follows #1604: a record carrying any replicated gateway key, or
the judging node's own, is rejected as LostConflict on every node. Nodes
with equal KV contents now agree once their own keys have replicated;
the window before that is kept as a counterexample. Key squatting is
added: a counterexample without proof of possession, and stable key
binding under the hypothesis that every record was registered by its
key's holder (#1615, modeled abstractly).

IpAlloc follows #1605: release_ip frees an address only when no other
instance holds it. Registration, rebuild, forget and KV reload are
modeled, and alloc_ip never reissues a live address, including one a
conflict loser shares during its grace period. PoolsClear stays an
assumption; #1606 only warns.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/gateway-wg-key-proof branch from 70e6677 to 36a783b Compare November 18, 2026 11:34
@kvinwang
kvinwang disabled auto-merge November 18, 2026 11:34
RegisterCvm took the CVM's WireGuard public key on trust. A CVM that
learned another CVM's key could register with it while the victim's
record was recycled; when the victim returned, its newer record lost the
oldest-wins key conflict on every node and stayed out of rotation, its
own handshakes (credited by key) keeping the squatter alive.

The gateway now reports its WireGuard key in Info, and a CVM attaches a
proof: HMAC-SHA256 keyed by HKDF(X25519(client_sk, gateway_pk)) over the
client key, gateway key, app id and instance id from its RA-TLS cert.
Low-order keys are rejected. A CVM that cannot build a proof registers as
before.

Whether a missing or invalid proof is refused is one cluster-wide switch
in the replicated KV (global/wg_key_proof_config), set with the admin
SetWgKeyProofConfig RPC and read per registration. It is off until set;
off, bad proofs are only logged so operators can tell when the fleet is
ready. An unreadable record fails closed. Only the registering node
verifies; replicated records are unchanged, so records written before
the switch was turned on are not re-checked.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang force-pushed the feat/gateway-wg-key-proof branch from 36a783b to 6d50929 Compare November 18, 2026 11:34
@kvinwang
kvinwang enabled auto-merge November 18, 2026 11:34
@kvinwang
kvinwang merged commit 7a9dbab into next Nov 18, 2026
23 checks passed
@kvinwang
kvinwang deleted the feat/gateway-wg-key-proof branch November 18, 2026 11:43
kvinwang added a commit that referenced this pull request Nov 18, 2026
Import follows #1604: a record carrying any replicated gateway key, or
the judging node's own, is rejected as LostConflict on every node. Nodes
with equal KV contents now agree once their own keys have replicated;
the window before that is kept as a counterexample. Key squatting is
added: a counterexample without proof of possession, and stable key
binding under the hypothesis that every record was registered by its
key's holder (#1615, modeled abstractly).

IpAlloc follows #1605: release_ip frees an address only when no other
instance holds it. Registration, rebuild, forget and KV reload are
modeled, and alloc_ip never reissues a live address, including one a
conflict loser shares during its grace period. PoolsClear stays an
assumption; #1606 only warns.

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