Skip to content

bitcoind: add rest option - #135

Merged
prusnak merged 7 commits into
masterfrom
bitcoind/rest
Oct 23, 2026
Merged

prusnak merged 7 commits into
masterfrom
bitcoind/rest

Conversation

@seberm

@seberm seberm commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

electrs 0.12 reads blocks through bitcoind's REST interface, so bitcoind needs
rest=1. This adds services.bitcoind.rest.enable (default off) ahead of the
electrs 0.12 update.

REST is served on the RPC address and port without authentication. It bypasses
RPC users and rpcwhitelist, and Bitcoin Core 31 has no separate REST bind or
allowlist. rpcallowip is the only access control (bitcoind checks it for every HTTP
request, REST included). To keep REST from reaching beyond the node, evaluation fails
when REST is enabled and rpc.allowip contains sources other than localhost and the
netns-isolation addresses. Users who expose RPC to their LAN must opt in with
services.bitcoind.rest.allowNonLocal = true.

Who can reach REST once it is enabled:

  • with netns isolation: the namespaces connected to bitcoind (they already have RPC
    credentials) and the host through the bridge, i.e. any local user on the host
  • without netns isolation: localhost, i.e. any local user

REST is read-only (blocks, transactions, UTXO set, mempool; no wallet access). The
remaining local exposure is unauthenticated read access and the load of heavy requests
such as /rest/getutxos.

The bitcoind service sandbox is unchanged. Nothing changes unless the option is
enabled, so there is no versioning entry.

Tests:

  • Nix: the test config is re-evaluated with REST and a LAN rpc.allowip source. The
    assertion must fail, and pass with rest.allowNonLocal.
  • New bitcoind-rest VM test: /rest returns 404 when disabled. When enabled, it is
    reachable from the host as an unprivileged user and, with netns isolation, not from
    namespaces without a bitcoind connection. REST is enabled in the regtest scenario,
    so CI covers both states (default/netns: off, netnsRegtest: on).

Ran default, netns and netnsRegtest locally: all passed.

Also partially related to:

@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 Oct 23, 2026
@seberm
seberm marked this pull request as draft October 23, 2026 08:40
@seberm
seberm requested a review from prusnak October 23, 2026 09:02
@seberm
seberm marked this pull request as ready for review October 23, 2026 09:02
@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Just rebased on top of the current master.

Add `services.bitcoind.rest.enable`, needed by electrs 0.12.

bitcoind serves REST on the RPC address and port without
authentication, bypassing RPC users and `rpcwhitelist`; `rpcallowip`
is the only access control, and Bitcoin Core has no separate REST
bind. Refuse to enable REST when `rpc.allowip` contains sources other
than localhost and the netns-isolation addresses, unless
`rest.allowNonLocal` is set explicitly.

Assisted-by: Claude Code (Claude Opus 5.5)
Check that REST is refused at evaluation time for non-local
`rpc.allowip` sources unless `rest.allowNonLocal` is set, that it
returns 404 when disabled, and that it is reachable from the host but
not from network namespaces without a bitcoind connection when
enabled. Enable REST in the regtest scenarios so CI covers both cases.

Assisted-by: Claude Code (Claude Opus 5.5)
Check the data path, not only that REST is enabled: fetch the genesis
block hash by height and the block itself in JSON and in the binary
format that electrs uses.

Assisted-by: Claude Code (Claude Opus 5.5)
Set each fixture's allowlist and opt-in explicitly, overriding even
mkForce definitions in the scenario. Report failed cases by name through
one Python assertion.

Validated explicit and forced true/false settings, a forced localhost
allowlist, and a scenario with REST forced off.

Assisted-by: OpenAI Codex (GPT-6)
Require rest.allowNonLocal for rpcallowip or includeconf directives in
extraConfig, including section-qualified and negated keys. Document the
checked rpc.allowip option and the explicit opt-in for raw settings.

Named evaluation cases cover raw directives, whitespace, sections,
includes, comments, the opt-in, and REST disabled. They pass in default,
netns, regtest and netnsRegtest, including inherited-setting regressions.

Assisted-by: OpenAI Codex (GPT-6)
@seberm seberm mentioned this pull request Oct 23, 2026
2 tasks done
Add 127.0.0.0/8, 127.0.0.1/32 and ::1/128 to the existing explicit
loopback list. Document the accepted spellings and cover them with
named cases that also reject the broader /7 and /127 ranges.

REST evaluation cases and scenario overrides pass. Flake checks for
all systems, CI test-derivation evaluation, Python syntax and mdBook pass.

Assisted-by: OpenAI Codex (GPT-6)
@prusnak

prusnak commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

added more changes suggested by Astra

@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@prusnak Thanks for the changes :).

I've done another round of review. Do you think it is worth adding allowUncheckedConfig?


One design point before merge: rest.allowNonLocal is now the only way past two separate checks:

  1. rpc.allowip contains non-local sources, and the user accepts that they get unauthenticated REST.
  2. extraConfig contains rpcallowip/includeconf, so the module can't check the effective allowlist.

Users who only hit check 2 have to turn off check 1 as well. Example: rpcauth kept in a separate file via includeconf=, plus a LAN source in rpc.allowip for an authenticated remote RPC client. Once REST is enabled, the error points them to allowNonLocal = true. That passes evaluation, and now the whole LAN gets unauthenticated REST, not only the included file's settings. This gets more likely once electrs 0.12 support enables REST automatically: users don't opt in themselves, they just hit the assertion on update.

Proposal:

  • Add services.bitcoind.rest.allowUncheckedConfig (bool, default false). It skips only the extraConfig scan.
  • The scan assertion passes on allowNonLocal || allowUncheckedConfig. allowNonLocal already accepts REST from every RPC source, so it can keep covering raw sources too, and rawOptIn stays valid.
  • The rpc.allowip assertion keeps depending on allowNonLocal only.
  • The scan's error message points to allowUncheckedConfig.
  • New case: allowUncheckedConfig = true with includeconf and a LAN allowip is still refused.
  • Option description and docs/configuration.md updated to match.

The option isn't released yet, so the split is free now. Changing it later would need a versioning entry. Happy to push this as a commit on top if you prefer.

@prusnak

prusnak commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Happy to push this as a commit on top if you prefer.

Feel free to apply your changes - you spent more time with this feature than me, so your intuition is much better than mine.

Raw `rpcallowip` and `includeconf` directives in extraConfig could only
be accepted with `rest.allowNonLocal`, which also disables the check of
`rpc.allowip`. A user with an included secrets file and a LAN RPC source
would thereby grant the LAN unauthenticated REST access.

Add a separate opt-in that skips only the extraConfig scan.
`allowNonLocal` keeps accepting raw directives as well.

Assisted-by: Claude Code (Claude Opus 5.5)
@seberm

seberm commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@prusnak added changes in:

Please recheck, If ok, i think you can merge.

@prusnak
prusnak merged commit dbeb545 into master Oct 23, 2026
9 checks passed
@prusnak
prusnak deleted the bitcoind/rest branch October 23, 2026 14:21
@seberm seberm added the type: feature New capability or service label Oct 23, 2026
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 type: feature New capability or service

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants