Skip to content

feat: Add PSC DNS and Global Write Endpoint support to NodeJS Connector - #593

Open
hessjcg wants to merge 2 commits into
mainfrom
feat-psc-dns
Open

feat: Add PSC DNS and Global Write Endpoint support to NodeJS Connector#593
hessjcg wants to merge 2 commits into
mainfrom
feat-psc-dns

Conversation

@hessjcg

@hessjcg hessjcg commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

The Private Service Connect (PSC) DNS Name Resolution & Fallback feature enables the Go connector to securely connect to Cloud SQL database instances using Private Service Connect (PSC) DNS, custom domain names (CNAMEs), and Global Write Endpoints.

The connector can now dial PSC instances using:

Its regional DNS hostname (e.g., 0123456789ab.fedcba9876543.us-central1.sql-psc.goog)
A custom domain CNAME pointing to the instance PSC DNS hostname
A Global Write Endpoint DNS hostname (e.g., 0123456789ab.fedcba9876543.global.sql-psc.goog)
The connectors will dynamically resolve this hostname to its real Cloud SQL instance connection name via the SQL Admin API.

For Global Write Endpoints (which use the "global" region in their DNS name), the resolver bypasses direct API resolution (as "global" is not a valid API region) and forces fallback to CNAME resolution. This CNAME should point to the active regional instance DNS hostname, enabling automatic failover.

See: GoogleCloudPlatform/cloud-sql-go-connector#1106

@hessjcg
hessjcg requested a review from a team as a code owner July 24, 2026 20:15
@google-cla

google-cla Bot commented Jul 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment thread src/cloud-sql-instance.ts Outdated
hessjcg added 2 commits July 24, 2026 21:32
This change implements Private Service Connect (PSC) DNS Name Resolution & Fallback feature for the NodeJS connector, allowing it to securely connect to Cloud SQL database instances using PSC DNS hostnames, custom domain names (CNAMEs), and Global Write Endpoints.

- Updated dns-lookup.ts to support CNAME resolution and return sorted TXT records.
- Updated sqladmin-fetcher.ts to implement resolveConnectSettings calling the SQL Admin API endpoint.
- Updated parse-instance-connection-name.ts with the resolution algorithm:
  - Match well-known DNS pattern and resolve via SQL Admin API.
  - Fallback to TXT records.
  - Fallback to CNAME records (up to depth 10 to prevent loops).
- Made `instanceConnectionName` optional in `ConnectionOptions` to allow only `domainName` to be provided, and updated `resolveInstanceName` to handle domain names passed in `instanceConnectionName` parameter.
- Fixed a bug in `sqladmin-fetcher.ts` where a missing trailing slash on `rootUrl` caused incorrect API URLs.
- Updated tests and mocks to verify the new resolution logic and parameter options.
- Implement transient vs non-transient error detection in CloudSQLInstance.
- Detect immutable instance DNS names using the corrected regex.
- Avoid checking error message strings by using error codes (ECNAMELOOPLIMITEXCEEDED, etc.) and response status.

Address review comments:
- kgala2: 'Should we have a try catch block of this sort to have a graceful shut in case of transient failures?'
- hessjcg: 'Use an error code. Don'\''t check error message strings.'
- hessjcg: 'The correct logic for detecting an immutable instance dns name: IF name matches /\.sql(-\w+)?\.goog$/ AND name does not match /\.global\.sql(-\w+)?\.goog$/'
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