Skip to content

feat(tools): add dstack-key-recovery for older KMS epochs - #1632

Merged
h4x3rotab merged 2 commits into
nextfrom
check-kms-epoch0-migration-sdk-publish
Nov 20, 2026
Merged

h4x3rotab merged 2 commits into
nextfrom
check-kms-epoch0-migration-sdk-publish

Conversation

@h4x3rotab

Copy link
Copy Markdown
Contributor

Adds dstack-key-recovery, a small tool to recover an application key from an older KMS root epoch.

Why

The guest agent only serves its boot (current) epoch. After a KMS root rotation, getKey returns a key derived from the new root, and the old key is no longer reachable through the agent. The KMS still holds the old epoch, so the tool asks for that epoch's app root and re-applies the frozen derivation.

What

  • Reproduces both guest APIs:
    • 0.5.x API (v0): getKey(path, purpose, algorithm)
    • 0.6.x API (v1): getKey(domain, algorithm)
  • --api auto picks by guest version from vm_config.image; --api v0|v1 forces either.
  • Reads KMS URL, pinned CA, launch ticket and collateral config from .appkeys.json / .sys-config.json; no flags needed.
  • key — one-shot derivation, human or --json.
  • info — current root/app epochs, guest version, whether epoch 0 is still served.
  • serve — HTTP on a Unix socket and/or localhost TCP: /health, /info, /key, /v0/key, /v1/key, GET and POST.
  • App roots cached per (root_epoch, app_epoch).

Container

Production CVMs have no SSH, so the tool is meant to run as a sidecar. Includes:

  • Dockerfile — pinned base image, clones at DSTACK_REV, cargo build --locked, static musl, scratch runtime.
  • docker-compose.example.yaml — sidecar + app.
  • .github/workflows/key-recovery-release.yml — builds ghcr.io/dstack-tee/dstack-key-recovery from the tag commit with provenance and SBOM.

Passthroughs that turned out to be required (validated on a real 0.5.15 CVM):

  • /dstack/.host-shared, /run/log/dstack, /etc/tdx-attest.conf
  • /dev/tdx_guest, /dev/vsock
  • CCEL mounted outside /sys plus DSTACK_CCEL_FILE (sysfs files cannot be bind-mounted into the container's /sys)
  • security_opt: ["seccomp=unconfined"] for AF_VSOCK

Testing

  • Unit tests pin the v0 vector from the guest-agent tests and the v1 vector from docs/guest-api-v1.md.
  • Real 0.5.15 CVM on prod5/prod9 against the live KMS (current epoch 1, epoch 0 preserved):
    • tool at the current epoch is byte-identical to the agent's getKey, both chain links
    • tool at epoch 0 returns the old-root key with the epoch-0 KMS signature
    • v1 at epoch 0 returns the v1 key from the same app root
    • serve works over Unix socket and TCP, GET and POST
    • containerized tool and guest-OS tool produce identical keys

Notes

  • The disk key is instance-bound and is not recovered here; app keys are instance-independent.
  • The tool must run inside the CVM (it needs the platform quote).

@h4x3rotab
h4x3rotab force-pushed the check-kms-epoch0-migration-sdk-publish branch 2 times, most recently from 91489db to 953f412 Compare November 20, 2026 12:46
@h4x3rotab
h4x3rotab enabled auto-merge November 20, 2026 12:46
Signed-off-by: Hang Yin <h4x3rotab@gmail.com>
Signed-off-by: Hang Yin <h4x3rotab@gmail.com>
@h4x3rotab
h4x3rotab force-pushed the check-kms-epoch0-migration-sdk-publish branch from 953f412 to 4d1b060 Compare November 20, 2026 12:53
@h4x3rotab
h4x3rotab disabled auto-merge November 20, 2026 12:53
@h4x3rotab
h4x3rotab merged commit 4995378 into next Nov 20, 2026
16 checks passed
@h4x3rotab
h4x3rotab deleted the check-kms-epoch0-migration-sdk-publish branch November 20, 2026 12:53
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