Skip to content

Add Cloud SQL Auth Proxy v2 support to CloudSqlProxyRunner - #73646

Merged
shahar1 merged 8 commits into
apache:mainfrom
arno-fukuda:fix/cloud-sql-proxy-v2
Nov 6, 2026
Merged

shahar1 merged 8 commits into
apache:mainfrom
arno-fukuda:fix/cloud-sql-proxy-v2

Conversation

@arno-fukuda

@arno-fukuda arno-fukuda commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

CloudSqlProxyRunner only knows how to run Cloud SQL Auth Proxy v1: the download URLs point at the v1 buckets and the command line uses v1-only flags (-dir, -instances, -credential_file, -enable_iam_login). As reported in #72681, v1 fails caching_sha2_password full authentication on Cloud SQL for MySQL 8.4, so the first connection after a restart/failover fails with 1045 Access denied. v1 is also no longer developed.

This PR adds opt-in v2 support through a new sql_proxy_major_version runner argument and CloudSQLDatabaseHook connection extra. The default stays 1, so existing behaviour does not change. With sql_proxy_major_version=2:

  • The binary is downloaded from https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/<version>/cloud-sql-proxy.<os>.<arch>, which is where Google publishes v2. v2 has no "latest" download, so sql_proxy_version (e.g. v2.27.0) is required unless sql_proxy_binary_path points to an existing binary.
  • The command line uses v2 flags: --unix-socket <dir> <instance>, --credentials-file, --auto-iam-authn, and always --auto-ip. v2 connects only to the public IP by default, and --auto-ip keeps v1's fallback to the private IP for private-IP-only instances. It needs v2.2.0 or newer. In TCP mode the hook builds <instance>?port=<port> instead of <instance>=tcp:<port>; v2 uses TCP for that instance even with --unix-socket set.
  • v2 logs its ready line (The proxy has started successfully and is ready for new connections!) to stdout, not stderr. So in v2 mode start_proxy merges stderr into stdout and reads from there. The ready-line check is now case-insensitive so it matches both versions.
  • get_proxy_version parses v2's --version output (cloud-sql-proxy version 2.14.0+linux.amd64).
  • If instance_specification is empty, v2 mode raises an error, because v2 can't forward every instance in a project (no -projects equivalent).
  • v2 configuration errors (missing or invalid sql_proxy_version when the binary has to be downloaded, empty instance) are raised when the runner is created, so they aren't hidden by the operator's stop_proxy() cleanup. A v2.x sql_proxy_version with the default major version 1 is rejected with a hint to set sql_proxy_major_version.

The connection docs cover the new extra. They also now say that IAM login through the proxy is Postgres-only on v1 and that MySQL needs v2, per Google's Cloud SQL docs. The previous text said v1 supported both. The docs also cover the v1-to-v2 differences users can run into: the v2.2.0 minimum, MySQL 8.4 needing v2.19.0 or newer over the default Unix socket, v2 using only Application Default Credentials where v1 also tries the active gcloud account, and v2 billing its Cloud SQL Admin API calls to the credentials' quota project.

Known issue, not addressed here: the proxy's output pipe isn't drained after startup. v1 already has this with stderr, and v2 inherits it on stdout. Left for a follow-up.

Relation to #72785

This supersedes #72785, which had the same idea. Compared with that PR, this one:

  • downloads from the GCS bucket above. The cloud-sql-proxy GitHub releases have no binary assets, so the GitHub URL used in Add Cloud SQL Auth Proxy v2 mode to CloudSqlProxyRunner #72785 returns 404.
  • reads the v2 ready line from stdout. Add Cloud SQL Auth Proxy v2 mode to CloudSqlProxyRunner #72785 only read stderr and matched ready to accept new connections, which v2 never prints, so start_proxy would block.
  • passes --credentials-file (v2 rejects -credential_file) when key_path/keyfile_dict is set.
  • wires the option through CloudSQLDatabaseHook/CloudSQLExecuteQueryOperator, including TCP mode.
  • raises ValueError instead of adding new AirflowException usages (check-no-new-airflow-exceptions).
  • drops the airflow-core/newsfragments entry, since this is a provider-only change.

Testing

  • New unit tests cover v2 command lines (unix socket, TCP, IAM), download URL and version validation, the credentials flag, the empty-instance error, start_proxy reading the ready line from stdout, get_proxy_version parsing, early validation, and hook wiring (TCP mode and invalid sql_proxy_major_version values). test_cloud_sql.py for both hooks and operators: 198 passed.
  • prek run --stage pre-commit on the changed files passes. Only check-provider-yaml-valid was skipped, because it needs breeze and provider.yaml is unchanged. mypy on the hook module is clean.
  • Manual check with the real v2.14.0 binary through CloudSqlProxyRunner (darwin/arm64, ADC): download, get_proxy_version() → 2.14.0+darwin.arm64, start_proxy() with --unix-socket plus ?port= listens on TCP and returns on the ready line, and in unix-socket mode an invalid instance shows up as the existing googleapi: Error failure.
  • System test cloudsql_query_proxy_iam passed against a real Cloud SQL instance with sql_proxy_major_version=2 and proxy v2.26.0 (Postgres 15, IAM login through the proxy over TCP, Breeze on linux/arm64). The task log shows the v2 download location, --auto-ip --auto-iam-authn on the command line, and SELECT 1 through the proxy. Screenshots: Add Cloud SQL Auth Proxy v2 support to CloudSqlProxyRunner #73646 (comment). The run used this PR's commits applied to the then-current main, because the branch's base could no longer build the CI image at the time (fixed in Install OS dependencies on hardened images after dhi.io renumbering #76200).
  • The system test uses Postgres, so the MySQL 8.4 caching_sha2_password behaviour still relies on the reproduction in CloudSqlProxyRunner cannot authenticate against Cloud SQL for MySQL 8.4 (caching_sha2_password full auth fails on Auth Proxy v1) #72681.

