keystore: Generalized readStreamSafe#2205
Open
Dexmachi wants to merge 3 commits into
Open
Conversation
this implements a new fsio package with fsio.Open, fsio.Read, fsio.ClearCache and some others in order to generalize my last proposed contrib. This allows SOPS to read files from streams safely, regardless of where or what they are. This took sometime, Srry. Signed-off-by: Caio Rocha de Oliveira <caiorocoli@gmail.com>
Signed-off-by: Caio Rocha de Oliveira <caiorocoli@gmail.com>
Author
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.

closes #2162
closes #1303
This PR replaces my last attempt at these issues ( #2163 ).
On that PR, some issues regarding cache and memory safety have been brought up.
Additionally, the maintainers have been asked if generalizing that implementation would be good, and so I went to try and do that. (Sorry this took a while, I had some personal matters to attend to.)
This PR adds a new
fsiopackage, and with it newfsio.Read,fsio.Openandfsio.ClearCache. These are stream safe and rely on caching credentials in order to mitigate read-once issues with pipes, FIFOs and such.Tests regarding race conditions and read-once issues have also been added to this package, although some are unix only (mainly due to
syscall.Mkfifoand FD use to test specific conditions regarding anonymous and named pipes). All tests are passing locally, and I've tested this version manually to check if the implementation works.Also, this caching concerns only stream reads, so this is purely a feature addition with no actual breaking changes to the current normal way to use the tool. This can easily be changed in the future (it's just removing an
ifstatement), so it can extend to the rest of the tool.Note
The
fsio.ClearCachefunction is technically a breaking change for users with library use-cases. If they use named pipes, anonymous pipes OR any other stream-based approach, they should usedefer fsio.ClearCacheso the cache's bytes get zeroed out from memory. This is not required, however it is an important safety consideration.