Skip to content

unbeholden-wallet: add allowedClients for remote reverse proxies - #285

Merged
prusnak merged 6 commits into
bitcoinix:masterfrom
unbeholdendev:unbeholden-wallet-allowed-clients
Nov 18, 2026
Merged

prusnak merged 6 commits into
bitcoinix:masterfrom
unbeholdendev:unbeholden-wallet-allowed-clients

Conversation

@unbeholdendev

Copy link
Copy Markdown
Contributor

Summary

I ran Unbeholden Wallet on bitcoinix behind an https reverse proxy on another host and the proxy could never connect, even with address = "0.0.0.0". The unit uses allowLocalIPAddresses, so systemd silently drops packets from any non-local address.

This adds services.unbeholden-wallet.allowedClients, IP addresses or networks appended to the unit's IPAddressAllow:

services.unbeholden-wallet = {
  address = "0.0.0.0";
  allowedClients = [ "192.0.2.10" ];
  allowedHosts = [ "wallet.example.com" ];
};
networking.firewall.allowedTCPPorts = [ 60846 ];

It's a list rather than any because IPAddressAllow also filters outgoing traffic, and the wallet only needs the local Electrum server. Entries must be IP addresses or networks, since systemd ignores ones it can't parse. An assertion rejects the option with netns-isolation, which drops LAN connections anyway. Docs and 0.2.0 release notes are updated.

Evidence

The unbeholden-wallet-electrs scenario allows 192.0.2.1 and connects from two local addresses:

curl --interface 192.0.2.1 192.0.2.1:60846   must return 200
curl --interface 192.0.2.2 192.0.2.1:60846   must fail
  • Before: the allowed request timed out (curl exit 28).
    After: passes in the electrs and fulcrum scenarios, and the netns scenario is unchanged. test/configuration.nix checks the address validation and the netns assertion.

The tor-enforce test now accepts each unit's extra allowed addresses. The basic scenarios and nixos-search weren't run locally.

Merge Danger

Door: two-way

Blast Radius: small

The option defaults to [], so existing configs behave as before.

The unit only allowed local IP addresses, so a reverse proxy on another
host got no answer even with `address = "0.0.0.0"`. `allowedClients`
adds addresses to the unit's IPAddressAllow. It is rejected with
netns-isolation, whose namespaces drop LAN connections.

Assisted-by: Claude Code (claude-opus-5-5)
systemd ignores entries of IPAddressAllow it can't parse, so a host
name or typo would silently keep the client blocked.

Assisted-by: Claude Code (claude-opus-5-5)
@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix labels Nov 17, 2026
@viberaven

Copy link
Copy Markdown
Contributor

Reviewed head de02a412b16627ca5bc8aba9936071022694f96d. I found one validation issue and two lower-priority test issues:

  1. [P2] Validate IPv6 structure, not just its character set — modules/unbeholden-wallet.nix:47–48. The IPv6 branch accepts malformed addresses such as 2001:db8:::1, 2001:db8::12345, and 2001:db8:1. I evaluated each through the actual module: all reach IPAddressAllow successfully. systemd-analyze verify then reports Invalid address prefix … ignoring assignment for each. A typo therefore still deploys successfully and leaves the proxy blocked, defeating the validation added in the second commit. Please validate group counts, group lengths, and compression syntax, and add malformed-address cases alongside the existing prefix-length checks. This fails closed; it is not an access-control bypass.

  2. [P3] Normalize addresses before comparing systemd's allowlist — test/suite/networking.py:137–138. With the supported allowedClients = [ "192.0.2.1" ], systemd reports 192.0.2.1/32, but extraAllow contains the original bare address. I reproduced the resulting assertion failure in the VM; the service's allowlist is correct. The current /32 fixture hides this. Canonicalize the expected addresses/networks before comparison and cover the bare-address spelling used in the documentation.

  3. [P3] Keep the denied probe outside the configured networks — test/suite/services.py:381–387. With the documented allowedClients = [ "192.0.2.0/24" ], the hardcoded denied client 192.0.2.2 is actually allowed. In the VM, the curl succeeds correctly and machine.fail rejects it. Also, a list containing two distinct IPv4 clients tries to add that same denied address twice. Either make these probes specific to the fixture scenario or select/setup probe addresses once, accounting for the complete allowlist. Valid network/list configurations should not produce false test failures.

Validation: module-config and test-runner checks passed, and the unchanged unbeholden-wallet-electrs VM scenario passed locally. The two test failures above were reproduced separately using this PR's test bodies in its VM with the corresponding runtime allowlists/test data. Other VM scenarios were not rerun locally; the PR's CI gate is green.

