Skip to content

google: write Cloud SQL keyfile_dict credentials with 0600 permissions#67507

Open
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:google-creds-file-0600
Open

google: write Cloud SQL keyfile_dict credentials with 0600 permissions#67507
potiuk wants to merge 1 commit into
apache:mainfrom
potiuk:google-creds-file-0600

Conversation

@potiuk
Copy link
Copy Markdown
Member

@potiuk potiuk commented May 25, 2026

When the Google connection supplies credentials via keyfile_dict, CloudSqlProxyRunner._get_credential_parameters writes the credentials file with open(path, "w") at cloud_sql.py:629. That inherits the process umask (typically 0o644), leaving the service-account private key world-readable on shared worker hosts — including any other process on the same machine that can read the worker's temp directory.

Reported as F-004 in the apache/tooling-agents L3 providers/google sweep b1aec75.

Change

Use os.open(..., O_WRONLY | O_CREAT | O_TRUNC, 0o600) followed by os.fdopen so the file is created with restrictive permissions atomically. Matches the explicit-mode handling already used for the SSL temp files in the same module.

Test plan

  • Added test_credentials_file_from_keyfile_dict_is_chmod_0600 — writes credentials via the real code path, reads Path.stat().st_mode, asserts stat.S_IMODE == 0o600.
  • prek run ruff clean on touched files.
  • breeze run mypy clean on the source file.
  • Existing test_cloud_sql_proxy_runner_keeps_key_path_credentials_with_iam_login still passes (no behaviour change on the key_path branch).

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

When the Google connection supplies credentials via ``keyfile_dict``,
``CloudSqlProxyRunner._get_credential_parameters`` wrote the credentials
file with ``open(path, "w")``. That inherits the process umask
(typically ``0o644`` on most distributions), leaving the service-account
private key world-readable on shared worker hosts — including any
other process on the same machine that can read the worker's temp
directory.

Use ``os.open(..., O_WRONLY | O_CREAT | O_TRUNC, 0o600)`` followed by
``os.fdopen`` so the file is created with restrictive permissions
atomically. Matches the explicit-mode handling already used for the
SSL temp files in the same module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant