Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of operations #117

Closed
jsimonetti opened this issue Jul 7, 2022 · 4 comments · Fixed by #119
Closed

Order of operations #117

jsimonetti opened this issue Jul 7, 2022 · 4 comments · Fixed by #119

Comments

@jsimonetti
Copy link
Contributor

As suggested in Matrix I am creating this issue about the order in which agenix operates.

When switching generations I consistantly see the following order of operations in the log output:

[agenix] symlinking new secrets to /run/agenix (generation 6)...
[agenix] removing old secrets (generation 5)...
[agenix] decrypting root secrets...
decrypting '/nix/store/xxx.age' to '/run/agenix.d/6/xxx'...
decrypting '/nix/store/yyy.age' to '/run/agenix.d/6/yyy'...
[agenix] decrypting non-root secrets...
decrypting '/nix/store/zzz.age' to '/run/agenix.d/6/zzz'...

This got me wondering as I would expect the order of operations to be:

  1. decrypt secrets into new generation
  2. symlink new secrets
  3. remove old generation/secrets

Could we get some clarification about the actual order?

@jsimonetti
Copy link
Contributor Author

jsimonetti commented Jul 7, 2022

Looking at the source at https://github.com/ryantm/agenix/blob/main/modules/age.nix#L155 it looks like the logged order is actually the order in which operations take place.

The agenixMountSecret activation script creates a new generation, (forcefully) symlinks it to the ${cfg.secretsDir} and (if it is larger then 1) removes the old generation.

The installRootOwnedSecrets and installNonRootSecrets both depend on agenixMountSecret and are therefor executed after that.

If I read this correctly, there a brief state in which the current/old generation no longer exists and the new/to-be generation is still empty (no decrypted secrets).

@jsimonetti
Copy link
Contributor Author

jsimonetti commented Jul 7, 2022

I think the solution would be to move lines 174-178 from https://github.com/ryantm/agenix/blob/main/modules/age.nix#L174 to a new script that depends on the installRootOwnedSecrets and installNonRootSecrets scripts.

What do you think? I can make a PR if you agree.

@ryantm
Copy link
Owner

ryantm commented Jul 7, 2022

@cole-h as the author of the symlinking PR, maybe you can comment?

@cole-h
Copy link
Collaborator

cole-h commented Jul 8, 2022

Yeah, that sounds like a good change to make -- thanks for catching that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants