feat(dstack-util): add streaming encrypt and decrypt commands - #1054
Open
kvinwang wants to merge 9 commits into
Open
feat(dstack-util): add streaming encrypt and decrypt commands#1054kvinwang wants to merge 9 commits into
kvinwang wants to merge 9 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends dstack-util (the guest utility CLI) with a new decrypt subcommand for decrypting data encrypted using the app environment encryption scheme, reusing the app’s env_crypt_key from the app keys file.
Changes:
- Added a
dstack-util decryptsubcommand wired into the CLI command enum andmain()dispatch. - Implemented
cmd_decryptto read ciphertext from stdin or a file, optionally hex-decode, decrypt viacrypto::dh_decrypt, and write plaintext to stdout or a mode-0600 file. - Added CLI flags for
--input,--output,--key-file, and--hex.
Suppressed comments (1)
dstack/dstack-util/src/main.rs:698
- For consistency with other error messages in this crate, this error should start lowercase.
let env_crypt_key: [u8; 32] = keys
.env_crypt_key
.try_into()
.map_err(|key: Vec<u8>| anyhow::anyhow!("Invalid env crypt key length: {}", key.len()))?;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
Addressed in
Verified with the repository strict clippy invocation and all 87 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The CVM encrypted-environment path only decrypts one monolithic blob during setup. Applications that deliver encrypted data through another channel have no reusable guest-side decrypt command, and the legacy single-tag AES-GCM format requires buffering the complete message.
Fix
dstack-util encrypt, which retrieves the app-scoped environment encryption public key from KMS--kms-pubkeyand verify the KMS timestampedsignature_v1before encryptingdstack-util decrypt, which auto-detects chunked ciphertext while retaining legacy encrypted-env compatibility/prpc/Each frame authenticates the stream header, chunk index, flags, and plaintext length. The decoder rejects truncation, reordering, unknown flags, oversized frames, authentication failures, and trailing data. Because authenticated chunks are emitted incrementally, callers must discard output whenever the command exits unsuccessfully.
Testing
cargo clippy -p dstack-util -- -D warnings -D clippy::expect_used -D clippy::unwrap_used --allow unused_variablescargo test -p dstack-util(87 passed)