Skip to content

fix(kms): clear measurement cache entries by their .json file name - #1471

Merged
kvinwang merged 3 commits into
nextfrom
fix/kms-clear-measurement-cache
Oct 28, 2026
Merged

kvinwang merged 3 commits into
nextfrom
fix/kms-clear-measurement-cache

Conversation

@Leechael

@Leechael Leechael commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Admin.ClearImageCache with a specific config_hash returns success but deletes nothing.

The verifier stores measurement cache entries as measurements/<key>.json (CvmVerifier::measurement_cache_path), but KmsState::clear_image_cache removes measurements/<config_hash>, without the suffix. remove_cache finds neither a dir nor a file at that path and returns Ok(()). Passing <key>.json as the key does not work either, because the key must be pure hex.

So only config_hash = "all" actually clears measurements. Clearing one image with {"image_hash": "<hash>", "config_hash": "<key>"} leaves its cached MRs behind, and the next legacy TDX verification re-downloads the image but reuses the stale measurements. The mismatch has existed since the measurement cache moved to <key>.json files (already the case in v0.5.6).

Fix

Cache clearing moves into CvmVerifier::clear_cache, which owns the cache layout and builds paths with images_dir() and measurement_cache_path(). KmsState::clear_image_cache now just delegates to it, so KMS no longer hard-codes images/, measurements/, or the .json suffix. The hex-key guard, the empty-key no-op, and the "all" behavior are unchanged.

Verification

Run in rust:1.92-bookworm (sev-snp-attest does not build on macOS):

  • New test clear_cache_only_deletes_the_named_entries (verifier) covers named, empty, non-hex, and "all" keys for both caches.
  • cargo test -p dstack-kms: 57 passed. cargo test -p dstack-verifier --lib: 40 passed.
  • cargo clippy -p dstack-kms -p dstack-verifier -- -D warnings --allow unused_variables: clean. cargo fmt --all --check: clean.

Not covered: a live ClearImageCache call against a running KMS.

Signed-off-by: Leechael Yim <yanleech@gmail.com>
@Leechael
Leechael force-pushed the fix/kms-clear-measurement-cache branch from bc21e19 to 25655b5 Compare October 24, 2026 06:16
The image and measurement cache layout is owned by CvmVerifier, so move
cache clearing there and drop the exported MEASUREMENT_CACHE_SUFFIX.
KMS no longer hard-codes the images/ and measurements/ paths, which is
how the .json suffix got out of sync in the first place.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang merged commit 4f37b4a into next Oct 28, 2026
12 checks passed
@kvinwang
kvinwang deleted the fix/kms-clear-measurement-cache branch October 28, 2026 05:02
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