Skip to content

create config file with owner-only permissions at both write sites - #333

Draft
vkrastanov wants to merge 1 commit into
cloudfoundry-community:mainfrom
vkrastanov:patch-2
Draft

vkrastanov wants to merge 1 commit into
cloudfoundry-community:mainfrom
vkrastanov:patch-2

Conversation

@vkrastanov

Copy link
Copy Markdown

~/.cf_client_python.json holds the long-lived refresh token, but both write sites created it with a plain open(path, "w") and no permission control, so its mode was silently inherited from the caller's umask — world-readable (0644) under the default umask 022. This is inconsistent with how credential files are normally handled and leaves the token readable by any other local user or process on a shared host.

Add a _write_config_file helper and route both write sites through it: import_from_clf_cli() and the interactive first-run path in build_client_from_configuration(). The helper creates the file with os.open(..., 0o600) and unconditionally chmods it to 0600 afterwards, so an existing file left loose by an earlier version gets tightened on the next write as well.

Behavior verified before/after: 0644 (unfixed, umask 022) -> 0600 for new files under umask 022/077 and for pre-existing 0644 files, with identical file content in all cases.

~/.cf_client_python.json holds the long-lived refresh token, but both
write sites created it with a plain open(path, "w") and no permission
control, so its mode was silently inherited from the caller's umask —
world-readable (0644) under the default umask 022. This is inconsistent
with how credential files are normally handled and leaves the token
readable by any other local user or process on a shared host.

Add a _write_config_file helper and route both write sites through it:
import_from_clf_cli() and the interactive first-run path in
build_client_from_configuration(). The helper creates the file with
os.open(..., 0o600) and unconditionally chmods it to 0600 afterwards,
so an existing file left loose by an earlier version gets tightened on
the next write as well.

Behavior verified before/after: 0644 (unfixed, umask 022) -> 0600 for
new files under umask 022/077 and for pre-existing 0644 files, with
identical file content in all cases.
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.

2 participants