Closed Padraic-O-Mhuiris closed 3 years ago
Usually you need to have at least two keys per secret in the secrets.nix file: the system's public ssh host key, and your public ssh key. It looks like in your case you've excluded your public ssh key from the secret, so when you encrypt it, it can only be decrypted by your server and not you.
The script will automatically add the ~/.ssh key as a recipient if it exists
This is not correct. The script automatically adds it as an identity (used for decrypting), but it does not add it as a recipient when encrypting. Recipients are controlled solely by the contents of your secrets.nix
file.
So to clarify, the correct model is a two key approach, the first being a per system "host" key under /etc/ssh
which is only used to decrypt secrets. The personal user ssh key under ~/.ssh
is used both for encrypting and decrypting as a means to edit the secret1.age
file?
aah I see, this way you can edit any key on any system?
Yes, that's right.
The idea is you have some set of users (usually identified by ~/.ssh ssh keys) and some set of systems (usually identified by /etc/ssh host keys). The secrets should only be decryptable by the systems they need to be deployed onto and the users that need to edit the secrets.
You can only edit the secrets on computers where your private ssh key is available.
:+1: Thanks for clearing this up. I'll close the issue
I think this should be added to the docs. It was also confusing to me.
Interesting, I hadn't set things up this way either -- I have just been editing the secrets as root on the respective systems, but that would make sense to have a second key enabled on each (in order to be able to edit them from my main day-to-day machine).
I've managed to set up agenix from unstable to a point where it appears to be working during the nixos-rebuild process. I've been using ssh host keys (located under
/etc/ssh/
) as outlined in:https://github.com/ryantm/agenix/blob/53aa91b4170da35a96fab1577c9a34bc0da44e27/modules/age.nix#L99
This is my
secrets.nix
file I have:The issue I have arises when I use the agenix tool by command
agenix -e ngrokConfig.age
. When I first initialise the file it works, opening a blank file and jumping into the neovim process I have set as my editor. However the second time I try to do it, it gives back an error:No identity found to decrypt ngrokConfig.age. Try adding an SSH key at /home/padraic/.ssh/id_rsa or /home/padraic/.ssh/id_ed25519 or using the --identity flag to specify a file.
Using the
-v
option:And using running the same command as root user through sudo:
~I'm inclined to think that I may be going about the encryption process incorrectly and it was only intended to be a one-time edit of the file. I can get by well enough by just deleting the file and recreating it again, however it is a bit tedious and would be preferred if I can make incremental changes to secret configs and the such. ~
All above aside, great tool btw
Update:
On further reading of the
agenix.nix
file, I believe I understand the issue better. I have on my machine two ssh keys, one under/etc/ssh
, the "host" key and then a personal ssh key under~/.ssh
. The script will automatically add the~/.ssh
key as a recipient if it exists but does not appear to search under/etc/hosts/
for the decryption, only~/ssh
. I think it would be a good default to lookup host ssh keys in the event of running as root (as they could only be accessed by root).