agenix icon indicating copy to clipboard operation
agenix copied to clipboard

Don't decrypt if secrets haven't changed from previous activation

Open winterqt opened this issue 4 years ago • 4 comments

Currently, agenix decrypts secrets every time the system is activated, even if the secrets haven't changed. Ideally, if the secrets haven't changed, the activation script would detect this and skip decrypting that secret. I can't really think of how this could be implemented though, hence the opening of this issue.

winterqt avatar Dec 31 '21 00:12 winterqt

I agree this is desirable, otherwise it triggers potential path change monitoring unnecessarily. It would still need to decrypt the secret, but it doesn't have to move it into place if the contents, group, user, and mode are unchanged.

ryantm avatar Dec 31 '21 03:12 ryantm

I tried to implement this, and ran into the issue that the way things currently work by default (this seems to have been changed recently), all the secrets get put into /run/agenix.d/<generation>/ and then that directory gets symlinked to /run/agenix. Since the directory is all updated as a whole, I don't see a way to not update secrets that aren't changed.

Radvendii avatar Jan 12 '22 16:01 Radvendii

If it's helpful to anyone else who's trying. my attempt looked like:

-    mv -f "$TMP_FILE" "$_truePath"
+
+    # only update the file if it's changed in some way
+    # NOTE: diff has opposite return value than expected
+    if ! [ -f $_truePath ] || \
+       ! diff -q $TMP_FILE $_truePath >/dev/null || \
+       [ "$(stat -c '%a' "$TMP_FILE")" -eq "$(stat -c '%a' "$_truePath")" ]
+    then mv -f "$TMP_FILE" "$_truePath"
+    fi

Radvendii avatar Jan 12 '22 20:01 Radvendii

https://github.com/ryantm/agenix/pull/132 has a minimal implementation to only create new generations when a secret has changed.

erikarvstedt avatar Jan 10 '23 12:01 erikarvstedt