Skip to content

hardware-wallets: limit device access to the hardware-wallets group - #276

Merged
prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:hardware-wallets-trezor-access
Nov 18, 2026
Merged

prusnak merged 2 commits into
bitcoinix:masterfrom
ostermayer:hardware-wallets-trezor-access

Conversation

@ostermayer

@ostermayer ostermayer commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #66. Fixes #153.

services.hardware-wallets gives Ledger and Trezor devices to group hardware-wallets. Two things bypassed that group:

  • Our Trezor rules added TAG+="uaccess".
  • systemd's 70-uaccess.rules adds 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's SUBSYSTEM=="usb", ENV{ID_HARDWARE_WALLET}=="1", TAG+="uaccess" and the same rule for hidraw.

With the tag, 73-seat-late.rules has 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 user trezord, which isn't in group hardware-wallets. The nixpkgs 51-trezor.rules set GROUP="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 on 127.0.0.1:21325, which has no authentication. Nothing in bitcoinix uses the bridge. HWI and trezorctl open the device directly.

This PR:

  • moves our rules to 71-hardware-wallets-ledger.rules and 71-hardware-wallets-trezor.rules, and each rule line now removes the tag with TAG-="uaccess". udevd sorts the files of /etc/udev/rules.d and systemd's own rules dir together by name. So ours run after 51-trezor.rules and 70-uaccess.rules, and before 73-seat-late.rules, which applies the tag. In systemd 260, TAG-= drops the tag from the device's current tags. 73-seat-late.rules matches current tags, and logind checks the current tag again before it sets ACLs on a session switch.
  • removes the tag only on the devices our rules give to the group. systemd's hwdb also lists generic USB serial chips and other wallets, which no group would get otherwise.
  • makes the Ledger rules match every Ledger device in systemd's hwdb: all products of vendor 2c97, and the HW.1 and early Nano IDs of vendor 2581. They matched only 2c97:0001 before. Real Ledger devices show other product IDs, for example a Nano S as 2c97:1011, so the group didn't get them and the session did.
  • adds services.hardware-wallets.trezorBridge (default false). It turns on trezord and sets SupplementaryGroups on its unit, so a switch restarts a running bridge with the group. The option description says what the bridge exposes.
  • warns when trezord runs with trezor but without the group, since it then can't open the device. That happens when services.trezord.enable is set directly. The warning stays off when trezord gets the group in another way: through users.users.trezord, users.groups.<group>.members, the unit's Group or SupplementaryGroups, or services.hardware-wallets.group = "trezord".
  • adds two 0.2.0 notices, upgrade notes, release notes and a paragraph in the Trezor section of 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 false gets the bridge notice too, although nothing changes for it. Detecting that needs option priority introspection, so this config only has to bump configVersion once more.

Testing

  • New tests in test/configuration.nix:
    • Every Ledger and Trezor rule line sets the group and removes the uaccess tag. The 2c97 rule matches every product, and the 2581 rule has the HW.1 IDs.
    • trezord is off by default and needs trezor. With the bridge on, its unit has the group.
    • The warning appears only when trezord runs with trezor but without the group. It doesn't appear with trezorBridge, users.users.trezord.extraGroups, users.groups.hardware-wallets.members, the unit's Group or SupplementaryGroups (also as a space-separated string), or group = "trezord".
    • Each notice fires only for the configs it describes.
    • The check build lists the system's udev rules dir, which on NixOS also holds copies of systemd's rules. It checks that 51-trezor.rules, 70-uaccess.rules, our two files and 73-seat-late.rules sort in that order, and that systemd still tags hardware wallets in 70-uaccess.rules. It also runs udevadm verify on our files.
    • These tests fail with our files at 52-, and with TAG-="uaccess" removed.
  • nix build .#checks.x86_64-linux.module-config (139 tests) and .#checks.x86_64-linux.test-runner pass.
  • nix eval .#ciTestInfo passes.
  • VM scenario netns passes on the final head. It enables services.hardware-wallets.trezor and ledger through full.

Not tested on a device. I didn't run udevadm test against a fake device in a VM.

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.

@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service labels Nov 16, 2026

@viberaven viberaven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@github-actions github-actions Bot added the status: rebase needed Merge conflicts need to be resolved label Nov 16, 2026
@ostermayer
ostermayer force-pushed the hardware-wallets-trezor-access branch from ad21081 to 3cd4265 Compare November 18, 2026 00:19
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)
@ostermayer
ostermayer force-pushed the hardware-wallets-trezor-access branch from 3cd4265 to 771affc Compare November 18, 2026 01:01
@github-actions github-actions Bot added status: rebase needed Merge conflicts need to be resolved and removed status: rebase needed Merge conflicts need to be resolved labels Nov 18, 2026
@prusnak prusnak added this to the v0.2.0 milestone Nov 18, 2026
@github-actions github-actions Bot removed the status: rebase needed Merge conflicts need to be resolved label Nov 18, 2026
@prusnak
prusnak merged commit 50cb86f into bitcoinix:master Nov 18, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix type: feature New capability or service

Projects

None yet

3 participants