Skip to content

sdk: make key epoch selection explicit - #1629

Merged
kvinwang merged 2 commits into
nextfrom
refactor/sdk-drop-get-key-at-root-epoch
Nov 20, 2026
Merged

kvinwang merged 2 commits into
nextfrom
refactor/sdk-drop-get-key-at-root-epoch

Conversation

@kvinwang

Copy link
Copy Markdown
Collaborator

Problem

  • SealedEnv sealed to the wrong app epoch by default. sealEnv/seal_env/SealEnv and the SealedEnv public-key verifiers defaulted the app epoch to 0. They run offline, so they cannot know the current epochs. A caller that passed only the root epoch, as every SDK README showed, sealed an envelope naming app epoch 0 after an app key rotation. The guest then decrypts with the app-epoch-0 key and the CVM fails at boot.
  • Go and Rust had two ways to pick a root epoch. GetKeyAtRootEpoch / get_key_at_root_epoch duplicate GetKeyAtEpochs(..., &root, nil) / get_key_at_epochs(..., Some(root), None).

Fix

  • All four SDKs and vmm-cli take root_epoch, app_epoch as required arguments, in that order, for sealing and for SealedEnv public-key verification. Go's SealEnvAtEpochs / VerifySealedEnvPublicKeyAtEpochs and Rust's seal_env_at_epochs / verify_sealed_env_public_key_at_epochs are folded into the plain names. Old call sites now fail to compile or raise on the missing argument, so nothing keeps sealing to epoch 0 by accident.
  • Remove GetKeyAtRootEpoch and get_key_at_root_epoch.
  • READMEs and docs/app-key-epochs.md pass both epochs of the GetSealedEnvPubKey response.

Both changes are breaking and recorded in CHANGELOG.md. Neither function was in a published SDK package: crates.io dstack-sdk is at 0.1.3, and the newest Go SDK tag, sdk/go/v0.1.0, predates them.

The VMM web UI already seals with the epochs from the response and is unchanged.

Verification

  • Rust: cargo fmt, clippy -D warnings, and cargo test --workspace against the simulator.
  • Go: gofmt, go vet, and go test ./dstack ./tappd against the simulator.
  • JS: tsc --noEmit, and vitest on sealed-env.test.ts.
  • Python: pytest tests/test_seal_env.py, plus ruff, ruff format and mypy.

#1508 touches nearby code (GetKey epoch decoding, SealedEnv fixture tests). Whichever PR lands second needs a small rebase.

GetKeyAtEpochs(ctx, domain, algorithm, &rootEpoch, nil) and
get_key_at_epochs(domain, algorithm, Some(root_epoch), None) already
select a root epoch alone, so the root-only variants in Go and Rust only
add a second way to say the same thing.

Signed-off-by: Kevin Wang <wy721@qq.com>
SealEnv and the SealedEnv public-key verifiers defaulted the app epoch to
0. They run offline and cannot know the current epochs, so a caller that
fetched the key after an app key rotation and passed only the root epoch,
as every SDK README showed, sealed an envelope naming app epoch 0. The
guest then decrypts with the app-epoch-0 key and fails at boot.

Take root_epoch and app_epoch as required arguments in that order in all
four SDKs and vmm-cli, fold Go's SealEnvAtEpochs and
VerifySealedEnvPublicKeyAtEpochs and Rust's seal_env_at_epochs and
verify_sealed_env_public_key_at_epochs into the plain names, and pass
both epochs of the GetSealedEnvPubKey response in the READMEs.

Signed-off-by: Kevin Wang <wy721@qq.com>
@kvinwang
kvinwang merged commit da4d823 into next Nov 20, 2026
20 checks passed
@kvinwang
kvinwang deleted the refactor/sdk-drop-get-key-at-root-epoch branch November 20, 2026 12:13
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