Skip to content
This repository was archived by the owner on Oct 24, 2026. It is now read-only.

Commit e66c00a

Browse files
committed
security fixes: lndconnect bind, RPC whitelist, secrets argv, wireguard, krops
M-2: lndconnect no longer forces services.lnd.restAddress to 0.0.0.0. The REST API stays on its configured address (default localhost); LAN exposure is now an explicit user choice, documented in the option. M-3: drop scantxoutset, gettxoutsetinfo, getblocktemplate (minutes-scale CPU DoS), getpeerinfo, getnodeaddresses (peer topology leak), and getblockfrompeer (P2P side effect) from the public RPC whitelist. The whitelist assignment is now mkDefault so users can extend it. L-6: pass the RPC password to rpcauth.py via file instead of argv (world-readable via /proc/<pid>/cmdline). L-7: shell-escape secret names/users/groups in setup-secrets. L-8: wireguard preset no longer re-executes its own sed-patched source as root; set the peer with an explicit wg call instead. L-11: bitcoind-remote rewrites the rpcpassword line instead of appending a duplicate on every restart; enforce 0640. krops: pin the commit hash of tag 1.26.2 instead of the re-targetable tag. bitcoind: document that group bitcoin == full RPC via the cookie (L-10).
1 parent 6379e34 commit e66c00a

7 files changed

Lines changed: 60 additions & 27 deletions

File tree

