Skip to content

feat(js-client): Add Google Cloud authentication support#7

Merged
steren merged 1 commit intoGoogleCloudPlatform:mainfrom
wietsevenema:pr-js-auth
Jan 12, 2026
Merged

feat(js-client): Add Google Cloud authentication support#7
steren merged 1 commit intoGoogleCloudPlatform:mainfrom
wietsevenema:pr-js-auth

Conversation

@wietsevenema
Copy link
Collaborator

@wietsevenema wietsevenema commented Jan 8, 2026

This PR introduces built-in authentication support for the JavaScript client, enabling secure connections to Cloud Run services protected by IAM.

Key Changes

1. Public API Update

  • Added useGoogleAuth (boolean) parameter to Sandbox.create and Sandbox.attach to enable automatic OIDC authentication.

2. Authentication Logic

  • Automatic OIDC: Integrated google-auth-library to fetch OIDC ID tokens automatically when useGoogleAuth is enabled.
  • Fail-Fast & Refresh: Implemented an internal tokenProvider mechanism that fetches a fresh ID token before every connection attempt.

3. Enhanced Error Reporting

  • Actionable Hints: Errors occurring during creation, restoration, or reconnection now include unified hints for 401/403 status codes, explicitly guiding users to enable useGoogleAuth or check permissions.
  • Troubleshooting: Failures include a link to official Cloud Run troubleshooting documentation.

4. Testing & Examples

  • Unit Tests: Added tests in sandbox.test.ts and connection.test.ts covering auth flows and error hints.
  • Examples: Updated all JavaScript examples to use secure authentication (useGoogleAuth: true) by default.

@wietsevenema wietsevenema force-pushed the pr-js-auth branch 20 times, most recently from 982e29a to 8838a30 Compare January 11, 2026 20:12
@wietsevenema wietsevenema marked this pull request as ready for review January 11, 2026 20:15
@wietsevenema wietsevenema requested a review from steren January 11, 2026 20:17
This PR introduces built-in authentication support for the JavaScript client, enabling secure connections to Cloud Run services protected by IAM.

### Key Changes

**1. Public API Update**

- Added 'useGoogleAuth' (boolean) parameter to 'Sandbox.create' and 'Sandbox.attach' to enable automatic OIDC authentication.

**2. Authentication Logic**

- **Automatic OIDC:** Integrated 'google-auth-library' to fetch OIDC ID tokens automatically when 'useGoogleAuth' is enabled.

- **Fail-Fast & Refresh:** Implemented an internal 'tokenProvider' mechanism that fetches a fresh ID token before every connection attempt.

- **Audience Derivation:** Automatically derives the correct OIDC audience from the connection URL, forcing the https:// scheme to match Cloud Run requirements.

**3. Enhanced Error Reporting**

- **Actionable Hints:** Errors occurring during creation, restoration, or reconnection now include unified hints for 401/403 status codes, explicitly guiding users to enable 'useGoogleAuth' or check permissions.

- **Troubleshooting:** Failures include a link to official Cloud Run troubleshooting documentation.

**4. Testing & Examples**

- **Unit Tests:** Added comprehensive tests in 'sandbox.test.ts' and 'connection.test.ts' covering auth flows, audience derivation, token freshness, session affinity, and error hints.

- **Examples:** Updated all JavaScript examples to use secure authentication ('useGoogleAuth: true') by default.
@steren steren merged commit 61a4450 into GoogleCloudPlatform:main Jan 12, 2026
3 checks passed
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