Skip to content

fix(config): keep the credentials file readable by its owner alone - #258

Merged
tas50 merged 1 commit into
mainfrom
fix/config-tighten-credentials-permissions
Sep 24, 2026
Merged

tas50 merged 1 commit into
mainfrom
fix/config-tighten-credentials-permissions

Conversation

@tas50

@tas50 tas50 commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

cinc created a new credentials file with mode 0600, because os.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, at 0644. So after cinc config create or 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 to 0600 before writing anything into it. That covers config create (add, update and replace), first-run configure and migration. On Windows Chmod only controls the read-only bit, and 0600 keeps the file writable, so nothing changes there.

docs/configuration.md now says the file is kept readable by its owner alone. It also gets the config validate --profile example missing from #256.

Tests

  • TestWriteProfileTightensAnExistingFile: a 0644 file becomes 0600 after an update.
  • A new integration case, cli/config-create-tightens-permissions, updates a profile in a 0644 credentials file through the real binary, checks the file is 0600, and checks the new profile works.

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>
@tas50
tas50 merged commit 7f60fd3 into main Sep 24, 2026
6 checks passed
@tas50
tas50 deleted the fix/config-tighten-credentials-permissions branch September 24, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant