Repository navigation
secrets: don't pass the RPC password to rpcauth in argv - #44
Merged
Merged
Conversation
bobberb
force-pushed
the
rpcauth-stdin
branch
from
October 16, 2026 01:04
54fea56 to
75619ca
Compare
ostermayer
approved these changes
Oct 16, 2026
ostermayer
left a comment
Collaborator
There was a problem hiding this comment.
Keeping the CR is more correct than our .strip(); the clients read the password with $(cat file), which keeps it too. writeSecret and the empty-file regeneration fix a real failure mode we did not cover. Approving.
bobberb
force-pushed
the
rpcauth-stdin
branch
from
October 16, 2026 22:19
75619ca to
44dc46c
Compare
ostermayer
added a commit
to ostermayer/bitcoinix
that referenced
this pull request
Oct 17, 2026
`rtl-setup-config` spliced the RTL `multiPass` into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs, and the password guards an lnd admin macaroon copy and the clnrest admin rune. Let jq read the secret file itself (`--rawfile`) and set the field. No process ever sees the password as an argument, and jq escapes it as JSON, which sed did not (a password with `|`, `&` or `"` broke the config before). Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
ostermayer
added a commit
to ostermayer/bitcoinix
that referenced
this pull request
Oct 17, 2026
The backend's `preStart` spliced the public RPC password into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs. Let jq read the secret file itself (`--rawfile`) and set `CORE_RPC.PASSWORD`. No process sees the password as an argument, and jq escapes it as JSON. Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
This was referenced Oct 17, 2026
Merged
bobberb
force-pushed
the
rpcauth-stdin
branch
from
October 17, 2026 22:52
44dc46c to
d367092
Compare
prusnak
previously approved these changes
Oct 18, 2026
seberm
pushed a commit
that referenced
this pull request
Oct 19, 2026
The clightning-rest and clnrest variants of the connect helper rewrote the URL with sed, with the admin macaroon (hex) or the admin rune spliced into the sed program. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs. Use bash parameter substitution instead, which spawns no process. Same class as the rpcauth argv fix (#44).
seberm
pushed a commit
to ostermayer/bitcoinix
that referenced
this pull request
Oct 19, 2026
`rtl-setup-config` spliced the RTL `multiPass` into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs, and the password guards an lnd admin macaroon copy and the clnrest admin rune. Let jq read the secret file itself (`--rawfile`) and set the field. No process ever sees the password as an argument, and jq escapes it as JSON, which sed did not (a password with `|`, `&` or `"` broke the config before). Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
makeBitcoinRPCPassword ran `rpcauth $user $(cat "$file")`, so the plaintext password was readable by any local user via /proc/<pid>/cmdline while rpcauth ran. rpcauth.py only takes the password as an argument (`-` reads it via getpass from the tty). Load rpcauth.py as a module instead and call its generate_salt and password_to_hmac functions on the password read from the file. The output is the same `<salt>$<hmac>` line that grep/cut extracted before: 16 random bytes as hex, HMAC-SHA256 hex, trailing newline. Clients send the password as `$(cat file)`, so read it the same way: keep CR bytes (no newline translation) and strip trailing newlines only. Unlike the old unquoted `$(cat)`, passwords with spaces, glob characters or leading/trailing whitespace now also get a matching HMAC. Also don't leave empty secret files behind. Passwords and HMACs were written with a plain redirect, which creates the file before the command runs. If pwgen or rpcauth failed, an empty file stayed, and neither the `-e` check for passwords nor the `-nt` check for HMACs regenerated it. An empty password file got the HMAC of a random password (rpcauth.py generates one when it gets none), so nobody could log in as that RPC user. A new `writeSecret` helper writes to a temp file and renames it on success, and empty password and HMAC files left by earlier versions are now regenerated. Add test `secrets-no-argv`: run the secrets generator under strace, check no generated password appears in any execve, and check each bitcoin-HMAC-* file matches its password, including a hand-placed password file with a CRLF line ending. It also checks that a failed HMAC generation leaves no file behind, and that empty password and HMAC files are regenerated. Reported as a low finding in the ostermayer/nix-bitcoin security audit (docs/security-audit-2026-08-14.md), fixed there in the secrets.nix part of ostermayer/nix-bitcoin@e66c00a. This is a different implementation, so it is not a cherry-pick. Fixes bitcoinix#24 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A password file that holds only a newline isn't empty, so makePasswordSecret keeps it. The rpcauth wrapper then stripped the newline and wrote the HMAC of the empty string, and bitcoind would accept an empty password for that RPC user. Fail secret generation for such a file instead, so it leaves no HMAC behind and setup-secrets reports the error. Assisted-by: Claude Code (Claude Opus 5.5)
Contributor
|
Rebased onto master and added a small follow-up commit: the rpcauth wrapper now refuses a password file that holds only a newline, because otherwise it would write the HMAC of the empty password. While at it I corrected one sentence in your commit message: on master an empty password file got the HMAC of a random password (rpcauth.py generates one when it gets none), not of the empty string. Thanks for the thorough testing table, it made this easy to review. |
prusnak
pushed a commit
to ostermayer/bitcoinix
that referenced
this pull request
Oct 20, 2026
The backend's `preStart` spliced the public RPC password into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs. Let jq read the secret file itself (`--rawfile`) and set `CORE_RPC.PASSWORD`. No process sees the password as an argument, and jq escapes it as JSON. Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
msgilligan
pushed a commit
to msgilligan/bitcoinix
that referenced
this pull request
Nov 8, 2026
The clightning-rest and clnrest variants of the connect helper rewrote the URL with sed, with the admin macaroon (hex) or the admin rune spliced into the sed program. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs. Use bash parameter substitution instead, which spawns no process. Same class as the rpcauth argv fix (bitcoinix#44).
msgilligan
pushed a commit
to msgilligan/bitcoinix
that referenced
this pull request
Nov 8, 2026
`rtl-setup-config` spliced the RTL `multiPass` into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs, and the password guards an lnd admin macaroon copy and the clnrest admin rune. Let jq read the secret file itself (`--rawfile`) and set the field. No process ever sees the password as an argument, and jq escapes it as JSON, which sed did not (a password with `|`, `&` or `"` broke the config before). Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
msgilligan
pushed a commit
to msgilligan/bitcoinix
that referenced
this pull request
Nov 8, 2026
The backend's `preStart` spliced the public RPC password into a sed program with `$(cat ...)`. A program argument is visible to every local user through /proc/<pid>/cmdline for as long as sed runs. Let jq read the secret file itself (`--rawfile`) and set `CORE_RPC.PASSWORD`. No process sees the password as an argument, and jq escapes it as JSON. Same class as the rpcauth argv fix (bitcoinix#44) and the lndconnect fix (bitcoinix#77).
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.
Problem
modules/secrets/secrets.nixranso the plaintext RPC password was an argv element of
rpcauth(and thepythonit execs), readable by any local user via/proc/<pid>/cmdlinewhile it ran. Fixes #24.Change
rpcauth.py(pinned upstream file) has no way to read the password from a file or stdin:-usesgetpass, which reads from the tty. So therpcauthwrapper now loadsrpcauth.pywithrunpy.run_path(itsmain()doesn't run) and calls its owngenerate_salt(16)andpassword_to_hmac(salt, password)on the password read from the file. Only the file path is in argv.The wrapper prints
<salt>$<hmac>directly, so thegrep | cutstep is gone. Output format is unchanged: 32 hex chars,$, 64 hex chars, newline (98 bytes), the value bitcoind expects afterrpcauth=<user>:.The password is read the way clients read it (
"$(cat file)"): the file is opened withnewline="", so CR bytes are kept, and only trailing newlines are stripped. This matters only for hand-placed password files (pwgen -snever writes CR, spaces or globs). Compared to master, passwords with spaces, glob characters or leading/trailing whitespace now get a matching HMAC; the old unquoted$(cat)split or mangled them. A password file that isn't valid UTF-8 makes the generator fail (rc 1); master handled it bytewise.Also: no empty secret files. Passwords and HMACs were written with a plain redirect, which creates the file before the command runs. If
pwgenorrpcauthfailed, an empty file stayed behind:[[ $file -nt $HMACfile ]]never regenerated it, and bitcoind gotrpcauth=<user>:with an empty HMAC.[[ -e $1 ]]check forever, and rpcauth hashed the empty string into a valid HMAC, so bitcoind would accept an empty RPC password for that user.A new
writeSecrethelper writes to<file>.tmpand renames it only on success (removing the temp file on failure).makePasswordSecretnow checks-sinstead of-e, and the HMAC is also regenerated when its file is empty, so files left by earlier versions get fixed on the next run.Testing
New test
secrets-no-argv(enabled whenever bitcoind is): runsnix-bitcoin.generateSecretsScriptin a fresh dir understrace -f -e trace=execve, then*password*file (16+ chars) appears in the trace,bitcoin-HMAC-<user>matches\A[0-9a-f]{32}\$[0-9a-f]{64}\n\Zand equals HMAC-SHA256(salt, password) computed in the test driver,bitcoin-rpcpassword-publicplaced by hand before generation asCrLfPassword12345\r\n, so the HMAC has to cover the\rlike$(cat)does,IsADirectoryError) leaves neither an HMAC file nor a temp file,The existing
bitcoindtest still authenticates as userpublicwith the generated rpcauth line (RPC User public not allowed to call method stopmeans auth succeeded).{ services.bitcoind.enable = true; },secrets.nixfromorigin/master(red)Secret 'bitcoin-rpcpassword-privileged' was passed as a command-line argument$(cat)kept the CR too). It guards against a regression in the first version of this change, which used universal newlinesdefaultnetnsRegtestnewline=""and the CRLF case)"$(cat pw)"for plain, spaces/quotes/glob/$, leading and trailing whitespace, multiple trailing newlines, no newline, CRLF, lone CR, UTF-8, empty file, embedded newlinesalt$hmac\nthat verifiesshellcheckon the generatedrpcauthwrapperbitcoin-HMAC-publicbehindPattern ... not found in '')-sfor passwordsbitcoindscenariodefault,regtest,netnsRegtest,wireguard-lndconnect,clightning-replicationon the final code (the last two generate secrets withwg genkeyandssh-keygen)./test/shellcheck.shnix flake check --all-systemsgenerateSecretsCmdsblock for argv leaks, compared the HMAC with"$(cat file)"for 11 password shapesnewline=""), all 11 cases now match/dev/full, crash aftermv, a leftover 0440.tmp, symlinked HMAC file, two concurrent runs: all heldNot covered
cp -p, equal mtimes) is kept, as before.makePasswordSecretsecret (lnd-wallet-password,backup-encryption-password,clightning-replication-password,rtl-password,liquid-rpcpassword) is now regenerated if its file is empty. None of the encryption passwords can have been in use while empty. Checked with the nixpkgs versions:lndinit init-walletfails withprivate passphrase may not be empty,gocryptfs -init -passfilefails withcould not read from "pw": EOF, and duplicity's gpg fails withInvalid passphraseand writes no backup.rtl-passwordandliquid-rpcpasswordare read from the file by every consumer on each start.lndinit init-walletrun above still leaves awallet.db(16 KiB, no wallet), so the[[ ! -f wallet.db ]]check inlnd'spreStartskips wallet creation on later starts, also after the password is regenerated.🤖 Generated with Claude Code