Repository navigation
btcpayserver: create the admin account before BTCPay opens its port - #278
Conversation
viberaven
left a comment
There was a problem hiding this comment.
Reviewed 4dbf53430da5.
No actionable findings. Checked the bootstrap's private network namespace, service ordering, password handling, existing-admin query, and registration response handling against the pinned BTCPay source.
Local module-config, test-runner, and mdBook builds pass. I also ran an additional NixOS VM test on this head with rootpath = "/payments", a custom BTCPay user and group, and regtest bitcoind. It verified that first startup creates exactly one server admin, the prefixed health endpoint works, rerunning btcpayserver-admin with an existing admin succeeds without adding another admin, and BTCPay starts successfully afterward. The VM test passed. I inspected the PR's anonymous-registration assertions and green CI results; I did not rerun the entire standard scenario matrix.
Review performed with Codex (GPT-6 Astra).
4dbf534 to
abe7644
Compare
BTCPay Server makes the first account that registers the server admin, which can use the internal Lightning node and install plugins. bitcoinix started BTCPay without an admin, so until the operator registered, any local user or a service that can reach the port could register first. Neither BTCPay's web form nor its Greenfield API needs a token for that first account, and `disable-registration` only applies once it exists. The new unit btcpayserver-admin runs before each start of btcpayserver. When the database has no admin, it starts BTCPay in a private network namespace, which no other process can reach, creates the admin `admin@localhost` through the Greenfield API with the password in the new secret btcpayserver-admin-password, and stops BTCPay. btcpayserver requires the unit, so it doesn't open its port before an admin exists. BTCPay then closes registration. Nodes that already have an admin keep it. Fixes bitcoinix#131. Assisted-by: Claude Code (Claude Opus 5.5)
abe7644 to
25cf58b
Compare
8b5343e to
25cf58b
Compare
Fixes #131.
BTCPay Server makes the first account that registers the server admin. That account can
use the internal Lightning node and install plugins. bitcoinix started BTCPay with no
admin, so until the operator registered, any local user, or a service that can reach the
port, could register first and take it. The window also covers the onion service and any
LAN or WireGuard address.
BTCPay 2.4.7 has no setting that closes it:
require a token or an invite for it.
disable-registration(default true) locks registration only once the first adminexists.
LockSubscriptionon before that blocks the web form, but notPOST /api/v1/users. While no admin exists, BTCPay treats an anonymous caller of theGreenfield API as an admin and lets it create one. The regtest test used exactly this
request until now.
At the network level, loopback can't tell local users apart.
IPAddressAllowfilters byaddress. netns-isolation lets every process in the host namespace reach the service
namespaces through the bridge. A UID owner match in the firewall would need an allow list
of every client (the operator's SSH tunnel, Tor, a reverse proxy) for both iptables and
nftables. BTCPay binds only to an address and port, so a Unix socket would mean a new
listener setup and would break the onion service and existing tunnels.
So this PR creates the admin before BTCPay opens its port:
btcpayserver-adminruns before each start ofbtcpayserver. If thedatabase has an admin, it exits.
PrivateNetwork), bound to127.0.0.1, which no other process can reach. It createsadmin@localhostthrough theGreenfield API with the password in the new secret
btcpayserver-admin-password, thenstops BTCPay. BTCPay then locks registration.
btcpayserverrequires the unit, so it doesn't start when the admin can't be created.services.btcpayserver.userand.group, so a custom user orgroup works with
setup-secrets.services.btcpayserver.rootpath, with/and atrailing
/treated like BTCPay does.bindin its config file and on its command line.Nodes that ran without an admin before this change may already have an admin that isn't
the operator's. The docs say how to check the admins in Server Settings > Users. An admin
that isn't yours could have installed plugins that run as the
btcpayserveruser anduse the Lightning node, so the docs say to treat the node as compromised: stop BTCPay
Server, move the funds to a wallet this node doesn't control and set up the node again.
They give no in-place recovery steps.
Docs: a new "Connect to BTCPay Server" section with "Check the admin accounts" in
docs/services.md, the 0.2.0 upgrade notes and release notes, the example config andthe BTCPay recipe in
dev/dev-features.sh. The old warning inexamples/configuration.nixabout creating the admin before enabling the onion service is gone, since the admin now
exists first.
The 0.2.0 notice is for every node with BTCPay. Nodes without an admin now sign in with
the generated account instead of registering. Nodes with an admin should check that it's
theirs. Setups that supply their own secrets must add the new one.
Testing
The
btcpayserverVM test now checks that:btcpayserver-adminruns withPrivateNetwork.admin@localhostwith the generated password is aServerAdmin.POST /api/v1/usersgets 401, with and withoutisAdministrator./registerredirects.Before this change, the anonymous request created the first admin. The regtest test
relied on it. That test now signs in as the generated admin for its Greenfield request.
BTCPay accepts Basic auth only in an account's first five minutes, so a test helper
resets the account's creation time before each request.
New eval tests in
test/configuration.nix:exist.
rootpathnull,/,btcpay,/btcpayandbtcpay/.Results:
regtestVM scenario: pass.netnsRegtestVM scenario: pass on an earlier revision of this branch, without thelast fixes. That run checked the
bindhandling in a service namespace: the configfile's
bindis the namespace address, so the setup instance gets its own config withbind=127.0.0.1. An earlier version passed--bind=127.0.0.1on the command line andfailed in both scenarios.
shellcheck-servicesbuild in the VM scenarios covers the new unit script.checks.x86_64-linux.module-configandchecks.x86_64-linux.test-runner: pass.Not tested: the mainnet scenarios, a running node with
rootpath, and a rerun ofbtcpayserver-adminon a node that already has an admin.module-config,test-runner,ci-workflows,shellcheckandregtestpass on the KVM host. On master, the notice is a warning until 0.2.0 is released, and the tests pass withversion.nixat 0.1.6 and at 0.2.0.Models
Claude Opus 5.5 wrote the change. Codex GPT-5.6 Sol, Codex GPT-6 Astra (two passes plus rechecks), Kimi K3.1 Pro (two passes), DeepSeek V4.1 Flash 1017 and GLM 5.3 reviewed it. Claude Opus 5.5 rebased it onto #224 and #283.