Skip to content

[v2] Write config file atomically in aws configure set - #10649

Open
lazerg wants to merge 1 commit into
aws:v2from
lazerg:fix-configure-set-atomic-write
Open

lazerg wants to merge 1 commit into
aws:v2from
lazerg:fix-configure-set-atomic-write

Conversation

@lazerg

@lazerg lazerg commented Sep 16, 2026

Copy link
Copy Markdown

Issue #, if available:
Fixes #10648

ConfigFileWriter.update_config reopened the config file with open(config_filename, 'w'), which truncates it before any of the new contents are written. If that write failed or the process died in between, the file was left at 0 bytes and every profile in it was gone, not just the one being edited. On the shared credentials file that means secret access keys that cannot be fetched again.

Description of changes:
Write the new contents to a temporary file in the same directory, copy the original file's permissions onto it, and os.replace() it over the original, removing the temporary file if anything fails. A failed write now leaves the old file untouched.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@lazerg
lazerg requested a review from a team as a code owner September 16, 2026 13:07
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