Skip to content

[ARCH-327] Address security comments. 2#1760

Merged
connorwstein merged 8 commits intomainfrom
address-sec2
Jan 9, 2026
Merged

[ARCH-327] Address security comments. 2#1760
connorwstein merged 8 commits intomainfrom
address-sec2

Conversation

@pavel-raykov
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2026

✅ API Diff Results - No breaking changes


📄 View full apidiff report

@pavel-raykov pavel-raykov marked this pull request as ready for review January 8, 2026 14:15
@pavel-raykov pavel-raykov requested a review from a team as a code owner January 8, 2026 14:15
Copilot AI review requested due to automatic review settings January 8, 2026 14:15
@pavel-raykov pavel-raykov requested a review from a team as a code owner January 8, 2026 14:15
@pavel-raykov pavel-raykov marked this pull request as draft January 8, 2026 14:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses security concerns by replacing a third-party atomic file writing library with an internal implementation that provides explicit control over file permissions. The changes remove the dependency on github.com/natefinch/atomic and introduce a custom atomic file writing solution that ensures sensitive keystore files are created with secure permissions (0600).

Key Changes:

  • Implemented custom atomic file writing functionality with explicit permission control
  • Removed external dependency github.com/natefinch/atomic from the project
  • Added test coverage for the new atomic file writing implementation

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
keystore/atomicfile/write.go New atomic file writing implementation with configurable file permissions
keystore/atomicfile/write_test.go Test coverage for the atomic file write functionality
keystore/file.go Updated to use internal atomic file writer with explicit 0600 permissions
keystore/go.mod Removed github.com/natefinch/atomic dependency
keystore/internal/raw_test.go Added test assertion for hexadecimal formatting of raw data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread keystore/internal/atomicfile/write_test.go
Comment thread keystore/internal/atomicfile/write.go
Comment thread keystore/internal/atomicfile/write.go
Comment thread keystore/internal/atomicfile/write.go
// WriteFile atomically writes the contents of r to the specified filepath with the given mode.
// This is a copy of https://github.com/natefinch/atomic/blob/master/atomic.go with minor modifications allowing
// to set mode of the written file. If the file already exists, its mode is preserved.
func WriteFile(filename string, r io.Reader, mode os.FileMode) (err error) {
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.

I noticed there's an options based here as well https://github.com/natefinch/atomic/pull/18/files - seems slightly better and we could just use it directly?

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.

Yeah if we can, but we shouldn't import a reference that can be deleted.

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.

yeah sorry I meant just copy paste the solution there, not depend on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, we cannot just copy paste solution here - we still need 1. to fix error output/handling (to make the linter happy), 2. use os.Rename instead of cross-platform Replace. Also, it seems that the copy is just https://github.com/sdassow 's PR - why would we trust it to be better than the current implementation?

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.

I'm not trusting it to be better, I'm saying the options with sane defaults approach implemented there is slightly better. Its a nit though, doesn't matter we can proceed with this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, I have moved it to internal for now

connorwstein
connorwstein previously approved these changes Jan 9, 2026
@connorwstein connorwstein added this pull request to the merge queue Jan 9, 2026
Merged via the queue into main with commit 6efadaa Jan 9, 2026
35 of 36 checks passed
@connorwstein connorwstein deleted the address-sec2 branch January 9, 2026 20:37
cawthorne pushed a commit that referenced this pull request Jan 13, 2026
* Minor.

* Minor.

* Minor.

* Minor.

* Minor.

* Minor.

* Minor.

---------

Co-authored-by: Connor Stein <connor.stein2@gmail.com>
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.

5 participants