closes: #72681


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

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

I reviewed the generated changes, checked the v2 behaviour described above against the cloud-sql-proxy v2 source and the real binary, and ran the tests and static checks listed above.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

🤖 Generated with Claude Code

@boring-cyborg boring-cyborg Bot added area:providers kind:documentation provider:google Google (including GCP) related issues labels Sep 24, 2026
@boring-cyborg

boring-cyborg Bot commented Sep 24, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@arno-fukuda
arno-fukuda force-pushed the fix/cloud-sql-proxy-v2 branch from 55f62be to 48bd721 Compare September 24, 2026 07:50
@arno-fukuda
arno-fukuda marked this pull request as ready for review September 24, 2026 08:00

@fat-catTW fat-catTW left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See no blocker to me.
Nice fix.

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, v2 support is overdue. The flag mapping, readiness detection, version parsing and download URL all look right. One behaviour difference inline between v1 and v2 that would break private-IP-only instances.


Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting

@MaksYermak MaksYermak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arno-fukuda thank you for the PR!
LGTM, could I ask you to run this system test cloudsql_query_proxy_iam for yours changes and provide the screenshot from Airflow UI that everything is green?

@shahar1 what do you think about this changes?

Cloud SQL Auth Proxy v1 connects to the public IP and falls back to the
private IP, while v2 connects to the public IP only unless told
otherwise. Instances with only a private IP therefore worked with v1 but
failed after switching to v2, and only at query time, because v2 still
reports that it is ready for new connections.
@arno-fukuda
arno-fukuda force-pushed the fix/cloud-sql-proxy-v2 branch from b0f2691 to 8f9298e Compare October 28, 2026 07:44

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the --auto-ip fix — that keeps v1's public-then-private fallback for private-IP-only instances on v2, and the docs explain it. Looks good to me.

@arno-fukuda before this can be merged we need the screenshot @MaksYermak asked for: please run the cloudsql_query_proxy_iam system test with sql_proxy_major_version=2 and post a screenshot from the Airflow UI showing it green.


Drafted-by: Claude Code (Claude Opus 5); reviewed by @potiuk before posting

@arno-fukuda

Copy link
Copy Markdown
Contributor Author

@arno-fukuda before this can be merged we need the screenshot @MaksYermak asked for: please run the cloudsql_query_proxy_iam system test with sql_proxy_major_version=2 and post a screenshot from the Airflow UI showing it green.

Thanks, this is done:
Screenshot 2026-11-02 at 11 36 44

Screenshot 2026-11-02 at 11 39 31

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The v2 flags, download URL, ready-line handling and version parsing all match the proxy's sources, and the code looks good to me. Three small documentation gaps about v1-to-v2 differences are inline; none of them blocks the merge.

Smaller observations

  • The Testing section of the PR description still says this wasn't tested against a real Cloud SQL instance. Could you update it with the cloudsql_query_proxy_iam run? That test uses Postgres, so the MySQL 8.4 behaviour still rests on the reproduction in #72681, which is worth keeping in the description.
  • Three more are posted as inline comments on providers/google/docs/connections/gcp_sql.rst.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

Users switching to v2 need to know which releases work, why MySQL 8.4
needs v2, and that v2 picks up credentials and the quota project
differently from v1, since those differences only show up as
connection or permission failures at runtime.
@arno-fukuda

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three inline points are addressed in 7913c42. The Testing section of the PR description now includes the cloudsql_query_proxy_iam run on v2 and links the screenshots. It keeps the MySQL 8.4 reproduction from #72681, since that system test uses Postgres.


Drafted-by: Claude Code (Opus 5.5); reviewed by @arno-fukuda before posting

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all three points: the v2.2.0 minimum, the MySQL 8.4 note and the authentication differences are now documented and match the proxy's sources. The only code change since my last review is the log line, which looks fine.

One thing I missed last time: v2.2.0 is the minimum for the flags, but not for the fix this PR closes. caching_sha2_password support over Unix sockets only arrived in proxy v2.19.0, so the docs as written can point MySQL 8.4 users at a v2 release that still fails. Details are inline. Could you also say which v2 release you used for the reproduction in #72681?


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.


Drafted-by: Claude Code (Opus 5.5); reviewed by shahar1 before posting

caching_sha2_password full authentication only works through the proxy
from v2.19.0 and over Unix sockets, so the earlier wording could lead
MySQL 8.4 users to a v2 setup that still fails. The examples now use a
current release that also meets Google's latest minimum.

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all three points from my last review are fixed and match the sources. The v2.19.0 minimum and the Unix socket requirement for MySQL 8.4 are documented, MySqlHook has no public key retrieval option in either client path, and v2.27.0 is the latest proxy release, with the download URL the runner builds listed in its release notes. Only docs, docstrings and one error message changed since my last review, and CI is green at this head.

Not blocking: the PR description leaves the undrained proxy output for a follow-up, and I didn't find an issue for it. Could you open one so it isn't lost?


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Airflow handles maintainer review:
Contributing guide.


Drafted-by: Claude Code (Opus 5.5); reviewed by shahar1 before posting

@shahar1
shahar1 merged commit f396a3b into apache:main Nov 6, 2026
80 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 6, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@shahar1

shahar1 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@arno-fukuda great work for a first PR :)
I'll be happy to see more of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudSqlProxyRunner cannot authenticate against Cloud SQL for MySQL 8.4 (caching_sha2_password full auth fails on Auth Proxy v1)

5 participants