Skip to content

feat: port GDCH credentials support to Node.js Auth SDK#8301

Open
macastelaz wants to merge 5 commits into
mainfrom
gdch-credentials
Open

feat: port GDCH credentials support to Node.js Auth SDK#8301
macastelaz wants to merge 5 commits into
mainfrom
gdch-credentials

Conversation

@macastelaz
Copy link
Copy Markdown

@macastelaz macastelaz commented May 18, 2026

Add support for GDCH Credentials to the Node.js Auth SDK

Manually tested - details in go/node-js-gdch-manual-test

Fixes #8289

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 the GdchClient to support Google Distributed Cloud Hosted (GDCH) credentials, including token exchange logic using JWT assertions and integration into the GoogleAuth class. Feedback focuses on optimizing performance by using asynchronous file operations for CA certificates and replacing new Date().getTime() with Date.now() for consistency.

Comment on lines +183 to +184
const ca = fs.readFileSync(this.caCertPath);
requestOpts.agent = new https.Agent({ ca });
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.

medium

Using fs.readFileSync in an async method blocks the event loop. It is recommended to use the asynchronous fs.promises.readFile instead. Additionally, consider caching the https.Agent or the CA certificate buffer to avoid re-reading the file and re-creating the agent on every token refresh.

Suggested change
const ca = fs.readFileSync(this.caCertPath);
requestOpts.agent = new https.Agent({ ca });
const ca = await fs.promises.readFile(this.caCertPath);
requestOpts.agent = new https.Agent({ ca });

Comment thread core/packages/google-auth-library-nodejs/src/auth/gdchclient.ts Outdated
…opics. 1) Async CA file reading 2) Token response validation 3) Option synchronization and 4) Expanded unit test coverage.
…manual testing in a GDCH environment. These fixes include: 1) Correcting the type of the credential being parsed from 'gdch_credentials' to 'gdch_service_account' which is the type generated in the SA file. 2)Changing the audience property in token exchange to get the STS-Bearer instead of just Bearer token. 3) Override the requestAsync method to ensure client operations automatically read and trust custom CA certificate files specificied in the credentials json 'ca_cert_path'. 4) Fixed unit test oversight of incorrect call to nockScope.restore().
@macastelaz macastelaz marked this pull request as ready for review May 22, 2026 04:31
@macastelaz macastelaz requested a review from a team as a code owner May 22, 2026 04:31
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

auth: Add support for Google Distributed Cloud service identity authentication

2 participants