Change the secrets encryption key¶
All the platform secrets are located in the secrets/secrets.yaml
and encrypted
with [sops ].
On the main branch this file is encrypted by a sample age key located at the
root of the project (sample_age_key.txt
) and contains fake secrets. While you
can use this sample key for testing, it's better to change it before doing
anything with the secrets file.
Start by making the sample age key reachable to sops by putting it in its well-known location:
Note
The following shows a rotation with a new Age key. Note that you can use any other key that sops understands. Check the sops documentation. You can also add other type of keys later on. We recommend to continue to use age at this stage.
Then create your own key:
Derive the age key from a ssh key
The age key can be derived from a ssh key. This is convenient as a SSH key may be used to access the repository.
The ssh-to-age project provides a command to convert an existing ed25519 ssh key into a valid age key:
$ go install github.com/Mic92/ssh-to-age/cmd/ssh-to-age@latest
$ ssh-to-age -private-key -i ~/.ssh/id_ed25519 >> ~/.config/sops/age/keys.txt
$ NEWKEY=$(ssh-to-age -i ~/.ssh/id_ed25519.pub)
Note that at the time of this writing, there is a PR in sops adding native ssh key support to sops.
Replace the secrets encryption by using the public key of your new key (recipient in age parlance) with the following commands:
PS> $OLDKEY=age-keygen.exe -y $env:APPDATA\sops\age\keys.txt | Select-Object -First 1
PS> $NEWKEY=age-keygen.exe -y $env:APPDATA\sops\age\keys.txt | Select-Object -Last 1
PS> $(ls .\secrets\secrets.yaml;ls .\secrets\helm\*) | `
> % { &sops '-r' '-i' '--add-age' $NEWKEY '--rm-age' $OLDKEY $_.FullName }
PS>
Now change the recipient in the .sops.yaml
sops configuration file in order to
use the new key for encryption from now on:
At this point, you can delete the sample key on your branch and commit the modifications:
From now on, you should forget the old key and make sure that you keep the new key safe. A good idea is to save it in some kind of secure password manager like gopass.
To remove the old key from the sops well-known location, issue the following command:
Test that your environment is correct by decrypting the secrets file:
.gitignore safe
the project .gitignore
file contains the *.dec.yaml
pattern. Therefore,
there is no risk of committing an unencrypted secrets file as long as you
keep it named like that.
You can also build the secrets kustomization. It will print out all the unencrypted secrets to the terminal:
Now that you can manage properly secured credentials, move on to the environment adaptation