googleapis / googleapis/google-cloud-node

Use of `GoogleAuth.getClient()` via `gax-nodejs` via `@googlemaps/addressvalidation` in AWS Lambda causes slow GCE metadata fetch attempt

Open
#7,689 5 comments 0 reactions 0 assignees View on GitHub
library: google-cloud-node-core type: feature request
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

### Please make sure you have searched for information in the following guides.

- [x] Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
- [x] Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
- [x] Check our Troubleshooting guide: https://github.com/googleapis/google-cloud-node/blob/main/docs/troubleshooting.md
- [x] Check our FAQ: https://github.com/googleapis/google-cloud-node/blob/main/docs/faq.md
- [x] Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
- [x] Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
- [x] Check out handwritten samples for many of our APIs: https://github.com/GoogleCloudPlatform/nodejs-docs-samples

### A screenshot that you have tested with "Try this API".

API does not seem to be available in the explorer

### Link to the code that reproduces this issue. A link to a **public** Github Repository or gist with a minimal reproduction.

https://gist.github.com/jstephenson/d8a44a2d28b73923796952aa8a02d081

### A step-by-step description of how to reproduce the issue, based on the linked reproduction.

1. Execute the above sample in an AWS Lambda function
- This should be reproducible in any environment which does not provide project ID in one of the pre-metadata fashions encoded here: https://github.com/googleapis/google-auth-library-nodejs/blob/a511e562783402468093d70e77e73762fa95ae79/src/auth/googleauth.ts#L299-L303

### A clear and concise description of what the bug is, and what you expected to happen.

I have attempted a trivial usage of the Google Maps Platform's _Address Validation API_ from an AWS Lambda function today. This service uses an API key for authentication.

It takes ~15 seconds for execution to resume at the API call site. Upon inspection—primarily via `NODE_DEBUG=http`—I can see three failed attempts to connect to a GCP metadata endpoint at `169.254.169.254` which each have a five second timeout.
[
As documented](https://cloud.google.com/docs/authentication/client-libraries#use_api_keys_with_client_libraries) I am using the `apiKey` auth strategy for the Address Validation API. Looking at the code, it seems that `GoogleAuth`'s `getClient()` method kicks off a call stack which ends up making a call into the `gcp-metadata` package's `project()` function in my use-case. This then in turn attempts to reach a link-local metadata server, and this then becomes slow.

To validate that this is indeed the issue I have set the environment variable `GOOGLE_CLOUD_PROJECT` on my AWS Lambda function and verified that no attempts are then made to reach a metadata service.

I can't find any documentation which suggests I am doing anything wrong, so I'm raising this here in the belief that this represents a bug. Sorry if I'm wrong.

### A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

[The Address Validation API uses API key authentication](https://developers.google.com/maps/documentation/address-validation/get-api-key) and this appears to be [supported by the SDK](https://cloud.google.com/docs/authentication/client-libraries#use_api_keys_with_client_libraries)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.