Repository navigation
Conversation
Add `services.barkd`, the REST daemon of bark (https://gitlab.com/ark-bitcoin/bark), a wallet for the Ark protocol built by Second. The package is `bark-wallet` from nixpkgs (pinned to nixpkgs-unstable). - Network (signet by default), Ark server URL, chain source (Esplora, or the local bitcoind via the `public` RPC user with `txindex` and `submitpackage`) - config.toml is written in preStart with `install -T -m 600`; the bitcoind RPC password never appears in argv - Wallet created on first start (`createWallet`), mnemonic kept in the data dir - `barkd-cli` for the operator (passes the bearer token via an fd) - Tor proxy/enforce, defaultHardening, netns-isolation (id 33), backups, nodeinfo, docs, README and example config - Tests: `barkd`, plus `rpc-whitelist`, `config-replace` and `netns-isolation` cases; barkd is enabled in the `full` and `regtest` scenarios The default REST port is 3030 because barkd's own default (3000) collides with RTL. Assisted-by: Claude Code (Claude Opus 5.5)
ostermayer
left a comment
There was a problem hiding this comment.
Thanks for the module. I read it with the test and checked the Tor behaviour against bark 0.7.1's source. Three things need a change before this ships, and a few smaller ones follow.
-
barkd isn't in
modules/presets/enable-tor.nix. On a secure-node the preset turns ontor.proxyandtor.enforcefor every service that talks out, but barkd gets neither, so it contacts the Ark server and the Esplora instance from the node's real IP. The defaults point at Second's servers on every network, so the counterparty the Ark model treats as untrusted learns the operator's IP.BARK_PLAN.mdlists this as open question 3. Addbarkd = defaultEnableTorProxy;there, but see the next point first. -
Wallet creation ignores the proxy.
bark-cli/src/wallet.rs:450builds its chain client withChainSource::new(chain_spec, net, None, None), then callschain.tip()andinitial_wallet_scanon it. With Esplora those requests go direct even whensocks5_proxyis set. barkd's RESTwallet/createruns the same function (bark-cli/src/bin/barkd/main.rs:436), so the restore path indocs/services.mdhas the same hole. Withtor.proxythe first start leaks the IP once. Withtor.enforcethe unit'sIPAddressAllowis local only, so creation fails and barkd never starts. The module can't fix this by itself. It needs a bark fix (passconfig.socks5_proxyintoChainSource::newincreate_wallet) or a patch inpkgs/. Until then the docs should say that wallet creation isn't proxied, and the enable-tor entry needs that fix first orcreateWalletbreaks under the preset. -
The assertion at
modules/barkd.nix:197rests on a wrong premise. The comment says bark bypasses the proxy only for loopback, so a non-local bitcoind can't be reached. In 0.7.1 the bitcoind backend never uses the proxy at all:bark/src/chain.rs:258says so and creates both RPC clients without it. The loopback bypass inbark/src/config.rs:177applies to the Ark server and Esplora URLs. Sotor.proxypluschainSource = "bitcoind"works with netns-isolation, because the RPC goes direct andtor.enforceallows169.254.0.0/16. That is the combination a secure-node operator wants: Tor for the Ark server, the local node for chain data. Drop the assertion, or replace it with a note that the bitcoind connection never goes through Tor.
Smaller points:
modules/barkd.nix:273addssubmitpackageto the sharedpublicRPC user, so lnd, clightning, electrs, fulcrum, nbxplorer and mempool get it too, and the btcpayserver user inherits it because its list is built from the public one. That is the pattern #127 describes. A dedicated RPC user for barkd, like btcpayserver has, keeps the grant with the service.config.tomlalready takesbitcoind_userandbitcoind_pass, so it is anix-bitcoin.secretsentry and arpc.users.barkdblock.modules/barkd.nix:223writesbitcoind_passinto TOML without escaping. Generated passwords arepwgenalphanumeric, so they are fine, but a hand-placed password with"or\produces a config bark can't parse. Either escape it or say in the option docs that the password must not contain those.BARK_PLAN.mdsays about itself that it should be dropped before the branch leaves draft. The open questions fit the PR description.services.backupsnow copiesdb.sqlitelive. Same class as #95, so nothing new to fix here, but worth knowing when a restore fails.
Checked and fine: preStart runs as the service user and install -T replaces config.toml without following a symlink, the token reaches curl through a file descriptor, netns id 33 and its connections match the chain source, extraArgs isn't shell-evaluated, and the test covers the 401, the modes and the failed creation.
DeepSeek V4.1 Flash 1017 run at max reasoning and GLM 5.3 run at max reasoning reviewed the tree at 43a5c20. Both flagged the missing enable-tor entry, and DeepSeek flagged the inherited submitpackage grant. Codex (GPT-6 Astra, xhigh) read the diff and raised the creation path, the assertion and the TOML quoting, which I checked against bark 0.7.1's wallet.rs, chain.rs and barkd/main.rs.
Keep lowercase for code identifiers (`barkd`, the `bark` CLI, `bark-wallet`, `services.barkd`) and URLs. Assisted-by: Claude Code (Claude Opus 5.5)
Bark's `socks5_proxy` doesn't reach the chain source client that wallet creation builds (`bark create`, REST `wallet/create`), so with Esplora the first start contacted Esplora directly, and failed under `tor.enforce`. That client honours the standard proxy variables, so set `ALL_PROXY` (and `NO_PROXY` for local and netns addresses) when `tor.proxy` is enabled, until Bark passes `socks5_proxy` there itself. With creation proxied, add `barkd = defaultEnableTorProxy` to the enable-tor preset. Drop the assertion against `tor.proxy` with `chainSource = "bitcoind"`: its premise was wrong. Bark never sends bitcoind RPC through the proxy (bark/src/chain.rs), and the loopback bypass only applies to the Ark server and Esplora URLs, so the combination works with netns-isolation. The regtest scenario now enables `tor.proxy` to cover it. Assisted-by: Claude Code (Claude Opus 5.5)
Grant `submitpackage` to a new `barkd` RPC user instead of the shared `public` user, so lnd, clightning, electrs, fulcrum, mempool, nbxplorer and btcpayserver don't inherit it. The password is a `bitcoin-rpcpassword-barkd` secret, as for btcpayserver. Escape `\` and `"` when writing `bitcoind_pass` into config.toml, so hand-placed passwords still give a valid TOML string. Assisted-by: Claude Code (Claude Opus 5.5)
|
Thanks a lot for the careful review, and for checking everything against the 0.7.1 source. You were right on all three main points. Here's what changed:
Smaller points:
Tests: |
43a5c20 to
4b413cf
Compare
|
I read aec46d0 and 4b413cf against my review and the three main points are fixed. The enable-tor entry, the I ran the adversarial review on 4b413cf. GLM 5.3 (max reasoning) found nothing in the files this PR changes, but it reported two findings in The branch now conflicts with master in |
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Assisted-by: Claude Code (claude-sonnet-5-5)
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Assisted-by: Claude Code (claude-sonnet-5-5)
sebsgent
left a comment
There was a problem hiding this comment.
@mvuk thanks for the fixes, ostermayer confirmed them. Could you rebase onto current master and re-test on bark 0.8.1, which nixpkgs ships now? Since the branch was written, master has changed what the module plugs into:
Must
pkgs/pinned.nixis gone. Addbark-wallettopinnedinpkgs/default.nix, otherwise evaluation fails onnbPkgs.bark-wallet.- netns id 33 now belongs to
unbeholden-wallet, and the module doesn't check that ids are unique. After a rebase, both services silently get169.254.1.33. Use a free id. - Test bodies now live in
test/suite/, and each@testmust be listed inTEST_PHASESintest/tests.py, or the runner raises. - The service page now goes in
docs/service/barkd.md(listed indocs/SUMMARY.md), plus a release-note draft indocs/release-notes/<next milestone>/barkd.md.
Should
- With
chainSource = "esplora", the wallet scan sends every wallet address to the Esplora server, which on mainnet is Second's by default. Please say so in the docs and recommendchainSource = "bitcoind"for mainnet.
Optional
- Link ark-bitcoin/bark!2674 (still a draft) in the
TODO-EXTERNALcomment.
Checked on 0.8.1: the ALL_PROXY workaround is still needed and works. Without it, bark create connects directly to the Esplora server despite socks5_proxy. barkd's /ping, the 401, {"fingerprint":null} and the non-loopback bind behave as the test expects.
Assisted-by: Claude Code (Claude Opus 5.5)
…id, admin-credential docs) - Build the RPC cookie in a root-only mktemp -d and mv -fT it into place, so the service user cannot swap a symlink in /run/rbitcoin mid-write. - Use utils.escapeSystemdExecArgs for ExecStart so % and $ in extraArgs survive. - Move the rbitcoin netns id from 33 to 34 (also claimed by bitcoinix#141 and bitcoinix#2). - Document that the RPC cookie is an administrative credential and that mempool holds it, in the rpc.enable and electrumServer descriptions and docs/services.md. - Test that no cookie temp dir is left behind. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Assisted-by: Claude Code (claude-sonnet-5-5)
|
bark-wallet 0.9.0 merged to nixpkgs master, nixos-unstable channel being updated -> https://pr.bitcoinix.net/?pr=596295 |
Hi, I'm Matthew from Second, the team that builds Bark. Bark implements Ark,
a protocol for holding and sending bitcoin off-chain with an Ark server while
keeping a unilateral on-chain exit. The package is already in nixpkgs as
bark-wallet(0.7.1).Implemented (
modules/barkd.nix)services.barkd: network (signet by default), Ark server, chain source(Esplora, or the local bitcoind via the
publicRPC user plustxindexandsubmitpackage), REST address/port,createWallet, Tor proxy/enforce,defaultHardeningconfig.tomlviainstall -T -m 600and is never in argvbarkd-cli, netns-isolation (id 33), backups, nodeinfo, docs, README and exampleTested
barkdtest:/ping, 401 without a token, data dir 700 andconfig.toml600,barkd-clias operator, and a REST wallet create that passes the bitcoind checksrpc-whitelist,config-replaceandnetns-isolation-s barkd,-s regtest(this caught a port 3000 clash with RTL,so barkd now uses 3030), netns + regtest,
nix flake checkandshellcheck.shNext steps
barkCLI and a safe SQLite backupcaptaindI'm happy to change anything, or to open an issue first if you'd like to talk it through.