feat(bcachefs): add declarative clevis unlocking support (TPM2/FIDO2/Tang)#1173
feat(bcachefs): add declarative clevis unlocking support (TPM2/FIDO2/Tang)#1173shift wants to merge 3 commits intonix-community:masterfrom
Conversation
Implements TASK-001 from bcachefs-improvements project to enable automated
unlocking of encrypted bcachefs filesystems using TPM2, FIDO2, or Tang
via Clevis integration.
- unlock.enable: Boolean flag to enable Clevis-based unlocking
- unlock.secretFiles: List of JWE token files for automatic unlock
- unlock.extraPackages: Additional packages for specific Clevis pins
- Automatic initrd secret injection to /etc/bcachefs-keys/${fsLabel}/
- Systemd service with fail-open ring logic for reliable boot
- Hardware support for Lenovo X1 Yoga Gen 4 (TPM + USB modules)
- Generic approach works with TPM2, FIDO2, and Tang without mode specification
- Fail-open ring ensures boot never blocks on unlock failure
- Backward compatible with existing bcachefs configurations
- Follows NixOS module conventions and disko patterns
- boot.initrd.extraPackages: clevis, jose, tpm2-tools, bash + extras
- boot.initrd.availableKernelModules: TPM and USB kernel modules
- boot.initrd.secrets: Maps secret files to initrd paths
- boot.initrd.systemd.services."bcachefs-unlock-${fsLabel}": Unlock service
| @@ -1,36 +1,19 @@ | |||
| # Main test runner for bcachefs TPM2 unlocking | |||
There was a problem hiding this comment.
Changing the default.nix file in tests to be the “Main test runner for bcachefs TPM2 unlocking” is the kind of change an AI agent would make. Did you use an AI agent to code this?
| [ | ||
| "X-mount.mkdir" | ||
| "X-mount.subdir=${lib.removePrefix "/" subvolume.name}" | ||
| clevis |
There was a problem hiding this comment.
AFAIK clevis does not have FIDO2 support: latchset/clevis#399
There was a problem hiding this comment.
There is https://github.com/olastor/clevis-pin-fido2 which provides FIDO2 pin functionality.
There was a problem hiding this comment.
Ah, I missed where you added that in extraPackages in the example FIDO2 disko
edit: I checked and that is not in nixpkgs.
|
|
||
| # Simple performance test | ||
| start_time = machine.succeed("date +%s%N") | ||
| machine.succeed("which bcachefs") |
There was a problem hiding this comment.
This test reads like nonsense to me.
There was a problem hiding this comment.
Possibly why it's still marked as a draft. I'll hopefully find the time to finish it next week.
This PR adds comprehensive TPM2 and FIDO2 unlocking support for bcachefs filesystems using Clevis, enabling automated boot scenarios with hardware-backed encryption keys.
Problem Statement
Currently, bcachefs filesystems with native encryption require manual password entry during boot, preventing automated deployment and unattended operation. Unlike LUKS, bcachefs lacks native integration with systemd-cryptenroll, forcing users to choose between:
Users need a declarative way to unlock encrypted bcachefs volumes using hardware tokens (TPM2, FIDO2, Tang) while maintaining fallback to manual entry.
Solution
This implementation introduces a fail-open ring design using Clevis as a sidecar:
Implementation
Core Features
1. Extended bcachefs Type
2. Initrd Integration
3. Systemd Service
4. Hardware Support
Technical Approach
Fail-Open Ring Logic
Changes
Files Modified
Security Considerations
Performance Impact
Boot Time
Memory/Disk Usage
Future Roadmap & Upstream Work
While this PR enables automated unlocking today via Clevis, managing the underlying Bcachefs keys (rotation/removal) remains manual because Bcachefs slots are currently unlabeled.
I have opened an RFC with upstream Bcachefs to add "Key Labels" to the superblock, which will allow for safer, declarative key management in the future:
Checklist