Comment thread modules/unbeholden-wallet.nix Resolved
The regex accepted malformed IPv6 addresses anyway. A proper address
type can come later in nbLib; systemd ignores entries it can't parse.

The tests now normalise bare addresses before comparing systemd's
allowlist, and probe the denied client from outside every allowed
network.

Assisted-by: Claude Code (claude-opus-5-5)
@unbeholdendev

Copy link
Copy Markdown
Contributor Author

Thanks @viberaven. Addressed in 5a5fa48:

  1. Superseded: per @prusnak's comment the option is now listOf str, so there is no regex left to tighten. A proper address type can come later in nbLib.
  2. Fixed: expected entries are normalised with ipaddress.ip_network(..., strict=False), and the fixture now uses the bare 192.0.2.1.
  3. Fixed: the denied probe is 198.51.100.1, added once and asserted to be outside every allowed network.

The electrs, fulcrum and electrs-netns scenarios pass locally.

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 18, 2026
@viberaven

Copy link
Copy Markdown
Contributor

Re-reviewed 5a5fa4880b4062ded442187f11caf065b79423d1, including the discussion about deferring address validation.

The earlier validation finding is superseded by the agreed listOf str design; the option now documents systemd's handling of malformed entries. The original bare-address, 192.0.2.0/24, and two-distinct-client cases now pass. I found no new service/runtime blocker, but two low-priority test issues remain:

  1. [P3] Account for redundant entries when comparing allowlists — test/suite/networking.py:138–141. Systemd also removes addresses covered by a broader allowed network. With the option's own example, [ "192.0.2.10" "192.0.2.0/24" ], it reports only 192.0.2.0/24 plus the localhost entries, while expected_allow still includes 192.0.2.10/32. I reproduced the assertion failure in the VM. Remove subsumed entries from the expected list, or compare equivalent network coverage on both sides, and cover this overlapping-list case.

  2. [P3] The denied probe still depends on the configured subnet — test/suite/services.py:384–386. Moving the probe to 198.51.100.1 fixes the original example, but allowedClients = [ "198.51.100.0/24" ] now fails the added assertion despite being a valid configuration. I reproduced that too. Please either restrict these fixed-address probes to their dedicated scenario or choose a denied address outside the actual allowlist. The assertion detects the fixture conflict but still makes the generic service test reject a valid configuration.

Validation: local module-config and test-runner checks passed, and the full unbeholden-wallet-electrs VM scenario passed. Additional VM probes exercised the subnet, multiple-client, overlapping-list, and denied-address cases using this revision's test bodies and matching runtime allowlists/test data. Other VM scenarios were not rerun locally; CI is green.

systemd drops IPAddressAllow entries covered by a broader network, so
the expected list does too; the electrs scenario now covers an
overlapping list. The remote-client probe uses addresses set by its
scenario, so other valid allowedClients no longer fail it.

Assisted-by: Claude Code (claude-opus-5-5)
Assisted-by: Claude Code (claude-opus-5-5)
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@unbeholdendev

Copy link
Copy Markdown
Contributor Author

Fixed in d8458fb, and merged master (only conflict: release notes).

  1. The expected allowlist now drops entries covered by a broader one in the same family, as systemd does. unbeholden-wallet-electrs now uses [ "192.0.2.1" "192.0.2.0/24" ] to cover the overlapping case.
  2. The client probes take their addresses from test.data.unbeholden-wallet-clients, which only that scenario sets, so other valid allowedClients aren't probed.

Validation: module-config and test-runner checks, and the unbeholden-wallet-electrs VM scenario (unbeholden-wallet and tor-enforce tests) pass locally.

@viberaven

Copy link
Copy Markdown
Contributor

Re-reviewed d8458fbc2258d55591b455707e975f48668967e2, including the merge from master. No new actionable findings; both remaining review comments are resolved.

  • The expected allowlist now removes entries covered by broader networks within the same address family. The updated Electrs scenario exercises overlapping entries and passes the systemd comparison.
  • Fixed client probes are now explicitly enabled by their scenario. A separate configuration with allowedClients = [ "198.51.100.0/24" ] passes without inheriting an incompatible denied probe.

Local validation passed:

  • module-config and test-runner checks.
  • Full unbeholden-wallet-electrs VM scenario.
  • Full custom VM scenario based on regtestBase, enabling the wallet with address = "0.0.0.0" and allowedClients = [ "198.51.100.0/24" ], without the scenario-specific probe data.

CI is green at this head. Other VM scenarios were not rerun locally. Address validation remains intentionally deferred per the earlier maintainer discussion.

@prusnak
prusnak merged commit f418db6 into bitcoinix:master Nov 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants