google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

access_secret_version Getting StatusCode.DEADLINE_EXCEEDED

Open pfitzsi1 opened this issue 3 years ago • 6 comments

Testing a first generation Pub/Sub triggered Google Cloud Function trying to get a Google Secret.

Within the function code the logging shows the following series of the same Python module DEBUG statements multiple times as it progresses through the function code:

(1) DEBUG - _get_explicit_environ_credentials @ line 257 - Checking None for explicit credentials as part of auth process... (2) DEBUG - _get_gcloud_sdk_credentials @ line 230 - Checking Cloud SDK credentials as part of auth process... (3) DEBUG - _get_gcloud_sdk_credentials @ line 236 - Cloud SDK credentials not found on disk; not using them (4) DEBUG - call @ line 104 - Making request: GET http://169.254.169.254/ (5) DEBUG - call @ line 104 - Making request: GET http://metadata.google.internal/computeMetadata/v1/project/project-id

Added in the following statement to see if the default credentials are properly obtained:

credentials, project = google.auth.default()

Displayed the credentials and project variables afterwards and yes they are OK. This statement of course also generated the above 5 DEBUG statements in the log.

But, later in the code when it gets to the access_secret_version statement the log shows the above 5 DEBUG statements again and then a 1 minute gap followed by the StatusCode.DEADLINE_EXCEEDED error.

There does not seem to be a way to set a timeout for access_secret_version but it appears to have a 1 minute timeout. The total time on the function execution to the error is 60109 ms. The function is deployed with --timeout=540s.

Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable return callable_(*args, **kwargs) File "/layers/google.python.pip/pip/lib/python3.10/site-packages/grpc/_channel.py", line 1030, in call return _end_unary_response_blocking(state, call, False, None) File "/layers/google.python.pip/pip/lib/python3.10/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.DEADLINE_EXCEEDED

pfitzsi1 avatar Jul 04 '23 17:07 pfitzsi1

I decided to add more logging and examine the returned DEFAULT CREDENTIALS. valid = credentials.valid is returning False Apparently this does not seem to matter until it gets to the access_secret_version but not sure if that is what is causing the 1 minute delay and then the error, the TRACEBACK log messages doesn't mention anything about credentials and I would expect some permission error if that is the problem.

I have made sure that the SA attached to the Function plus the Functions runtime SA plus the App Engine runtime SA all have all the roles needed.

If the invalid default credentials is the problem I'm having difficulty trying to figure out how to update them. I think from the documentation that the flow for obtaining them says that in this case with a first gen function that it is getting them from the App Engine (or supposed to) but the 5th DEBUG statement looks like it is then trying to get them from metadata. The App Engine attempt must be the call to http://169.254.169.254/. I wonder why it is apparently not getting them there...

pfitzsi1 avatar Jul 05 '23 16:07 pfitzsi1

Since there is a service account (SA) attached to the Function, not sure why it goes through that flow trying to obtain default credentials over and over again (show up multiple times in the log), when it should be using the attached SA as the credentials. I only added in the credentials, project = google.auth.default() statement so that I could examine and log things for debugging. That statement of course issued the 5 DEBUG statements in the log yet again.

Don't know if there is a way to stop it from doing that if it is unnecessary...

pfitzsi1 avatar Jul 05 '23 17:07 pfitzsi1

May be on the wrong track here looking at the default credentials. The TRACEBACK log messages only refer to RPC issues...

Had a look at https://gcloud.readthedocs.io/en/latest/_modules/grpc/_channel.html but not sure what the problem is.

pfitzsi1 avatar Jul 05 '23 17:07 pfitzsi1

UPDATE: (1) Default Credentials had nothing to do with this. Was able to pass in the Service Account (SA) that is attached to the Function as an argument to SecretManagerServiceClient prior to the call to access_secret_version and the log no longer shows any of those DEBUG statements going through that flow trying to obtain default credentials. (2) Was able to add a timeout parameter to the call to access_secret_version and instead of the DEADLINE EXCEEDED error, now getting the following error: failed to connect to all addresses; last error: UNKNOWN: ipv4:199.36.153.8:443: Failed to connect to remote host: FD Shutdown

pfitzsi1 avatar Jul 05 '23 23:07 pfitzsi1

This issue can be closed.

pfitzsi1 avatar Jul 06 '23 18:07 pfitzsi1

Closed.

pfitzsi1 avatar Jul 06 '23 18:07 pfitzsi1