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

Commit c021a3e

Browse files
ostermayerclaude
andcommitted
hardening: close the 2026-09-09 gate findings (K3+GLM max, Astra second opinion)
- test/ci/scan-node.nix: scan the recommended deployment — import the secure-node preset (tor, doas, operator) and enable backups (duplicity). The runtime closure vulnix scans now contains what a deployed node exposes; re-baseline .github/cve-whitelist.toml on the next Monday scan. cve-scan.sh: describe the real target; fail closed on malformed report entries or counting errors instead of reading them as 0 findings. - setup-secrets: scoped root sandbox (ProtectSystem=strict with only the secrets dir writable, no network, NoNewPrivileges, capability set limited to chown/fowner/dac). A tmpfiles rule pre-creates the directory because ReadWritePaths= refuses a missing path. - lnd macaroon delivery: `mv -fT --` so a symlink-to-directory planted by lnd at the destination cannot redirect root's move into that directory. - wireguard preset: insert the restrictPeer REJECT at the top of nixos-fw / FORWARD; appended it sat behind the allowed-port accepts, so the peer could still reach any firewall-allowed port on the node's other addresses. - SECURITY.md: commits are signed, CI release tags are not — say so, and pin by commit + narHash. - Fork-native update path: `update-nix-bitcoin` pins the latest fork release tag by commit + prefetched hash; install.md, configuration.md and the importable example no longer route through the refused upstream fetch-release. Audit runs 2026-09-09-025815 (+ Astra second opinion), audits branch. Full local VM suite green. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016AG4NJ9NXLZjHxJLFUX3dn
1 parent d22c5da commit c021a3e

10 files changed

Lines changed: 113 additions & 23 deletions

File tree

‎SECURITY.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,13 @@ PRs to improve the audit prompt are welcome.
6969

7070
## Release Integrity
7171

72-
Commits and tags on this fork are signed with the maintainer's SSH key.
73-
GitHub shows verified commits as "Verified"; to verify locally, add the
74-
maintainer's public signing key to an SSH allowed-signers file and run
75-
`git log --show-signature` or `git verify-commit <rev>`.
72+
Commits on this fork are signed with the maintainer's SSH key. GitHub shows
73+
them as "Verified"; to verify locally, add the maintainer's public signing key
74+
to an SSH allowed-signers file and run `git log --show-signature` or
75+
`git verify-commit <rev>`. The CalVer release tags are created by CI
76+
(`release-tag.yml`) as annotated but **unsigned** tags — a tag name is a
77+
convenience pointer, not a signature. Verify the *commit* a tag points at, and
78+
pin by commit hash + `narHash` (below) rather than by tag name.
7679

7780
Because this fork is consumed as a flake input, integrity ultimately comes
7881
from your `flake.lock`: it records the exact commit and its content hash

‎docs/configuration.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ You now have access to deployment commands:
1515

1616
## Updating nix-bitcoin
1717
Run `update-nix-bitcoin` from the deployment shell.\
18-
This fetches the latest release, verifies its signatures and updates `nix-bitcoin-release.nix`.
18+
This resolves the fork's latest `release` tag to its commit, prefetches that
19+
commit's tarball hash and rewrites `nix-bitcoin-release.nix`. Review the diff
20+
of the pinned commit before deploying — tags are unsigned pointers, commits
21+
are signed (see `SECURITY.md`). Flake users: `nix flake update nix-bitcoin`
22+
against `github:ostermayer/nix-bitcoin/release` instead.
1923

2024
# Customizing your configuration
2125

