Repository navigation
fix(guest): write generated credentials atomically - #883
Merged
Merged
Conversation
This was referenced Jul 31, 2026
`dstack-util gen-ra-cert`, `gen-ca-cert` and `gen-app-keys` truncated and rewrote the destination in place. A crash or a full disk mid-write left a partial certificate, private key, or app-keys JSON on disk that the next boot then tried to load. Write them with `safe-write`, which the workspace already uses for the same job in `kms`, `gateway`, `dstack-attest` and `dstack-util`'s own system setup: the payload goes to a temporary file in the target directory, is fsynced, renamed over the destination, and the parent directory is flushed. A reader only ever sees the old file or the complete new one. Private keys and app keys use `safe_write_with_mode(.., 0o600)`, so the mode is applied at creation and the secret never exists on disk with wider permissions, not even briefly between a rename and a follow-up chmod. Bump the workspace `safe-write` to 0.2.0: `safe_write_with_mode` landed in 0.1.3, and 0.2.0 carries the durability and temp-file permission fixes this change depends on.
kvinwang
force-pushed
the
codex/fix-guest-atomic-credentials
branch
from
August 4, 2026 07:49
cfba158 to
83076e6
Compare
kvinwang
added a commit
that referenced
this pull request
Aug 5, 2026
[STACKED on #883] fix(util): write TPM quotes atomically
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
dstack-util gen-ra-cert,gen-ca-certandgen-app-keystruncated and rewrote their destination files in place. A crash or a full disk during the write left a partial certificate, private key, or app-keys JSON on disk that the next boot then tried to load.Fix
Write those files with
safe-write, the crate the workspace already uses for the same job inkms,gateway,dstack-attest, anddstack-util's own system setup. The payload goes to a temporary file in the target directory, is fsynced, renamed over the destination, and the parent directory is flushed afterwards. A reader only ever observes the old file or the complete new one.Private keys and app keys go through
safe_write_with_mode(.., 0o600), so the mode is applied at creation time and the secret never exists on disk with wider permissions -- not even briefly between a rename and a follow-upchmod.The workspace
safe-writepin moves from 0.1.2 to 0.2.0:safe_write_with_modelanded in 0.1.3, and 0.2.0 carries the durability and temp-file permission fixes this change depends on.Changed paths:
dstack/Cargo.tomldstack/Cargo.lockdstack/dstack-util/src/main.rsScope
This PR addresses one logical
guestfinding. It intentionally excludes the acceptance-test infrastructure from #841 and unrelated product fixes from #840.Dependency and merge order
This PR is based directly on
masterand does not require another split product PR to merge first.Verification
cargo check -p dstack-util: passed.cargo clippy -p dstack-util --all-targets: clean.cargo fmt -p dstack-util -- --check: clean.cargo check --workspacewith thesafe-write0.2.0 bump: passed, no other crate needed a change.