‎modules/bitcoind-rpc-public-whitelist.nix‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
# RPC calls that are safe for public use
1+
# RPC calls that are safe for public use.
2+
#
3+
# Safety bar: bounded CPU cost per call, no P2P side effects beyond
4+
# transaction relay, no leaks of peer topology or wallet contents.
5+
#
6+
# Deliberately excluded (audit M-3):
7+
# - scantxoutset, gettxoutsetinfo, getblocktemplate: minutes-scale CPU,
8+
# trivially abused for DoS by any holder of the public credentials.
9+
# - getpeerinfo, getnodeaddresses: leak the node's peer topology.
10+
# - getblockfrompeer: lets the caller drive the node's P2P block fetching.
11+
# If you need any of these, grant them via
12+
# `services.bitcoind.rpc.users.public.rpcwhitelist` in your own config.
213
[
314
"echo"
415
"getinfo"
@@ -12,7 +23,6 @@
1223
"getblockchaininfo"
1324
"getblockcount"
1425
"getblockfilter"
15-
"getblockfrompeer"
1626
"getblockhash"
1727
"getblockheader"
1828
"getblockstats"
@@ -27,17 +37,12 @@
2737
"getrawmempool"
2838
"gettxout"
2939
"gettxoutproof"
30-
"gettxoutsetinfo"
31-
"scantxoutset"
3240
"verifytxoutproof"
3341
# Mining
34-
"getblocktemplate"
3542
"getmininginfo"
3643
"getnetworkhashps"
3744
# Network
3845
"getnetworkinfo"
39-
"getnodeaddresses"
40-
"getpeerinfo"
4146
# Rawtransactions
4247
"analyzepsbt"
4348
"combinepsbt"

‎modules/bitcoind.nix‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ in {
372372
};
373373
rpc.users.public = {
374374
passwordHMACFromFile = true;
375-
rpcwhitelist = import ./bitcoind-rpc-public-whitelist.nix;
375+
# mkDefault so users can extend/replace the whitelist in their own config
376+
rpcwhitelist = mkDefault (import ./bitcoind-rpc-public-whitelist.nix);
376377
};
377378
}
378379
];
@@ -432,6 +433,9 @@ in {
432433

433434
# Enable RPC access for group
434435
postStart = ''
436+
# NOTE: this makes the RPC cookie readable by group `bitcoin` — every
437+
# service in that group gets full privileged RPC. Keep group membership
438+
# minimal; new services should use an rpc user + HMAC instead (audit L-10).
435439
chmod g=r '${cfg.dataDir}/${optionalString cfg.regtest "regtest/"}.cookie'
436440
'' + (optionalString cfg.regtest) ''
437441
chmod g=x '${cfg.dataDir}/regtest'

‎modules/lndconnect.nix‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ let
2020
# Print URL
2121
lndconnect --url
2222
```
23+
24+
The lnd REST server stays on its configured `restAddress`
25+
(default: localhost). To pair a client over the local network,
26+
either set `services.lnd.lndconnect.onion = true` (recommended),
27+
tunnel the port over SSH (`ssh -L 8080:localhost:8080`), or — if
28+
you really want LAN exposure — set `services.lnd.restAddress`
29+
yourself. Enabling lndconnect never changes the listen address
30+
implicitly.
2331
'';
2432
};
2533
onion = mkOption {
@@ -101,7 +109,10 @@ in {
101109
}
102110
)];
103111

104-
services.lnd.restAddress = mkIf (!lnd.lndconnect.onion) "0.0.0.0";
112+
# Deliberately NOT setting services.lnd.restAddress here.
113+
# Upstream forced it to 0.0.0.0 when lndconnect was enabled without
114+
# onion, which silently exposed the macaroon-admin REST API on all
115+
# interfaces. Exposure must be an explicit user choice (audit M-2).
105116
}
106117

107118
(mkIf lnd.lndconnect.onion {

‎modules/presets/bitcoind-remote.nix‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ in {
1515

1616
systemd.services.bitcoind = {
1717
preStart = lib.mkAfter ''
18-
echo "rpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-privileged)" >> '${cfg.dataDir}/bitcoin.conf'
18+
# Rewrite, don't append: the old version added a duplicate line on every
19+
# restart (audit L-11). The privileged RPC password must stay 0640
20+
# (owner bitcoin, group bitcoin) so the operator can read it for
21+
# bitcoin-cli, but not world-readable.
22+
conf='${cfg.dataDir}/bitcoin.conf'
23+
${pkgs.gnused}/bin/sed -i '/^rpcpassword=/d' "$conf"
24+
echo "rpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-privileged)" >> "$conf"
25+
chmod 0640 "$conf"
1926
'';
2027
postStart = lib.mkForce "";
2128
serviceConfig = {

‎modules/presets/wireguard.nix‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,16 @@ in {
124124
after = wants;
125125
};
126126

127-
# HACK: Modify start/stop scripts of the peer setup service to read
128-
# the pubkey from a secrets file.
129-
wireguard-wg-nb-peer-peer0 = let
130-
getPubkeyFromFile = mkBefore ''
131-
if [[ ! -v inPatchedSrc ]]; then
132-
export inPatchedSrc=1
133-
publicKey=$(cat "${secretsDir}/wg-peer-public-key")
134-
<"''${BASH_SOURCE[0]}" sed "s|\bpeer0\b|$publicKey|g" | ${pkgs.bash}/bin/bash -s
135-
exit
136-
fi
127+
# Read the peer pubkey from the secrets file at service runtime.
128+
# (Upstream patched its own source with sed and re-executed it as root,
129+
# which turned a secrets-store write into root RCE; audit L-8.)
130+
wireguard-wg-nb-peer-peer0 = {
131+
script = mkForce ''
132+
${pkgs.wireguard-tools}/bin/wg set wg-nb peer "$(cat "${secretsDir}/wg-peer-public-key")" allowed-ips ${peerAddress}/32
133+
'';
134+
postStop = mkForce ''
135+
${pkgs.wireguard-tools}/bin/wg set wg-nb peer "$(cat "${secretsDir}/wg-peer-public-key")" remove || true
137136
'';
138-
in {
139-
script = getPubkeyFromFile;
140-
postStop = getPubkeyFromFile;
141137
};
142138
};
143139

‎modules/secrets/secrets.nix‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ let
7777
url = "https://raw.githubusercontent.com/bitcoin/bitcoin/d6cde007db9d3e6ee93bd98a9bbfdce9bfa9b15b/share/rpcauth/rpcauth.py";
7878
sha256 = "189mpplam6yzizssrgiyv70c9899ggh8cac76j4n7v0xqzfip07n";
7979
};
80+
# rpcauth.py takes the password as an argv element, which is
81+
# world-readable via /proc/<pid>/cmdline while the process runs
82+
# (audit L-6). Pass it via file instead.
8083
rpcauth = pkgs.writers.writeBash "rpcauth" ''
81-
exec ${pkgs.python3}/bin/python ${rpcauthSrc} "$@"
84+
exec ${pkgs.python3}/bin/python -c '
85+
import runpy, sys
86+
with open(sys.argv[2]) as f:
87+
password = f.read().strip()
88+
sys.argv = ["rpcauth.py", sys.argv[1], password]
89+
runpy.run_path("${rpcauthSrc}", run_name="__main__")
90+
' "$@"
8291
'';
8392
# Writes secrets to PWD
8493
in pkgs.writers.writeBash "generate-secrets" ''
@@ -96,7 +105,7 @@ let
96105
HMACfile=bitcoin-HMAC-$user
97106
makePasswordSecret "$file"
98107
if [[ $file -nt $HMACfile ]]; then
99-
${rpcauth} $user $(cat "$file") | grep rpcauth | cut -d ':' -f 2 > "$HMACfile"
108+
${rpcauth} "$user" "$file" | grep rpcauth | cut -d ':' -f 2 > "$HMACfile"
100109
fi
101110
}
102111
makeCert() {
@@ -211,7 +220,7 @@ in {
211220
processedFiles=()
212221
${
213222
concatStrings (mapAttrsToList (n: v: ''
214-
setupSecret ${n} ${v.user} ${v.group} ${v.permissions}
223+
setupSecret ${escapeShellArg n} ${escapeShellArg v.user} ${escapeShellArg v.group} ${escapeShellArg v.permissions}
215224
'') cfg.secrets)
216225
}
217226

‎pkgs/krops/default.nix‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
let
44
src = pkgs.fetchgit {
55
url = "https://cgit.krebsco.de/krops";
6-
rev = "1.26.2";
6+
# Commit of tag 1.26.2 (pin the commit, tags can be re-targeted)
7+
rev = "13ae434b140035e7e2664bd5a8ef4c475413b2e0";
78
sha256 = "0mzn213dh3pklvdzfpwi4nin4lncdap447zvl11j81r809jll76j";
89
};
910
in {

0 commit comments

Comments
 (0)