Secrets are generated through a tool called Sops created by mozilla. This is
then consumed by NixOS via sops-nix
.
Sops lets us deal with many encryption standards (pgp, age, ssh, etc.) under one
common tool and CLI framework.
You currently have 3 options for creating a new secret key to operate with sops and its secrets. Age keys are the recommended choice for their ease of use.
NOTE: All ed25519
based ssh keys (excluding -sk
versions) will have age
keys
generated for them. So ensure extra caution when adding such a key.
Requires an ed25519
based generated ssh key with the secret readable by the
local device. This is used by ssh-to-age
to generate a private age
.
A handy tool is exposed to you through nix run .#first-run
to generate this
age
key, put it under .secrets/age.txt
, and set SOPS_AGE_KEY_FILE
for you.
To generate a new one, use mkdir -p ~/.config/sops/age
and then
age-keygen -o ~/.config/sops/age/keys.txt
.
You need to keep this file safe yourself. You should not need to set
up SOPS_AGE_KEY_FILE
as this is the standard location to put age keys.
Public key needs to be available in keys.openpgp.org
. Use the fingerprint
of the key with gpg --fingerprint
. Feel free to remove the extra spaces
from the fingerprint. Generating and how to use a pgp
key is left up to
you.
Formatting: echo "FINGERPRINT" | awk '{ gsub(/ /,""); print tolower($0) }'
Someone with access to sops will need to go and add your key to the
state/users.json
file, then run sops updatekeys secrets/XXX.yaml
on the relevant secrets you need access to.
- Install nixos on the host.
- Run
ssh-keyscan host
. - Copy the ed25519 key to the
state/machines.json
file. - Run
nix run .#sops-gen-lockfile
. - Run
sops updatekeys secrets/XXX.yaml
. - deploy the configuration with secrets to the machine.
- Go into
state/users.json
orstate/servers.json
and remove all keys for the user/server. - Run
nix run .#sops-gen-lockfile
. - Run
sops updatekeys secrets/XXX.yaml
to remove the key from the file. - Rotate the internal data-key with
sops --rotate --in-place secrets/XXX.yaml
. - Rotate any API keys manually which may have been available to the previous key.
Warning:
Do not run
sops updatekeys
only, as it will only sync the data-key between the users defined in.sops.yaml
. With this command, it will still use the previous secret key that the user we are removing still has access to. To stop a rogue user from fetching the data-key in our git history and decrypting the new rotated keys, remember to also run--rotate --in-place
.