Skip to content

feat(cloudsqlpg): add native read-only session locking - #3619

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

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

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 PostgreSQL.

Changes

  • Appends options='-c cloudsql_session_read_only=locked' to the connection DSN when readOnly: true is configured on the source.
  • Added ReadOnly bool to cloudsqlpg.Config and implemented IsReadOnly() bool on cloudsqlpg.Source.
  • Updated prebuilt configuration templates (cloud-sql-postgres.yaml and cloud-sql-postgres-admin.yaml) to dynamically resolve read-only mode via the CLOUDSQL_PG_READONLY environment variable (readonly: ${CLOUDSQL_PG_READONLY:false}).
  • Enforces non-bypassable read-only mode at the PostgreSQL kernel level, preventing physical Transaction ID (XID) allocation for DML/DDL mutations, transaction breakout attacks (e.g. COMMIT; DROP TABLE;), and side-effecting stored procedures.
  • Added unit tests in cloud_sql_pg_test.go, 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 support for Cloud SQL Postgres by adding a CLOUDSQL_PG_READONLY configuration, a new execute_sql_readonly tool, and enforcing the cloudsql_session_read_only=locked option in the connection string. An integration test is also added to verify that write operations are rejected in read-only mode. The feedback suggests improving the integration test's robustness by making the error message assertion case-insensitive.

@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-cloudsqlpg branch from cff807b to 0c67add 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-cloudsqlpg branch from 0c67add to d641571 Compare July 14, 2026 08:13
@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 the Cloud SQL Postgres source, adding configuration options, a read-only execution tool, and DSN-level enforcement using cloudsql_session_read_only=locked. It also includes an integration test to verify that write operations are rejected under this mode. The reviewer feedback suggests improving the integration test by constructing the configuration map directly in Go rather than parsing a raw YAML template string, which also allows removing the unused gopkg.in/yaml.v3 import.

@anubhav756
anubhav756 marked this pull request as ready for review July 14, 2026 13:29
@anubhav756
anubhav756 requested review from a team as code owners July 14, 2026 13:29
@anubhav756 anubhav756 assigned Yuan325 and unassigned anubhav756 Jul 14, 2026
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlpg branch 2 times, most recently from adfe355 to 7a43fcc Compare July 15, 2026 08:08
Comment thread docs/CLOUDSQLPG_README.md Resolved
@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-cloudsqlpg branch from 7a43fcc to 71bdd26 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-cloudsqlpg branch from 0df5dbc to 4248f3a Compare August 6, 2026 13:14
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from 8a7ace5 to 6242771 Compare August 10, 2026 19:31
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlpg branch from 4248f3a to 9ae7050 Compare August 10, 2026 19:31
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from 6242771 to cc44835 Compare August 10, 2026 20:19
@anubhav756
anubhav756 force-pushed the anubhav-readonly-cloudsqlpg branch from 9ae7050 to 2a9fa48 Compare August 10, 2026 20:19
@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-cloudsqlpg branch from 2a9fa48 to d7e5a19 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-cloudsqlpg branch from d7e5a19 to e3244d8 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-cloudsqlpg branch from e3244d8 to aaa45f2 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-cloudsqlpg branch from aaa45f2 to 8dd2503 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-cloudsqlpg branch from 8dd2503 to c960c33 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-cloudsqlpg branch from c960c33 to 7e458f1 Compare August 11, 2026 02:59
@anubhav756
anubhav756 force-pushed the anubhav-readonly-core branch from bddc2c0 to fd7a8e9 Compare August 11, 2026 03:06
@averikitsch

Copy link
Copy Markdown
Contributor

nit: please update the admin source docs

@anubhav756

Copy link
Copy Markdown
Contributor Author

nit: please update the admin source docs

Updated docs. Thanks for bringing that up!

@github-actions

Copy link
Copy Markdown
Contributor

🧨 Preview deployments removed.

Cloudflare Pages environments for pr-3619 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