sops icon indicating copy to clipboard operation
sops copied to clipboard

keystore: Generalized readStreamSafe

Open Dexmachi opened this issue 6 months ago • 1 comments

closes https://github.com/getsops/sops/issues/2162 closes https://github.com/getsops/sops/issues/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 fsio package, and with it new fsio.Read, fsio.Open and fsio.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.Mkfifo and 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 if statement), so it can extend to the rest of the tool.

[!NOTE] The fsio.ClearCache function 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 use defer fsio.ClearCache so the cache's bytes get zeroed out from memory. This is not required, however it is an important safety consideration.

Dexmachi avatar Jun 02 '26 22:06 Dexmachi

works :b image

Dexmachi avatar Jun 02 '26 23:06 Dexmachi

as soon as #2232 gets merged, I'll update this branch

Dexmachi avatar Jun 28 '26 13:06 Dexmachi

hey, uh

are there any updates about this @felixfontein?

Dexmachi avatar Jul 27 '26 12:07 Dexmachi

I'm still waiting on what the other maintainers think (https://github.com/getsops/sops/pull/2163#discussion_r3178641157). So far nobody commented here or in the original PR.

felixfontein avatar Jul 27 '26 19:07 felixfontein

I'm still waiting on what the other maintainers think (#2163 (comment)). So far nobody commented here or in the original PR.

gotcha

Dexmachi avatar Jul 27 '26 20:07 Dexmachi