Repository navigation
fix(config): keep the credentials file readable by its owner alone - #258
Merged
Merged
Conversation
cinc created a new credentials file with mode 0600, but a rewrite of an existing file kept whatever mode it had. Knife setups often leave ~/.chef/credentials, and files copied from it, at 0644, so profiles naming private keys and data bag secrets stayed readable by every user on the machine after cinc updated them. Every write now tightens the file to 0600 before anything is written into it. Signed-off-by: Tim Smith <tsmith84@proton.me>
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.
cinc created a new credentials file with mode
0600, becauseos.OpenFile's mode only applies on create. Rewriting an existing file kept whatever mode it had. Knife setups often leave~/.chef/credentials, and files copied from it, at0644. So aftercinc config createor first-run setup updated such a file, its profiles, which name private keys and data bag secrets, stayed readable by every user on the machine.WriteProfileWithExtras, the one place a credentials file is written, now sets the file to0600before writing anything into it. That coversconfig create(add, update and replace), first-run configure and migration. On WindowsChmodonly controls the read-only bit, and0600keeps the file writable, so nothing changes there.docs/configuration.mdnow says the file is kept readable by its owner alone. It also gets theconfig validate --profileexample missing from #256.Tests
TestWriteProfileTightensAnExistingFile: a0644file becomes0600after an update.cli/config-create-tightens-permissions, updates a profile in a0644credentials file through the real binary, checks the file is0600, and checks the new profile works.