Skip to content

feat(cloudsqlmysql): add native read-only session locking - #3618

Merged
anubhav756 merged 1 commit into
feat/read-onlyfrom
anubhav-readonly-cloudsqlmysql
Aug 27, 2026
Merged

anubhav756 merged 1 commit into
feat/read-onlyfrom
anubhav-readonly-cloudsqlmysql

Conversation

@anubhav756

@anubhav756 anubhav756 commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR implements native, protocol-level Read-Only session enforcement for Cloud SQL for MySQL.

Changes

  • Appends &session_variables=cloudsql_session_read_only%3Dlocked to the connection DSN when readOnly: true is configured on the source.
  • Added ReadOnly bool to cloudsqlmysql.Config and implemented IsReadOnly() bool on cloudsqlmysql.Source.
  • Updated prebuilt configuration templates (cloud-sql-mysql.yaml and cloud-sql-mysql-admin.yaml) to dynamically resolve read-only mode via the CLOUDSQL_MYSQL_READONLY environment variable (readonly: ${CLOUDSQL_MYSQL_READONLY:false}).
  • Enforces non-bypassable session locking directly within the MySQL database engine upon connection handshake, thwarting prompt injection mutations and multi-statement breakout attempts.
  • Added unit tests, integration vulnerability tests, and updated integration READMEs.

@anubhav756 anubhav756 self-assigned this Jul 14, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces read-only mode support for the Cloud SQL MySQL source. It adds a readonly configuration option, configures the database connection pool to enforce read-only sessions via cloudsql_session_read_only=locked when enabled, introduces a prebuilt execute_sql_readonly tool, and adds an integration test to verify the read-only enforcement. The feedback recommends renaming the environment variable CLOUDSQL_MYSQL_READONLY to CLOUD_SQL_MYSQL_READONLY in both the documentation and configuration files to maintain naming consistency with existing environment variables.

Comment thread docs/CLOUDSQLMYSQL_README.md Resolved
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 2 times, most recently from a975dc7 to efeaaa2 Compare July 14, 2026 07:31
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from 9a2c11a to 67c5006 Compare July 14, 2026 07:32
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from efeaaa2 to c638838 Compare July 14, 2026 07:36
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from 67c5006 to 1440fd2 Compare July 14, 2026 08:14
@anubhav756

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a read-only mode for Cloud SQL MySQL sources, enforcing read-only session locking on the database connection via DSN parameters when enabled. It adds a new execute_sql_readonly tool, updates the configuration and source initialization, and includes an integration test to verify that write operations are rejected in read-only mode. Feedback suggests correcting the README documentation to accurately describe that the readonly option enforces session locking on the connection rather than routing queries to a read-only endpoint.

Comment thread docs/CLOUDSQLMYSQL_README.md Resolved
@anubhav756
anubhav756 marked this pull request as ready for review July 14, 2026 13:30
@anubhav756
anubhav756 requested review from a team as code owners July 14, 2026 13:30
@anubhav756 anubhav756 assigned Yuan325 and unassigned anubhav756 Jul 14, 2026
@anubhav756
anubhav756 requested review from Yuan325, averikitsch and kurtisvg and removed request for a team July 14, 2026 13:32
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch 2 times, most recently from 502e5f9 to 8f59ae2 Compare July 15, 2026 08:09
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch 6 times, most recently from c35957e to a6f8ff1 Compare July 20, 2026 14:36
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from 8f59ae2 to 2cff425 Compare July 20, 2026 15:06
@anubhav756
anubhav756 marked this pull request as draft July 20, 2026 15:50
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from a6f8ff1 to 4091cdd Compare July 20, 2026 16:02
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from cc44835 to bf538b0 Compare August 10, 2026 20:29
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from f1f111f to 8b61e58 Compare August 10, 2026 20:29
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from bf538b0 to b058146 Compare August 10, 2026 20:35
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from 8b61e58 to a10c055 Compare August 10, 2026 20:35
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from b058146 to 3bcf247 Compare August 10, 2026 21:11
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from a10c055 to e5fb97b Compare August 10, 2026 21:11
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from 3bcf247 to f9cc575 Compare August 10, 2026 21:19
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from e5fb97b to ce488fc Compare August 10, 2026 21:19
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from f9cc575 to 50037a4 Compare August 10, 2026 21:52
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from ce488fc to 407c689 Compare August 10, 2026 21:52
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from 50037a4 to bddc2c0 Compare August 11, 2026 02:59
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlmysql branch from 407c689 to 6b3b8a6 Compare August 11, 2026 02:59
@anubhav756

Copy link
Copy Markdown
Contributor Author

Hi @shuzhou-gc

Checking in to see if the explanations above addressed your questions, or if you have any further thoughts on the approach. If everything looks good, could you please give this an LGTM?

Thanks! 🙂

@rajavi-vivek rajavi-vivek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please see comments about clousql_session_readonly

@rajavi-vivek rajavi-vivek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please see the suggested changes.

@rajavi-vivek rajavi-vivek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for pulling in the recommended changes.

@github-actions

Copy link
Copy Markdown
Contributor

🧨 Preview deployments removed.

Cloudflare Pages environments for pr-3618 have been deleted.

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

Labels

priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants