Repository navigation
hardware-wallets: limit device access to the hardware-wallets group - #276
Conversation
viberaven
left a comment
There was a problem hiding this comment.
Reviewed ad21081aecbd.
No actionable code findings. Checked udev rule ordering and removal of the current uaccess tag, the expanded Ledger IDs, opt-in trezord access, custom groups, and both migration notices. Local module-config passes, including generated-rule ordering and udevadm verify; the mdBook build also passes. I did not test physical hardware wallets or rerun the VM locally.
CI follow-up: the failed default VM run hit a kernel NULL-pointer dereference in pick_task_fair while LND was running, then timed out. It did not report a hardware-wallet test assertion failure. Rerun the failed scenario before merging; if it repeats, investigate the VM/kernel failure separately.
Review performed with Codex (GPT-6 Astra).
ad21081 to
3cd4265
Compare
The Trezor udev rules added the uaccess tag, and systemd's 70-uaccess.rules adds it to Ledger and Trezor devices too. With it, systemd-logind gives the user of the active local session access to the device, also when that user isn't in group hardware-wallets. The module grants access only by group. The module also turned on the Trezor Bridge (trezord). Its user isn't in group hardware-wallets, and our rules replace the group that the nixpkgs rules set, so the bridge couldn't open the device. Making it work lets every local user and service use the Trezor through the bridge's HTTP API, which has no authentication. HWI and trezorctl open the device directly and don't need the bridge. Move our rules after 70-uaccess.rules and remove the uaccess tag in each of them, before 73-seat-late.rules applies it. Match every Ledger product, as systemd does, since Ledger models and firmware versions use many product IDs. Run the bridge only with the new option services.hardware-wallets.trezorBridge, which gives the trezord unit the group. Its description says what the bridge exposes. Warn when trezord runs without the group, since it then can't open the device. 0.2.0 notices tell Ledger and Trezor users about the changes. Fixes bitcoinix#66. Fixes bitcoinix#153. Assisted-by: Claude Code (Claude Opus 5.5)
3cd4265 to
771affc
Compare
Fixes #66. Fixes #153.
services.hardware-walletsgives Ledger and Trezor devices to grouphardware-wallets. Two things bypassed that group:TAG+="uaccess".70-uaccess.rulesadds the same tag to every device in its hardware wallet hwdb, which includes all Ledger and Trezor devices. In systemd 262, which master pins, that'sSUBSYSTEM=="usb", ENV{ID_HARDWARE_WALLET}=="1", TAG+="uaccess"and the same rule forhidraw.With the tag,
73-seat-late.ruleshas systemd-logind give the user of the active local session an ACL on the device, also when that user isn't in the group.The module also turned on the Trezor Bridge (
services.trezord.enable = true). In the pinned nixpkgs, trezord runs as usertrezord, which isn't in grouphardware-wallets. The nixpkgs51-trezor.rulessetGROUP="trezord", but our rules come later and replace it. So the bridge couldn't open the device. Making it work lets every local user and service use the Trezor through the bridge's HTTP API on127.0.0.1:21325, which has no authentication. Nothing in bitcoinix uses the bridge. HWI andtrezorctlopen the device directly.This PR:
71-hardware-wallets-ledger.rulesand71-hardware-wallets-trezor.rules, and each rule line now removes the tag withTAG-="uaccess". udevd sorts the files of/etc/udev/rules.dand systemd's own rules dir together by name. So ours run after51-trezor.rulesand70-uaccess.rules, and before73-seat-late.rules, which applies the tag. In systemd 260,TAG-=drops the tag from the device's current tags.73-seat-late.rulesmatches current tags, and logind checks the current tag again before it sets ACLs on a session switch.2c97, and the HW.1 and early Nano IDs of vendor2581. They matched only2c97:0001before. Real Ledger devices show other product IDs, for example a Nano S as2c97:1011, so the group didn't get them and the session did.services.hardware-wallets.trezorBridge(defaultfalse). It turns on trezord and setsSupplementaryGroupson its unit, so a switch restarts a running bridge with the group. The option description says what the bridge exposes.trezorbut without the group, since it then can't open the device. That happens whenservices.trezord.enableis set directly. The warning stays off when trezord gets the group in another way: throughusers.users.trezord,users.groups.<group>.members, the unit'sGrouporSupplementaryGroups, orservices.hardware-wallets.group = "trezord".docs/services.md. One notice covers session access for Ledger and Trezor users. The other covers the bridge, for Trezor users who don't run trezord.A device that's plugged in while you deploy keeps the session user's ACL until you unplug it. The upgrade note says so.
A config that turned the bridge off with
services.trezord.enable = lib.mkForce falsegets the bridge notice too, although nothing changes for it. Detecting that needs option priority introspection, so this config only has to bumpconfigVersiononce more.Testing
test/configuration.nix:uaccesstag. The2c97rule matches every product, and the2581rule has the HW.1 IDs.trezor. With the bridge on, its unit has the group.trezorbut without the group. It doesn't appear withtrezorBridge,users.users.trezord.extraGroups,users.groups.hardware-wallets.members, the unit'sGrouporSupplementaryGroups(also as a space-separated string), orgroup = "trezord".51-trezor.rules,70-uaccess.rules, our two files and73-seat-late.rulessort in that order, and that systemd still tags hardware wallets in70-uaccess.rules. It also runsudevadm verifyon our files.52-, and withTAG-="uaccess"removed.nix build .#checks.x86_64-linux.module-config(139 tests) and.#checks.x86_64-linux.test-runnerpass.nix eval .#ciTestInfopasses.netnspasses on the final head. It enablesservices.hardware-wallets.trezorandledgerthroughfull.Not tested on a device. I didn't run
udevadm testagainst a fake device in a VM.module-config,test-runner,ci-workflowsandnetnspass 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. Kimi K3.1 Pro (two passes) and Claude Fable 5.2 reviewed the first rebase.