Repository navigation
Conversation
…ile's directory. By default sops looks for .sops.yaml starting at the current working directory. With the new opt-in flag (or SOPS_CONFIG_FROM_FILE_DIR) the search starts at the directory of the file being operated on instead, and walks up from there. The flag only changes the starting point, it never merges two configs, and --config still takes precedence. Default behavior is unchanged. updatekeys looks the config up per file when the flag is set, and publish starts from its file argument. Also switch LookupConfigFile from path to path/filepath. path.Dir does not understand Windows separators, so an absolute Windows file path would have silently fallen back to the current directory. Fixes getsops#242 Signed-off-by: Ethan Aldrich <ethan@ethanaldrich.net>
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 searches for
.sops.yamlstarting at the current working directory. If you runsops -e path/to/secret.yamlfrom somewhere else, the config next to the file is not found.This adds an opt-in global flag,
--config-from-file-dir(envSOPS_CONFIG_FROM_FILE_DIR). When set, the search starts at the directory of the file being operated on and walks up from there, as it does today from the cwd.On the precedence question raised in the issue: the flag only replaces the starting point of the search. Exactly one config is ever used, two configs are never merged, and
--configstill wins when given. Without the flag nothing changes, so the current cwd behavior stays the default. Looking in the cwd was an explicit choice in 597acb7 ("Look for config file in cwd, not in the directory of the edited file"), and autrilla's 2017 comment on this issue explains why, so I did not want to change it for everyone.Details:
findConfigFilenow takes the target file and uses it as the start when the flag is set.loadConfigandloadStoresConfigalready receive the file, so encrypt, decrypt, edit, rotate, set, unset, exec-env, exec-file, filestatus and groups are covered. With--filename-overridethe override is used, the same path that is matched againstpath_regex.updatekeysdoes the lookup per file when the flag is set, since each file may have a different config. A file with no config is reported as a failure and the others still run.publishstarts from its argument (a directory argument is searched from inside that directory). Withpublish --recursive, the destination rules come from the config found for the top-level argument, not per subfile.path_regexin destination rules is still matched against the path as given on the command line, as before.LookupConfigFileusedpath.Dir/path.Join, which do not handle Windows separators:path.Dir("C:\a\f.yaml")returns".", which would silently fall back to the cwd. It now usespath/filepath. Behavior for"."and POSIX paths is unchanged.Testing:
configthat starts the lookup at a nested file path through the existing mock fs.make testin golang:1.25 passes exceptTestMasterKey_Identities_Passphraseinage, which also fails on main.go vet,make vendor && git diff --exit-codeandGOOS=windows go build ./cmd/sopsare clean.path_regex: ^b/rule ina/.sops.yaml, whereencryptandupdatekeysona/b/secret.yamlmatch correctly with relative paths;publish a/b/secret.yamlfinds the destination): witha/b/.sops.yaml(age rule) anda/b/secret.yaml, runningsops -e a/b/secret.yamlfrom the parent fails with "config file not found, or has no creation rules..." without the flag, and succeeds with--config-from-file-dirand withSOPS_CONFIG_FROM_FILE_DIR=1. With--config other.yamladded,other.yamlis used.I did not add a cmd-level test, as there is no existing harness for invoking the CLI actions.
Suggested text for getsops/docs (config file section):
Closes #242