File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -332,9 +332,14 @@ e.g. inside your `flake.nix` file:
332332 {
333333 "secret1.age".publicKeys = [ user1 system1 ];
334334 "secret2.age".publicKeys = users ++ systems;
335+ "armored-secret.age" = {
336+ publicKeys = [ user1 ];
337+ armor = true;
338+ };
335339 }
336340 ```
337341 These are the users and systems that will be able to decrypt the ` .age ` files later with their corresponding private keys.
342+ The armor option may also be supplied here to ensure files are output in Base64 PEM text which is useful for more readable diffs.
338343 You can obtain the public keys from
339344 * your local computer usually in ` ~/.ssh ` , e.g. ` ~/.ssh/id_ed25519.pub ` .
340345 * from a running target machine with ` ssh-keyscan ` :
Original file line number Diff line number Diff line change 2525 {
2626 "secret1.age".publicKeys = [ user1 system1 ];
2727 "secret2.age".publicKeys = users ++ systems;
28+ "armored-secret.age" = {
29+ publicKeys = [ user1 ];
30+ armor = true;
31+ };
2832 }
2933 ```
30344 . Edit secret files (these instructions assume your SSH private key is in ~ /.ssh/):
Original file line number Diff line number Diff line change 1+ -----BEGIN AGE ENCRYPTED FILE-----
2+ YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IFYzWG1FQSBpZkZW
3+ aFpLNnJxc0VUMHRmZ2dZS0pjMGVENnR3OHd5K0RiT1RjRUhibFZBCnN5UG5vUjA3
4+ SXpsNGtiVUw4T0tIVFo5Wkk5QS9NQlBndzVvektiQ0ozc0kKLS0tIGxyY1Q4dEZ1
5+ VGZEanJyTFNta2JNRmpZb2FnK2JyS1hSVml1UGdMNWZKQXMKYla+wTXcRedyZoEb
6+ LVWaSx49WoUTU0KBPJg9RArxaeC23GoCDzR/aM/1DvYU
7+ -----END AGE ENCRYPTED FILE-----
Original file line number Diff line number Diff line change 66 "secret2.age" . publicKeys = [ user1 ] ;
77 "passwordfile-user1.age" . publicKeys = [ user1 system1 ] ;
88 "-leading-hyphen-filename.age" . publicKeys = [ user1 system1 ] ;
9+ "armored-secret.age" = {
10+ publicKeys = [ user1 ] ;
11+ armor = true ;
12+ } ;
913}
Original file line number Diff line number Diff line change @@ -118,6 +118,10 @@ function keys {
118118 (@nixInstantiate@ --json --eval --strict -E " (let rules = import $RULES ; in rules.\" $1 \" .publicKeys)" | @jqBin@ -r .[]) || exit 1
119119}
120120
121+ function armor {
122+ (@nixInstantiate@ --json --eval --strict -E " (let rules = import $RULES ; in (builtins.hasAttr \" armor\" rules.\" $1 \" && rules.\" $1 \" .armor))" ) || exit 1
123+ }
124+
121125function decrypt {
122126 FILE=$1
123127 KEYS=$2
@@ -148,6 +152,7 @@ function decrypt {
148152function edit {
149153 FILE=$1
150154 KEYS=$( keys " $FILE " ) || exit 1
155+ ARMOR=$( armor " $FILE " ) || exit 1
151156
152157 CLEARTEXT_DIR=$( @mktempBin@ -d)
153158 CLEARTEXT_FILE=" $CLEARTEXT_DIR /$( basename -- " $FILE " ) "
@@ -169,6 +174,9 @@ function edit {
169174 [ -f " $FILE " ] && [ " $EDITOR " != " :" ] && @diffBin@ -q -- " $CLEARTEXT_FILE .before" " $CLEARTEXT_FILE " && warn " $FILE wasn't changed, skipping re-encryption." && return
170175
171176 ENCRYPT=()
177+ if [[ " $ARMOR " == " true" ]]; then
178+ ENCRYPT+=(--armor)
179+ fi
172180 while IFS= read -r key
173181 do
174182 if [ -n " $key " ]; then
Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ pkgs.nixosTest {
6464 file = ../example/secret2.age ;
6565 path = "/home/user1/secret2" ;
6666 } ;
67+ secrets . armored-secret = {
68+ file = ../example/armored-secret.age ;
69+ } ;
6770 } ;
6871 } ;
6972 } ;
@@ -73,6 +76,7 @@ pkgs.nixosTest {
7376 password = "password1234" ;
7477 secret2 = "world!" ;
7578 hyphen-secret = "filename started with hyphen" ;
79+ armored-secret = "Hello World!" ;
7680 in ''
7781 system1.wait_for_unit("multi-user.target")
7882 system1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
@@ -93,6 +97,9 @@ pkgs.nixosTest {
9397 system1.send_chars("cat /run/user/$(id -u)/agenix/secret2 > /tmp/2\n")
9498 system1.wait_for_file("/tmp/2")
9599 assert "${ secret2 } " in system1.succeed("cat /tmp/2")
100+ system1.send_chars("cat /run/user/$(id -u)/agenix/armored-secret > /tmp/3\n")
101+ system1.wait_for_file("/tmp/3")
102+ assert "${ armored-secret } " in system1.succeed("cat /tmp/3")
96103
97104 assert "${ hyphen-secret } " in system1.succeed("cat /run/agenix/leading-hyphen")
98105
You can’t perform that action at this time.
0 commit comments