Repository navigation
bitcoind: add rest option - #135
Conversation
|
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)
840583c to
b70ce86
Compare
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)
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)
b70ce86 to
adf7a3a
Compare
|
added more changes suggested by Astra |
|
@prusnak Thanks for the changes :). I've done another round of review. Do you think it is worth adding One design point before merge:
Users who only hit check 2 have to turn off check 1 as well. Example: Proposal:
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. |
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)
electrs 0.12 reads blocks through bitcoind's REST interface, so bitcoind needs
rest=1. This addsservices.bitcoind.rest.enable(default off) ahead of theelectrs 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 orallowlist.
rpcallowipis the only access control (bitcoind checks it for every HTTPrequest, REST included). To keep REST from reaching beyond the node, evaluation fails
when REST is enabled and
rpc.allowipcontains sources other than localhost and thenetns-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:
credentials) and the host through the bridge, i.e. any local user on the host
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:
rpc.allowipsource. Theassertion must fail, and pass with
rest.allowNonLocal.bitcoind-restVM test:/restreturns 404 when disabled. When enabled, it isreachable from the host as an unprivileged user and, with netns isolation, not from
namespaces without a bitcoind connection. REST is enabled in the
regtestscenario,so CI covers both states (
default/netns: off,netnsRegtest: on).Ran
default,netnsandnetnsRegtestlocally: all passed.Also partially related to: