age: optional caching of key command output#2247
Open
oivindoh wants to merge 1 commit into
Open
Conversation
SOPS constructs one MasterKey per recipient and loads identities for each in turn, executing SOPS_AGE_KEY_CMD / SOPS_AGE_SSH_PRIVATE_KEY_CMD once per attempted recipient. With a slow command (e.g. a password manager CLI) a single decrypt multiplies into many seconds. Setting SOPS_AGE_KEY_CMD_CACHE=true executes each command at most once per process and reuses the output for every recipient. Opt-in because the command receives SOPS_AGE_RECIPIENT and may legitimately return a different key per recipient. Only successful outputs are cached, and the lock is not held while the command runs, so a failing or slow command cannot poison or serialise decrypts in long-lived processes such as the keyservice. Signed-off-by: Øivind Hoel <oivind.hoel@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since sops loads identities once per recipient it attempts, executing
SOPS_AGE_KEY_CMD/SOPS_AGE_SSH_PRIVATE_KEY_CMDeach time when set, using slow clients likebwis painful when files have many recipients. In my testing, a file with 7 recipients where the matching key is last takes ~20 seconds to finish decrypting.To fix this, add the opt-in
SOPS_AGE_KEY_CMD_CACHEto make the command run at most once per process and reuse the result for each recipient. If unset or false, no behaviour changes.Opt-in because a command may use
SOPS_AGE_RECIPIENTto return a different key per recipient; caching can break that (a command that exits non-zero for unknown recipients survives, since errors are not cached). The flag is only for commands that ignore the recipient.Tests cover once-per-process with the flag, once-per-recipient without, and errors not being cached.