fix: write settings.toml with owner-only permissions - #887
Conversation
Introduce util::write_private_file to create files with 0o600 on Unix and tighten permissions on existing files. Route all settings.toml creation paths (headless/Docker, wizard manual, wizard guided) through it so the nsec_privkey is no longer world-readable. Add unit tests covering new files, content writes, and pre-existing world-readable files being tightened. Co-authored-by: Cursor <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. WalkthroughThe change adds a shared helper for writing owner-only configuration files. Template creation and wizard output use the helper. Tests verify file contents, new-file permissions, and permission tightening for existing files. ChangesPrivate configuration files
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This PR restricts settings.toml to owner-only permissions across the affected creation paths, reducing exposure of the private key. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
AndreaDiazCorreia
left a comment
There was a problem hiding this comment.
@arkanoider apologies, I opened #890 a couple of hours after this one without noticing it was already covering the same ground on settings.toml. That's on me for not checking first.
The two overlap directly: both replace the same std::fs::write in config::util and the same inline OpenOptions block in config::wizard, so whichever lands first will conflict with the other. They also differ on one design point. The helper here tightens an existing file, while mine refuses to touch a path that already exists (O_EXCL, so a planted symlink can't be written through).
Would you mind taking a look at #890 so we can decide together which one to keep? Happy either way, including reworking mine on top of yours if you prefer this shape.
@AndreaDiazCorreia don't worry it happens in these days...if your pr covers also this one, go and close this in favor of yours! |
|
I'll leave this open until #890 is actually merged, just so we don't end up with nothing fixing the Thanks for catching this first. |
Summary
settings.tomlcontains thensec_privkey. Previously, the daemon created it with default permissions (0o644) on the headless/Docker/CI path and the wizard manual-setup path, leaving the private key readable by any user on the host.This PR introduces a shared
util::write_private_filehelper that creates files with0o600on Unix and tightens permissions on pre-existing files, then routes all threesettings.tomlcreation paths through it.Changes
util::write_private_fileinsrc/config/util.rs(Unix:OpenOptions::mode(0o600)+ explicitset_permissions(0o600); non-Unix: plain write).std::fs::writewithwrite_private_filein the non-interactive/headless template copy.src/config/wizard.rswithwrite_private_file.0o644file.Summary by CodeRabbit
Security Improvements
Bug Fixes