News for hackers. Stuff that matters.
Re:Handling secrets (somewhat) securely in shells by mpyne on Tuesday January 13, 2026 @11:16PM (#46612274)
Another trick I've used is to use named FIFOs for commands that expect there to be files rather than stdin/stdout. The command that spits the sensitive credential outputs to the FIFO and blocks.

The command that needs the sensitive credential to be input is pointed to the FIFO and reads it, and nothing is left over on disk or in the shell's history or memory.

Re:Handling secrets (somewhat) securely in shells by luckman212 on Tuesday January 13, 2026 @11:26PM (#46612322)
would very much like to see a small example of how to create, consume, and destroy those FIFOs...
Re:Handling secrets (somewhat) securely in shells by stouset on Tuesday January 13, 2026 @11:29PM (#46612343)
https://man7.org/linux/man-pages/man1/mkfifo.1.html

Pretty simple. This creates a named pipe. One end of a shell command redirects to it, one end redirects from it. rm when finished.

Re:Handling secrets (somewhat) securely in shells by akdev1l on Wednesday January 14, 2026 @12:13AM (#46612583)
You can just use process substitution

cat <(secret-print my-secret)

Re:Handling secrets (somewhat) securely in shells by SoftTalker on Wednesday January 14, 2026 @12:33AM (#46612698)
In a shell script situation, you'd typically trap EXIT and ERR and remove the fifo in the handler.
Re:Handling secrets (somewhat) securely in shells by SoftTalker on Wednesday January 14, 2026 @12:31AM (#46612689)
I was going to mention this too, it was a pretty common approach we used in batch files. There's a potential race condition if something else can read from the fifo after the secret is there but before the intended process consumes it, so you still need to be careful with permissions.
Re:Handling secrets (somewhat) securely in shells by linuxhackerman on Wednesday January 14, 2026 @04:08AM (#46613930)
Process substitution (the `<(echo ...)` approach I used in the post) is practically equivalent to this, creating a path that can be read by the shell and its child processes (and, at least as expanded, _only_ by them) just like a named FIFO -- but without the race condition mentioned by SoftTalker.

What you've hinted at and what I didn't mention in the post is that this is indeed a good way to avoid even having the secret ever be a shell variable. It's a bit of extra fiddling to turn just the token into the Authorization header, but it's certainly possible, something like this:

curl -H @<(rbw get gitlab-access-token | sed 's/^/Authorization: Bearer/') https://gitlab.example.com/api/v4/projects