-
Notifications
You must be signed in to change notification settings - Fork 175
feat: add age plugin support, take 2 #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
849b49f
to
7678b2d
Compare
modules/home-manager/sops.nix
Outdated
plugins = lib.mkOption { | ||
type = lib.types.listOf lib.types.package; | ||
default = [ | ||
pkgs.age-plugin-fido2-hmac |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, I don't want to set a default here for the first iteration. Especially this plugin might not work very well since we cannot enter a PIN easily - Maybe this works for activation scripts but with systemd services I am not sure how this is supposed to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this pull request should at least describe how one can setup one age plugin of choice from start to end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, I don't want to set a default here for the first iteration. Especially this plugin might not work very well since we cannot enter a PIN easily - Maybe this works for activation scripts but with systemd services I am not sure how this is supposed to work.
Yeah, I can leave that option blank. 👍🏾
Speaking of systemd.. so I was trying userborn on my laptop to see if the plugins (specifically the yubikey one) works but with the sops-install-secrets-for-users service, I'm seeing warnings about the HOME variable isn't defined and it fails to interact with the key (the key flashes on like it got a request to do something but fails to do actually do the request)
● sops-install-secrets-for-users.service
Loaded: loaded (/etc/systemd/system/sops-install-secrets-for-users.service; enabled; preset: ignored)
Active: active (exited) since Fri 2025-05-16 10:47:05 CDT; 50min ago
Invocation: c65e2068806247bb8ed3193542af0afc
Process: 34406 ExecStart=/nix/store/yh0g1mxx2zcv4snnrgblxdss9mjbxbs5-sops-install-secrets-0.0.1/bin/sops-install-secrets -ignore-passwd /nix/store/b9swyn2kxpf98cdycg6yhshjm62131vw-manifest-for-users.json (code=exited, status=0/SUCCESS)
Main PID: 34406 (code=exited, status=0/SUCCESS)
IP: 0B in, 0B out
IO: 0B read, 0B written
Mem peak: 8.9M
CPU: 60ms
May 16 10:47:05 yoganova systemd[1]: Starting sops-install-secrets-for-users.service...
May 16 10:47:05 yoganova sops-install-secrets[34406]: sops-install-secrets: Imported /etc/ssh/ssh_host_ed25519_key as age key with fingerprint age1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
May 16 10:47:05 yoganova sops-install-secrets[34406]: [AGE] time="2025-05-16T10:47:05-05:00" level=warning msg="could not determine the user home directory: $HOME is not defined"
May 16 10:47:05 yoganova sops-install-secrets[34406]: [AGE] time="2025-05-16T10:47:05-05:00" level=warning msg="could not determine the user home directory: $HOME is not defined"
May 16 10:47:05 yoganova sops-install-secrets[34406]: [AGE] time="2025-05-16T10:47:05-05:00" level=warning msg="could not determine the user home directory: $HOME is not defined"
May 16 10:47:05 yoganova sops-install-secrets[34406]: [AGE] time="2025-05-16T10:47:05-05:00" level=warning msg="could not determine the user home directory: $HOME is not defined"
May 16 10:47:05 yoganova systemd[1]: Finished sops-install-secrets-for-users.service.
Even stranger is the home-manager sops-nix service. It just completely skips the key, similarly flashing on like how I described with the install secrets service. But as soon as I turn off userborn, the home-manager service works fine for the home-manager service!
🤔 What's really odd is I've been able to get the plugin working over in agenix with home-manger but not with the user passwords (similarly had issues with the plugin not being executed during the boot process, always had to include an ssh key as a fallback key to decrypt the user passwords)
Additionally, the plugin activates normally when I switch the configurations for both Home-manager and NixOS (specifically with userborn off)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this pull request should at least describe how one can setup one age plugin of choice from start to end.
Will do! I intended to do one earlier but I forgot to do so 😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even stranger is the home-manager sops-nix service. It just completely skips the key, similarly flashing on like how I described with the install secrets service. But as soon as I turn off userborn, the home-manager service works fine for the home-manager service!
Ah I realized. The age key I was using on my yubikey had a PIN policy on it, switched that one out for a pinless one and now the home-manager service doesn't break anymore (with either userborn and standard! 🥳 ); but I still can't figure out that $HOME is not defined
warning with the NixOS service 🤔
@@ -34,8 +34,9 @@ in | |||
{ | |||
wantedBy = [ "systemd-sysusers.service" ]; | |||
before = [ "systemd-sysusers.service" ]; | |||
environment = cfg.environment; | |||
environment = cfg.environment // {PATH = lib.mkForce "${cfg.environment.PATH}:${lib.makeSearchPathOutput "bin" "sbin" cfg.age.plugins}";}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @brianmcgee for review.
I also withdrew the darwin changes in case those caused breakages over on that side (I can't test that build at all since I don't have a Mac) |
And the write up is done! @Mic92 |
782693f
to
162aec0
Compare
I completely missed the |
I am interested in TPM-based decryption at system boot. I got it working thanks to this pull request. I made a proof of concept here for a virtual machine. I also got it working on a physical machine, but not in a state to share. I found that it works the same whether I include the |
Co-authored-by: brianmcgee <brian@41north.dev>
Updated to resolve some merge conflicts. Also I've noticed I can actually get the |
Description
Continuing directly off of #680 .
I went and updated the changes to work with the most recent commits of sops-nix as well as adding in the wrapper changes introduced into the sops and age packages with NixOS/nixpkgs#395189. I can confirm it does work when you rebuild the NixOS install (and home-manager). I'm using the
age-plugin-yubikey
plugin on my system but all other plugins should work fine.Additionally, I also went and added the plugin support over in the home-manager module too! I don't have a Mac to test the nix-darwin changes but I'm sure it's simply just adding the same changes into the darwin module aswell.
Some Notes
Some things oddities and things I've noticed while working on getting the PR together:
keys.txt
file is crucial otherwise sops can't figure out what keys to access. And I've noticed you can put multiple public keys in the same file so that's what I did for all of my age keys from my yubikeysneededForUsers
secrets that only use the yubikeys (without some other key like ssh host derived age key) to decrypt when the system boots up.It seems to be because they're being executed before systemd even has a chance to start (because the service is using activationScripts when you're not using userborn)Actually, it maybe because the plugin can't determine the user?Write-up of new steps to configure age plugins
sops.age.plugins
and make sure to install them withenvironment.systemPackages
so you can use the plugins to generate the keys.age-plugin-yubikey
, runage-plugin-yubikey
and follow prompts (See guide for more options)age-plugin-fido2-hmac
, runage-plugin-fido2-hmac -g
(See the guide for more detailed information, I don't have this setup to give any further details)~/.config/sops/age/keys.txt
. This will allow sops to use your newly created age keys to be used by sops (otherwise it can't figure out which hardware-based secret key to use).sops.age.keyFile
for both NixOS and Home-manager (which in my case is/var/lib/sops/keys.txt
for NixOS and/home/USERNAME/.config/sops/age/keys.txt
for Home-Manager). Sops-nix then will try to use the keys listed here