Repository navigation
Keep edits made with sops edit --show-master-keys - #2328
Open
SkippySteve wants to merge 1 commit into
Open
SkippySteve wants to merge 1 commit into
SkippySteve wants to merge 1 commit into
Conversation
With --show-master-keys the editor gets the whole tree including the sops metadata, and runEditorUntilOk replaced the tree after reloading it with `opts.Tree = &t`. That only changed the local copy of the options; the caller then encrypted and wrote back its original tree, so the edit was silently discarded (exit 0, new MAC and timestamp, old content). Update the caller's tree in place instead, and only replace the branches in the non --show-master-keys path. Signed-off-by: Steven Richards <steve@aimingupward.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.
sops edit --show-master-keys(-s) silently discards the edit. The command exits 0 and rewrites the file with a new MAC andlastmodified, but with the old content.Cause: with
-s,runEditorUntilOkreloads the full tree (data + metadata) from the editor's file and then doesopts.Tree = &t. That only updates the local copy ofopts.edit()then encrypts and emits its own, unchanged tree. This goes back to the store refactor in #335.Fix: update the caller's tree in place (
*opts.Tree = t, keepingFilePath), and only assignBranchesin the non--spath, where the editor sees just the data.Reproduction with a throwaway age key, and an editor script that changes
password: oldtopassword: new:Test: a new
cmd/sops/edit_test.go(TestEditKeepsChanges, run with and withoutShowMasterKeys) encrypts a file with a generated age key, runsedit()with a scriptedSOPS_EDITOR, and decrypts the result. Onmaintheshow-master-keyscase fails (expected "secret: new\n",actual "secret: old\n"). The small shared helpers are incmd/sops/helpers_test.go. They isolateHOMEand theSOPS_AGE_*variables so a developer's own keys are never used.go test ./cmd/... .,go vetandgofmtare clean on Go 1.25.