Repository navigation
bitcoind: let the group read new block files with dataDirReadableByGroup - #305
Conversation
sebsgent
left a comment
There was a problem hiding this comment.
No must/should items.
The ACL is limited to the blocks dir, and the group still can't read chainstate. The remaining race between the -L check and chmod -R (which follows a symlink given as its argument) can't reach anything beyond the data dir and /run/bitcoind, because of ProtectSystem=strict. That's the same rename exposure the PR body already names, so it fits the follow-up for a data dir the group can't write.
Tested: CI green, including bitcoindGroupRead. Checked locally that with the default ACL and umask 077, new files get 0640 and new subdirs 0750 and inherit the ACL, and that setfacl -P refuses a symlink argument.
Assisted-by: Claude Code (Claude Opus 5.5)
sebsgent
left a comment
There was a problem hiding this comment.
Approving per the review above.
Assisted-by: Claude Code (Claude Opus 5.5)
viberaven
left a comment
There was a problem hiding this comment.
The standalone bitcoindGroupRead VM and the module-config and test-runner checks passed locally on x86_64-linux. I’m requesting changes because I also reproduced a group-read failure with an existing ACL, an LND start-limit failure in a combined scenario, and an evaluation error in the documented migration. The inline comments include the fixes and the permission-handling details.
The branch currently has merge conflicts with master in test/run-tests.sh and test/tests.nix.
Assisted-by: Codex (gpt-6.2-astra)
db4618d to
ce87711
Compare
|
Thanks for the review. All in ce87711, rebased onto master.
Tests on a KVM host. |
viberaven
left a comment
There was a problem hiding this comment.
The revision addresses all five findings from my previous review. The dedicated regtest VM passed with the existing ACL and symlink cases, a separate group-read VM with LND passed, and the upgrade example generated the expected /etc/fstab entry. I also verified the fallback on btrfs mounted with noacl and ran the module-config and test-runner checks.
One startup regression remains for nodes with an on-demand blocks mount. I reproduced it on first start and verified the mount dependency suggested inline.
Assisted-by: Codex (gpt-6.2-astra)
viberaven
left a comment
There was a problem hiding this comment.
Apply these two suggestions together to make the ACL helper wait for the blocks mount on mainnet and regtest. The path quoting follows the Core Lightning replication module.
Assisted-by: Codex (gpt-6.2-astra)
Bitcoin Core sets umask 077 at startup and has had no sysperms setting since 25.0. So with dataDirReadableByGroup, every file that bitcoind created while it ran had mode 0600, and the group lost access to new blocks until the next restart. On regtest, the option did nothing, because preStart looked for the blocks dir in the wrong place. Set a default ACL on the blocks dir and the dirs in it. Below such a dir, the ACL takes the place of the umask, so new files are readable by the group. Create the dir first, so this also covers the files of the first start, and create regtest/wallets with it like Core would. If a step fails, for example on a filesystem without ACL support, log a warning and start bitcoind anyway, so a node doesn't go down over read access for another program. The admin may have set ACLs there already, for example for a backup group. chmod g+rX changes only the mask of such an ACL, so the owning group can stay locked out while named entries gain rights, and setfacl -m recalculates the mask from all entries. So read each ACL with getfacl, add the group's rights with a short awk script, and apply the result with setfacl --restore. Where the mask gains a right, the script takes it from the named entries, so their effective rights stay the same. The rights go to the owning group of each entry, so an entry of another group is left alone with the warning. Without ACL support, setfacl falls back to chmod for these minimal ACLs, as before. bitcoind runs with PrivateUsers, which shows the users and groups that an ACL names as unmapped ids, and setfacl can't write them back. So do the setup in its own oneshot unit, bitcoind-group-read, with the same hardening but without PrivateUsers. bitcoind wants it and starts after it, so it runs before each start of bitcoind. It also waits for a mount at blocks/index, at blocks or at a dir above them, so with a disk that's mounted on demand, it sets the ACL on that disk and not on the empty mount point. The data dir is group-writable, so a group member can replace blocks (or regtest on regtest) with a symlink to other files of the bitcoin user, also between two commands. So enter each dir with cd, only after checking that it's a dir of the bitcoin user, and then check that the dir we're in is the one we checked. A rename after that can't move us out of it. Change only the current dir and the names in it: setfacl -P doesn't follow a symlink at a name, and for a path with a dir part it would need openat2(), which systemd's RestrictSUIDSGID blocks. A symlink at blocks or regtest stops the setup with a warning. Master's chmod followed such a symlink on mainnet, so add a notice and an upgrade note. The VM test restarts bitcoind many times, which also stops the services that depend on it. So run it only in its own scenario, with bitcoind alone, and in the disruptive phase. Remove the sysperms option and the UMask setting, which had no effect. Fixes bitcoinix#55 Assisted-by: Claude Code (Claude Opus 5.5)
ce87711 to
e1191d0
Compare
|
Thanks for catching this. It's fixed in e1191d0. Master didn't move, so there's no rebase.
On this head |
viberaven
left a comment
There was a problem hiding this comment.
Approved at e1191d04. All six findings from my earlier reviews are addressed.
I tested first startup with an on-demand bind mount at blocks on mainnet and at regtest/blocks/index on regtest. In both VMs, systemd mounted the storage before starting bitcoind-group-read.service, and operator could read a pre-existing file immediately. Using the network-specific blocks/index path for RequiresMountsFor covers both layouts.
The dedicated VM passed its symlink and existing-ACL checks, including preservation of named groups’ effective permissions. A separate VM with LND and group read enabled also passed. I verified the documented bind mount generates the expected /etc/fstab entry, and the module-config and test-runner checks passed locally.
Assisted-by: Codex (gpt-6.2-astra)
Fixes #55.
Bitcoin Core calls
umask(077)when it starts, and Core 25.0 removed thesyspermssetting. So withdataDirReadableByGroup, every file that bitcoind created while it ran got mode 0600. A group member that reads blocks from disk lost access to new ones until the next restart. On regtest the option did nothing, because preStart looked forblocksin the data dir and not inregtest/.A default ACL on a dir takes the place of the umask for new files below it. Core creates block files with
fopen(mode 0666) and LevelDB uses 0644, so with the ACL new files get 0640. I checked this with Core 32.1 in a VM. A file that's created with an explicit 0600 stays 0600, but Core doesn't do that in the blocks dir.This PR:
bitcoind-group-read, which runs before each start of bitcoind, only withdataDirReadableByGroupon. It's a unit of its own because bitcoind runs withPrivateUsers, and there setfacl can't write back an ACL that names other users or groups. It waits for a mount atblocks/index, atblocksor at any dir above them, so a disk that's mounted on demand gets the ACL and not the empty mount point.r-xand a default ACL withr-xon the blocks dir and each dir in it, andr--on each file. To reach the blocks dir, the group gets--xon the data dir and, on regtest, on the network dir.setfacl --restore. All other users and groups keep their effective rights. Before,chmod g+rXchanged only the mask of such an ACL, so the group could stay locked out while named entries gained rights. An entry of another group is left alone.regtest/wallets, because Core makes that dir only in a network dir that it creates itself.acltype=posixacl. The group then reads only the files that exist at start, like before. That's safer than a failed start. The option only gives another program read access, and a stopped bitcoind takes the Lightning nodes down with it.cdonly after it checks that it's a dir of the bitcoin user, and then works only on.and the names in it. The data dir is group-writable, so a group member could put a symlink atblocksorregtest, also between two commands. A symlink there stops the setup with the warning. Master'schmod -Rfollowed such a symlink on mainnet, so this gets a 0.2.0 notice and an upgrade note. The note says how to move to a bind mount.services.bitcoind.syspermswithmkRemovedOptionModule, a 0.2.0 notice and an upgrade note.UMask = "0027", which Core overrides.bitcoindGroupReadto CI. It runs only bitcoind and its tests. The test checks that the operator can read every file in the blocks dir after the first start, after a restart and after a crash, but notchainstate. It replacesregtestandblockswith symlinks and checks that the setup leaves the targets alone. It also sets up an ACL with named groups and narrow masks and checks that their effective rights don't change.A group member can still rename dirs in the mainnet data dir before a restart, for example
walletstoblocks. Master's chmod has the same problem, and no path check can stop it. A data dir that the group can't write would, like #272 did for Core Lightning. That's for a separate PR.Testing
bitcoindGroupReadpasses. On master it fails, because the operator can't enter/var/lib/bitcoind/regtest/blocks./var/lib/bitcoind/blocksafter the first start. After a restart, the newCURRENT,MANIFEST-000004,000005.ldband000006.loginblocks/indexhave mode 0600 too.blocksor theregtestsymlink check, without the change to the named entries of the default ACL, or without the check of the owning group,bitcoindGroupReadfails.fastprune, 400 mined blocks gave the newblk00001.datandrev00001.datmode 0640.noacl, setfacl fails with "Operation not supported". bitcoind starts and logs the warning.noautobind mount at the blocks dir that mounts late, the operator can read every file on the first start and after a restart, on mainnet and on regtest. Without the mount dependency, the setup runs before the mount and the operator can't enter the blocks dir. The same holds for a late mount atblocks/index.defaultpasses.module-config,test-runner,nix eval --raw .#ciTestInfo,test/shellcheck.shandhelper/check-release-notes.shpass.Written with Claude Opus 5.5 and reviewed with Claude Fable 5.2, GPT-6 Astra, Kimi K3.1 Pro, DeepSeek V4.1 Flash, Gemini 4 Carbon, GLM 5.3 and Qwen4-Max.