‎docs/install.md‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,28 @@ You can also build Nix from source by following the instructions at https://nixo
220220
cp -r ../nix-bitcoin/examples/{configuration.nix,shell.nix,krops,.gitignore} .
221221
```
222222
223-
3. Obtain the hash of the latest nix-bitcoin release
223+
3. Pin the fork release to deploy
224+
225+
This is a maintained fork: do **not** use upstream fort-nix release
226+
tarballs (they lack the fork's fixes; `helper/fetch-release` refuses to
227+
run for that reason). Pin a commit of this fork instead — the deployment
228+
shell's `update-nix-bitcoin` command writes `nix-bitcoin-release.nix` for
229+
you from the latest `release` tag, or do it by hand:
224230
225231
```
226-
../nix-bitcoin/helper/fetch-release > nix-bitcoin-release.nix
232+
commit=$(git -C ../nix-bitcoin rev-parse release) # or any reviewed commit
233+
hash=$(nix-prefetch-url --unpack "https://github.com/ostermayer/nix-bitcoin/archive/$commit.tar.gz")
234+
cat > nix-bitcoin-release.nix <<EOF
235+
builtins.fetchTarball {
236+
url = "https://github.com/ostermayer/nix-bitcoin/archive/$commit.tar.gz";
237+
sha256 = "$hash";
238+
}
239+
EOF
227240
```
228241
242+
Release tags are unsigned CI pointers; the commit is what you review and
243+
pin (see `SECURITY.md`).
244+
229245
#### Optional: Specify the system of your node
230246
This enables evaluating your node config on a machine that has a different system platform
231247
than your node.\

‎examples/importable-configuration.nix‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
let
99
# FIXME:
10-
# Overwrite `builtins.fetchTarball {}` with the output of
11-
# command ../helper/fetch-release
12-
nix-bitcoin = builtins.fetchTarball {};
10+
# Pin a commit of this fork (NOT an upstream fort-nix release — those lack
11+
# the fork's fixes). Get the hash with
12+
# nix-prefetch-url --unpack https://github.com/ostermayer/nix-bitcoin/archive/<commit>.tar.gz
13+
# or let `update-nix-bitcoin` in the deployment shell write it for you.
14+
nix-bitcoin = builtins.fetchTarball {
15+
url = "https://github.com/ostermayer/nix-bitcoin/archive/<commit>.tar.gz";
16+
sha256 = "<hash>";
17+
};
1318
in
1419
{ config, pkgs, lib, ... }: {
1520
imports = [

‎helper/makeShell.nix‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,27 @@ pkgs.stdenv.mkDerivation {
6363
}
6464
6565
update-nix-bitcoin() {(
66+
# Fork-native pin: resolve the fork's latest CalVer release tag to the
67+
# commit it points at, prefetch that commit's tarball and rewrite
68+
# nix-bitcoin-release.nix. Never fetches upstream fort-nix releases
69+
# (they lack this fork's fixes). Tags are unsigned CI pointers — the
70+
# commit is what you review; see SECURITY.md.
6671
set -euo pipefail
6772
releaseFile="${cfgDir}/nix-bitcoin-release.nix"
73+
repo=https://github.com/ostermayer/nix-bitcoin
74+
tag=$(git ls-remote --tags --refs "$repo" 'refs/tags/20*' | sed 's|.*refs/tags/||' | sort -V | tail -n1)
75+
[[ $tag ]] || { echo "No release tag found on $repo" >&2; exit 1; }
76+
commit=$(git ls-remote "$repo" "refs/tags/$tag^{}" | cut -f1)
77+
[[ $commit ]] || commit=$(git ls-remote "$repo" "refs/tags/$tag" | cut -f1)
78+
url="$repo/archive/$commit.tar.gz"
79+
hash=$(nix-prefetch-url --unpack "$url" 2>/dev/null)
80+
new=$(printf 'builtins.fetchTarball {\n # fork release %s\n url = "%s";\n sha256 = "%s";\n}\n' "$tag" "$url" "$hash")
6881
current=$(cat "$releaseFile" 2>/dev/null || true)
69-
new=$(fetch-release)
70-
if [[ $new == $current ]]; then
71-
echo "nix-bitcoin-release.nix already contains the latest release"
82+
if [[ $new == "$current" ]]; then
83+
echo "nix-bitcoin-release.nix already pins $tag ($commit)"
7284
else
73-
echo "$new" > "$releaseFile"
74-
echo "Updated nix-bitcoin-release.nix"
85+
printf '%s' "$new" > "$releaseFile"
86+
echo "Pinned $tag ($commit) in nix-bitcoin-release.nix — review that commit before deploying"
7587
if [[ $isInteractive ]]; then
7688
exec nix-shell
7789
fi

‎modules/lnd.nix‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ in {
298298
${pkgs.coreutils}/bin/head -c 65536 |\
299299
${pkgs.jq}/bin/jq -ce '.macaroon | strings' | ${pkgs.xxd}/bin/xxd -p -r > "$macaroonTmp"
300300
chown ${cfg.macaroons.${macaroon}.user}: "$macaroonTmp"
301-
${pkgs.coreutils}/bin/mv -f "$macaroonTmp" "$RUNTIME_DIRECTORY/${macaroon}.macaroon"
301+
# -T: the destination is a path lnd controls; without -T a
302+
# symlink-to-directory planted there would make root move the
303+
# file INTO that directory under the fixed basename instead of
304+
# replacing the path (second opinion 2026-09-09).
305+
${pkgs.coreutils}/bin/mv -fT -- "$macaroonTmp" "$RUNTIME_DIRECTORY/${macaroon}.macaroon"
302306
'') (attrNames cfg.macaroons)}
303307
'';
304308
in [

‎modules/presets/wireguard.nix‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,14 @@ in {
160160
iptables -w -A nixos-fw -i wg-nb -p tcp -s ${peerAddress}/32 --dport ${toString lnd.restPort} -j nixos-fw-accept
161161
''
162162
+ optionalString cfg.restrictPeer ''
163-
iptables -w -A nixos-fw ${restrictPeerRule}
164-
iptables -w -A FORWARD ${restrictPeerRule}
163+
# Insert at the top: appended (-A) the REJECT would sit behind the
164+
# standard accept rules (allowed ports, the REST accept above), so a
165+
# peer could still reach any firewall-allowed port on the node's
166+
# other addresses through the tunnel (second opinion 2026-09-09).
167+
# Replies to server-initiated traffic are unaffected: their
168+
# destination is serverAddress.
169+
iptables -w -I nixos-fw 1 ${restrictPeerRule}
170+
iptables -w -I FORWARD 1 ${restrictPeerRule}
165171
'';
166172

167173
extraStopCommands =

‎modules/secrets/secrets.nix‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,35 @@ in {
175175
# - Make all other secrets accessible to root only
176176
# For all steps make sure that no secrets are copied to the nix store.
177177
#
178+
# The secrets dir must exist before the sandboxed service starts:
179+
# ReadWritePaths= refuses a missing path.
180+
systemd.tmpfiles.rules = mkIf cfg.setupSecrets [
181+
"d '${cfg.secretsDir}' 0700 root root - -"
182+
];
183+
178184
systemd.services.setup-secrets = mkIf cfg.setupSecrets {
179185
requiredBy = [ "nix-bitcoin-secrets.target" ];
180186
before = [ "nix-bitcoin-secrets.target" ];
181187
serviceConfig = {
182188
Type = "oneshot";
183189
RemainAfterExit = true;
190+
# Scoped root sandbox (audit 2026-09-09, low): this is the one root
191+
# service that generates and re-permissions every secret on the box.
192+
# It needs to write exactly one directory and to chown/chmod files it
193+
# does not own — nothing else. No network, no new privileges, no
194+
# writable / outside the secrets dir.
195+
ProtectSystem = "strict";
196+
ReadWritePaths = [ cfg.secretsDir ];
197+
ProtectHome = true;
198+
PrivateTmp = true;
199+
NoNewPrivileges = true;
200+
RestrictAddressFamilies = [ "AF_UNIX" ];
201+
RestrictNamespaces = true;
202+
LockPersonality = true;
203+
ProtectKernelTunables = true;
204+
ProtectKernelModules = true;
205+
ProtectControlGroups = true;
206+
CapabilityBoundingSet = [ "CAP_CHOWN" "CAP_FOWNER" "CAP_DAC_OVERRIDE" "CAP_DAC_READ_SEARCH" ];
184207
};
185208
script = ''
186209
# Use the same sort order for globbing and sorting as in Nix attrsets.

‎test/ci/cve-scan.sh‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ if [ "$rc" -ne 0 ] && [ "$rc" -ne 2 ]; then
5555
fi
5656
jq -e 'type == "array"' vulnix-report.json >/dev/null 2>&1 \
5757
|| { echo "vulnix produced no valid JSON (rc=$rc) — not reporting a result"; exit 1; }
58+
# Shape check on the entries too: a malformed element (e.g. affected_by not an
59+
# array) would make the counting expression below throw, and an error there
60+
# must never read as "0 findings" (second opinion 2026-09-09, low).
61+
jq -e 'all(.[]; type == "object" and ((.affected_by // []) | type == "array") and ((.whitelisted // []) | type == "array"))' vulnix-report.json >/dev/null 2>&1 \
62+
|| { echo "vulnix report entries have an unexpected shape — not reporting a result"; exit 1; }
5863

5964
# Summarize with the runner's native jq (present on GitHub runners and pop-os).
6065
# vulnix --json fields: `affected_by` holds only the ACTIVE (non-whitelisted)
@@ -65,20 +70,23 @@ jq -e 'type == "array"' vulnix-report.json >/dev/null 2>&1 \
6570
# CVE and a genuinely new one — defeating the per-CVE scoping policy.
6671
real='[.[] | select(((.affected_by // []) | length) > 0)]'
6772
maxcvss='(([.cvssv3_basescore // {} | .[]] | max) // 0)'
68-
count=$(jq "$real | length" vulnix-report.json 2>/dev/null || echo 0)
73+
count=$(jq "$real | length" vulnix-report.json) \
74+
|| { echo "cannot count findings in vulnix-report.json — not reporting a result"; exit 1; }
75+
[[ $count =~ ^[0-9]+$ ]] || { echo "non-numeric finding count '$count' — not reporting a result"; exit 1; }
6976
{
7077
echo "# CVE scan — $(date -u +%Y-%m-%dT%H:%MZ)"
7178
echo
72-
echo "Scanned: representative node toplevel (bitcoind + lnd + electrs + btcpayserver + nbxplorer), runtime closure"
79+
echo "Scanned: representative node toplevel (secure-node preset: tor, operator; bitcoind + lnd + electrs + btcpayserver + nbxplorer + backups), runtime closure"
7380
echo "Affected store paths with non-whitelisted CVEs: **$count**"
7481
echo
7582
if [ "$count" != 0 ]; then
7683
# shellcheck disable=SC2016 # jq program, not shell — \(...) is jq syntax
7784
jq -r "$real | map(. + {_m: $maxcvss}) | sort_by(-._m) | .[] | \"## \(.pname // .name) \(.version // \"\") — CVSS \(._m)\n- \((.affected_by // []) | join(\", \"))\"" \
7885
vulnix-report.json
7986
echo
80-
echo "Triage: fix in \`pkgs/overrides.nix\` (version-guarded); whitelist test/build"
81-
echo "tooling (this scans the full test closure) or N/A CVEs in \`.github/cve-whitelist.toml\`."
87+
echo "Triage: fix in \`pkgs/overrides.nix\` (version-guarded); whitelist only vulnix"
88+
echo "pname collisions or CVEs that are N/A to this runtime closure in \`.github/cve-whitelist.toml\`"
89+
echo "(this scans the node's RUNTIME closure, so build tooling should not appear — if it does, find out why)."
8290
else
8391
echo "No action needed."
8492
fi

‎test/ci/scan-node.nix‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Representative nix-bitcoin node with all shipped services enabled.
1+
# Representative nix-bitcoin node: the secure-node preset plus every shipped
2+
# service and backups — i.e. the recommended deployment.
23
#
34
# CVE-scan target (test/ci/cve-scan.sh): vulnix scans this system's RUNTIME
45
# closure — the software a user actually runs (bitcoind, lnd, electrs,
@@ -15,8 +16,16 @@ in
1516
system = "x86_64-linux";
1617
modules = [
1718
f.nixosModules.default
19+
# The recommended deployment, not the bare service set: secure-node pulls
20+
# in tor (client + onion services — the largest continuously exposed
21+
# parsing surface on a real node), the operator/doas setup and the preset
22+
# infrastructure; backups adds duplicity. Without these the scan silently
23+
# skipped exactly the components a deployed node exposes (audit
24+
# 2026-09-09, medium).
25+
"${f.outPath}/modules/presets/secure-node.nix"
1826
{
1927
nix-bitcoin.generateSecrets = true;
28+
services.backups.enable = true;
2029
services.bitcoind.enable = true;
2130
services.lnd.enable = true;
2231
services.electrs.enable = true;

0 commit comments

Comments
 (0)