Repository navigation
Allow passing several files to exec-env - #2324
Open
abd-ulbasit wants to merge 1 commit into
Open
abd-ulbasit wants to merge 1 commit into
abd-ulbasit wants to merge 1 commit into
Conversation
All arguments except the last one are now files to decrypt; the last one is still the command to run. The values of all files are inserted into the environment. If a key appears in several files, the value from the last of these files is used, which is the same result as nesting one exec-env call per file. Only that last value is passed on, so which file wins does not depend on how the started process (or execve with --same-process) handles duplicate keys. All files are decrypted before the command starts, so if one of them fails, the command does not run. With more than one file, an error about one of the files starts with its name. Errors loading the config file are not prefixed, since the same config applies to all files. Calls with a single file give the same output, error messages and exit codes as before. The only difference is the order of the checks: the flags are now checked before the config file is loaded, so if both are invalid, the error about the flags is reported. Signed-off-by: abd-ulbasit <basit@basit.engineer>
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.
Refs #945
This lets
sops exec-envtake more than one encrypted file:All arguments except the last are files; the last is the command, run through
sh -cas today. It's the smallest piece of #945, along the lines of the suggestion in #945 (comment).Behaviour:
sops exec-env a.yaml "sops exec-env b.yaml 'cmd'". Files still override the inherited environment, as before.exec.MergeEnv), so which file wins doesn't depend on how the child process, orexecvewith--same-process, treats duplicate keys.sops metadata not found) don't say which file failed. Exit codes are unchanged. Errors loading.sops.yamlkeep their message, since the config is the same for all files.--config, or the.sops.yamlfound from the working directory),--decryption-order,--ignore-macand the key service flags are the same for all files.Compatibility:
error: missing file to decrypt. So nothing that works today changes meaning. Single-file calls give the same output, error messages and exit codes as before, with one exception: the config is now loaded after the flags are checked. So if both.sops.yamland the flags are invalid, the flag error is reported instead of the config error.sops exec-env f.yaml -- npm start) still fails, but now the error is about a file namednpminstead ofmissing file to decrypt.exec-env a.yaml --pristine b.yaml cmddecryptsb.yamlfirst). That's existing parser behaviour and I didn't try to work around it here; theexec-envhelp text now says so.Not in this PR:
exec-filewith several files (it needs one placeholder per file).decryptwith several files or a bulk subcommand. @felixfontein, you suggested separate subcommands for that in Feature request: Support decrypting multiple files at a time #945 (comment), so I'd leave that design to you.Open question: this uses the positional tail that the argv mode in #1469 might want. If you'd rather keep that free, I can switch to a repeatable flag for the extra files.
Heads-up: #2321 adds a field to the exec-env
decryptOpts, which this PR moves intodecryptFileToEnv. Whichever lands second needs a small rebase; I'm happy to do it here.Tests:
cmd/sops/subcommand/exec/exec_test.go:MergeEnv.cmd/sops/exec_env_test.go:envFromTreeand the file-name prefix. The existing error messages are pinned byte-for-byte.exec_env_multiple_files: two files with a shared key, in both orders. Then three failures where the command doesn't run: an unencrypted second file (the error starts with its name), that file alone (same message as today, no prefix), and a broken--configwith two files (no prefix).go vet,gofmt -s,go test -racefor./cmd/sops/...,cargo fmt --check, and the functional tests (all pass except the two Vault publish tests, which need a Vault server). I also checked by hand with age-encrypted YAML, dotenv and JSON files, including--pristineand--same-process.Once the shape is settled I'll send a PR to getsops/docs for the exec-env section.