Skip to content

[STACKED on #873] fix(kms): persist private keys owner-only - #874

Merged
kvinwang merged 1 commit into
masterfrom
codex/fix-kms-private-key-permissions
Aug 4, 2026
Merged

[STACKED on #873] fix(kms): persist private keys owner-only#874
kvinwang merged 1 commit into
masterfrom
codex/fix-kms-private-key-permissions

Conversation

@kvinwang

@kvinwang kvinwang commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Problem

KMS wrote private-key files with permissions derived from the generic safe_write() path. A permissive environment could leave CA or service private keys readable by other local users.

Fix

The upstream safe-write crate now provides:

safe_write_with_mode(path, content, mode)

Version 0.1.3 has been published to crates.io and tagged as v0.1.3 upstream. KMS now uses that API with mode 0o600 for:

  • temporary CA private key;
  • root CA private key;
  • RPC private key;
  • K256 private key.

This keeps atomic-write behavior centralized in its owning crate instead of duplicating it in KMS.

Changed paths

  • dstack/Cargo.toml
  • dstack/Cargo.lock
  • dstack/kms/src/onboard_service.rs

Dependency and merge order

Verification

  • Upstream safe-write: all unit and documentation tests passed.
  • Upstream cargo publish --dry-run: passed.
  • safe-write v0.1.3: published successfully to crates.io.
  • cargo test -p dstack-kms onboard_service::tests --no-fail-fast: passed.
  • cargo fmt --all -- --check: passed.
  • git diff --check: passed.

Copilot AI review requested due to automatic review settings July 31, 2026 02:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kvinwang
kvinwang force-pushed the codex/fix-kms-private-key-permissions branch from 062a2a7 to 88201a4 Compare August 3, 2026 14:53
Base automatically changed from codex/fix-kms-bootstrap-once to master August 3, 2026 16:39
@kvinwang
kvinwang force-pushed the codex/fix-kms-private-key-permissions branch from 88201a4 to 51f7c85 Compare August 3, 2026 16:39
Upgrade safe-write to 0.1.3 and use its Unix mode-aware atomic write API for KMS private keys. Root CA, temporary CA, RPC, and K256 keys are created with mode 0600 without duplicating the atomic-write implementation in KMS.
@kvinwang
kvinwang force-pushed the codex/fix-kms-private-key-permissions branch from 51f7c85 to 44cd5ea Compare August 3, 2026 16:46
@kvinwang
kvinwang merged commit c01d0d3 into master Aug 4, 2026
15 checks passed
@kvinwang
kvinwang deleted the codex/fix-kms-private-key-permissions branch August 7, 2026 13:46
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