26 Mar 2025 |
rane [they/them] | I think you might be mixing up public and private keys - you need the public key to encrypt, the private key to decrypt. A private key only needs to be present when you are decrypting the existing values. When you are editing or creating secrets, you will need access to at least one private key. Every private key has a corresponding public key, which must be "added" in secrets.nix to have "access" to a secret. A yubikey is just one thing you use, you can use a private key you control with a passphrase for example, instead. As long as the corresponding public key has "access" in secrets.nix to the secret. When it comes to machines, the SSH private key should only ever be present on the machine where the SSH key is being used for SSH, but agenix can also use this as a private key for decrypting secrets. So if you store the public key of a machine which needs access to a secret in the secrets.nix file and give it "access" to a secret, agenix, when running on that destination NixOS machine can decrypt the secrets from the Nix store and then store the decrypted secret as a file under /run which is typically a memory-only filesystem (so they don't persist and need to be decrypted each reboot).
Putting all of this together, if you have a personal private key for admin purposes (i.e., adding and editing secrets), you would give the corresponding public key access to the secrets so the public key is used to encrypt the value. The public keys of any machines (i.e the SSH public key, which ssh-keyscan gives you) are also added as public keys and used for encryption for the secret. Only the machines and users with access to the private key for any of those identities however can actually decrypt the secret. Does that make more sense?
| 04:21:27 |
27 Mar 2025 |
@raijin_:matrix.org |  Download image.png | 15:59:19 |
@raijin_:matrix.org | rane [they/them]: thanks so much for your explanations, I think I'm starting to understand. I'm kind of a visual learner, so I diagrammed out my current setup here. Maybe that will shed light on where my misunderstanding lies.
A private key only needs to be present when you are decrypting the existing values
But what public key does this private key correspond to? One of the public keys defined and assigned to the secret in secrets.nix ? Or one of the original keys in identityPaths that encrypted the secret?
A yubikey is just one thing you use
So I would have a public key entry in secrets.nix for the YubiKey just as I would for a host?
So if you store the public key of a machine which needs access to a secret in the secrets.nix file and give it "access" to a secret, agenix,
I think I have this part, because when I get a new host (non-server), I generate a new keypair on that machine and add the pubkey to secrets.nix . I then add that key as a target in secrets.nix . (for the secrets defined in user_secrets.nix )? But obviously I'm missing something when trying to rekey my secrets for the new machine, because the operation does not generate new files.
| 15:59:22 |
28 Mar 2025 |
| scottytheengineer joined the room. | 18:16:13 |
30 Mar 2025 |
| 98765abc joined the room. | 02:13:30 |
31 Mar 2025 |
| taw420 joined the room. | 21:13:40 |
3 Apr 2025 |
| Ben Sparks joined the room. | 16:18:24 |
4 Apr 2025 |
| divit joined the room. | 12:22:35 |
5 Apr 2025 |
| @tinybronca:sibnsk.net left the room. | 15:41:33 |
8 Apr 2025 |
| @morbidity3080:deep.fo joined the room. | 10:39:18 |
| @morbidity3080:deep.fo left the room. | 10:39:52 |
9 Apr 2025 |
| Sean joined the room. | 19:06:15 |
Sean | https://github.com/ryantm/agenix/issues/115
where do I get my host ssh key from? | 19:25:08 |
Sean | oh, I don't need one | 19:44:32 |
10 Apr 2025 |
| fwam changed their profile picture. | 19:57:47 |
11 Apr 2025 |
| thoughtcrime69 joined the room. | 14:39:59 |
| @ambroisie:belanyi.fr left the room. | 22:09:34 |
16 Apr 2025 |
| wesleyjrz joined the room. | 12:10:05 |
17 Apr 2025 |
| mmkaram joined the room. | 04:29:42 |
| Sam changed their display name from Sam to Sam (away → 5/5). | 17:17:41 |
18 Apr 2025 |
| Saik joined the room. | 16:20:15 |
Saik | Hello, heres a simple question that I've had a hard time finding an answer to:
is there a way to have a subfolder within secrets/ ?
I prefer subfoldering--category/secret_name.age --over appending--category.secret_name.age
| 16:22:34 |
eyJhb | In reply to @saik3617:matrix.org
Hello, heres a simple question that I've had a hard time finding an answer to:
is there a way to have a subfolder within secrets/ ?
I prefer subfoldering--category/secret_name.age --over appending--category.secret_name.age
Yes, just create it and use it | 16:32:18 |
eyJhb | @Saik https://git.fricloud.dk/fricloud/server-configs/src/branch/main/secrets/secrets.nix#L20 | 16:33:01 |
eyJhb | And then I use it like this https://git.fricloud.dk/fricloud/server-configs/src/branch/main/secrets/default.nix#L6 | 16:33:27 |
eyJhb | You can see all the secrets in that folder as well. | 16:33:48 |