Skip to content

feat(gateway): add an admin API to remove a CVM - #1044

Merged
kvinwang merged 3 commits into
nextfrom
fix/gateway-admin-remove-cvm
Aug 12, 2026
Merged

feat(gateway): add an admin API to remove a CVM#1044
kvinwang merged 3 commits into
nextfrom
fix/gateway-admin-remove-cvm

Conversation

@kvinwang

@kvinwang kvinwang commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add an explicit, narrowly scoped Admin RPC for removing one CVM from replicated state and the local data plane.

This is stacked on #1035. That PR deliberately preserves instance records that an older gateway cannot decode or validate. This PR provides the corresponding manual operator recovery path without exposing arbitrary raw-KV deletion.

Behavior

Admin.RemoveCvm takes an instance_id and:

  • writes a tombstone for inst/<instance_id> to persistent WaveKV;
  • removes this node's ephemeral connection and handshake observations;
  • removes the CVM from local ProxyState when present;
  • releases its allocated address and application routing entries;
  • regenerates the WireGuard configuration unconditionally, so a retry after a failed reconfigure still repairs the data plane.

The operation is idempotent and still succeeds when the instance record is unreadable or the CVM is already absent locally. The response reports record_existed and removed_locally, so a mistyped instance_id (which still writes a tombstone) is visible to the operator instead of silently reporting success. The administrative action is logged at warn! level.

Verification

  • cargo fmt --all --check
  • cargo test -p dstack-gateway --all-features (140 tests)
  • cargo clippy -p dstack-gateway --all-features -- -D warnings -D clippy::expect_used -D clippy::unwrap_used --allow unused_variables

Copilot AI lite review requested due to automatic review settings August 12, 2026 08:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a narrowly scoped administrative RPC to remove a single CVM instance from replicated WaveKV state and the local gateway data plane, providing an operator recovery path for bad/unreadable instance records.

Changes:

  • Add Admin.RemoveCvm RPC and request message to the gateway proto.
  • Implement AdminRpcHandler::remove_cvm, calling into the gateway Proxy to delete the instance from WaveKV and local state.
  • Add a regression test covering removal when the stored instance record is unreadable.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
dstack/gateway/src/main_service.rs Adds Proxy::remove_cvm to sync a tombstone to WaveKV and drop the instance from local ProxyState (with WG reconfigure when needed).
dstack/gateway/src/admin_service.rs Wires new remove_cvm admin RPC handler and emits an operator audit log entry.
dstack/gateway/rpc/proto/gateway_rpc.proto Adds RemoveCvm RPC and RemoveCvmRequest message to the Admin service.
dstack/gateway/src/main_service/tests.rs Adds a test proving an operator can remove a CVM even if its KV record is unreadable, and that the operation is idempotent.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dstack/gateway/src/admin_service.rs Outdated
Comment thread dstack/gateway/src/admin_service.rs
Base automatically changed from fix/gateway-kv-robustness to next August 12, 2026 09:29
…come

Address review findings on the RemoveCvm admin RPC:

- Reconfigure WireGuard unconditionally. The tombstone write and the
  in-memory removal are not repeated on a retry, so gating reconfigure
  on them left a failed reconfigure with no retry path and the removed
  CVM's WireGuard peer stuck on the interface.
- Return record_existed/removed_locally to the operator. A mistyped
  instance_id still writes a tombstone, so it previously reported an
  indistinguishable success; now both fields come back false.
- Move RemoveCvmRequest out of the DNS credential section in the proto.
- Start the admin removal log message with lowercase per code style.
The handler only rejected leading/trailing whitespace, so an ID with
internal whitespace, control characters (log injection via the warn!
audit line), or unbounded length was accepted and written into a KV
tombstone key. Reuse import::validate_id — every identifier a
legitimate gateway writes satisfies it, so this rejects only typos.
@kvinwang
kvinwang force-pushed the fix/gateway-admin-remove-cvm branch from 1c7f861 to 4ec0563 Compare August 12, 2026 09:29
@kvinwang
kvinwang merged commit 319aef0 into next Aug 12, 2026
16 checks passed
@kvinwang
kvinwang deleted the fix/gateway-admin-remove-cvm branch August 12, 2026 09:42
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.

2 participants