Skip to content

keystore: Generalized readStreamSafe#2205

Open
Dexmachi wants to merge 3 commits into
getsops:mainfrom
Dexmachi:fsio
Open

keystore: Generalized readStreamSafe#2205
Dexmachi wants to merge 3 commits into
getsops:mainfrom
Dexmachi:fsio

Conversation

@Dexmachi

@Dexmachi Dexmachi commented Jun 2, 2026

Copy link
Copy Markdown

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 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 added 2 commits June 2, 2026 19:30
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>
@Dexmachi

Dexmachi commented Jun 2, 2026

Copy link
Copy Markdown
Author

works :b
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SOPS_AGE_KEY_FILE not being able to read from file descriptors in SSS setups Passing age keys via stdin SOPS_AGE_KEY_FILE=/dev/stdin not working

2 participants