Skip to content

fix(keystore): create private config directories owner-only - #419

Merged
PastaPastaPasta merged 2 commits into
masterfrom
fix/sec-keyfile-perms
Oct 7, 2026
Merged

PastaPastaPasta merged 2 commits into
masterfrom
fix/sec-keyfile-perms

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

What

  • write_private_file (forge-core keystore) now creates every directory it has to make under the Forge config directory as 0700, not only the direct parent. ensure_private_dir is recursive (and public so dg can use it); a directory that already exists is left alone, and paths outside the Forge config directory (for example a folder named with -o) still get the plain create_dir_all and are never chmodded.
  • dg auth export creates the default <config>/exports folder through the same helper, so it is 0700 too. A folder named with -o is not touched.
  • Docs: one sentence in docs/guides/identity-and-keys.md that key files are owner-only on macOS/Linux and rely on the user profile's default permissions on Windows, so choose an export location only you can read.

Why

Key files were already written 0600 through an exclusive temporary file and an atomic rename. Missing ancestor directories, however, were created with the process umask (typically 0755), so on a shared host the config tree could be listable by other accounts even though the key files were not readable. All directories Forge creates for its own key material are now owner-only regardless of umask.

How tested

Unix tests (umask set to 022 inside the test, serialised and restored):

  • a stored key is 0600 and every directory created for it (including a not-yet-existing config directory and nested subfolders) is 0700; replacing it stays 0600 and leaves no temp file;
  • a folder outside the config directory keeps its mode;
  • a symlink at the destination is replaced, not followed;
  • a file where a directory is needed is an error;
  • dg auth export default folder is 0700 (this test uses the process umask, so it fails before the change under the usual 022).

The directory-mode tests fail without the change and pass with it. cargo fmt --check and clippy --workspace --all-targets -D warnings pass; the forge-core, forge-relay and other workspace test suites pass, and the new dg test passes.

Limits

  • Windows has no ACL handling here; files rely on the user profile's default ACL (documented).
  • Directories that already exist are not tightened beyond the existing behaviour (the direct parent of a key file under the config directory is still set to 0700).

🤖 Generated with Claude Code

write_private_file now creates every missing directory under the Forge config dir as 0700 (ensure_private_dir is recursive), not only the direct parent, and dg auth export creates its default exports folder the same way. Directories outside the config dir are still never touched. Adds Unix tests for key and directory modes under umask 022 and for a symlink at the destination, and a docs note on Windows ACLs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 80f6dc16-20d2-4977-a3f0-67946177388c
📥 Commits

Reviewing files that changed from the base of the PR and between 1b622a2 and 851d1af.

📒 Files selected for processing (3)
  • crates/dg/src/auth/mod.rs
  • crates/forge-core/src/keystore.rs
  • docs/guides/identity-and-keys.md
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@PastaPastaPasta
PastaPastaPasta merged commit b363762 into master Oct 7, 2026
15 of 20 checks passed
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