我想將我的 grpc 服務部署到 Cloud Run 并通過 Python3 向它發送經過身份驗證的請求。我遵循了有關設定為 Google Cloud Run 服務建立身份驗證的各種檔案,并且收到了 grpc._channel._InactiveRpcError 錯誤:
我的客戶端代碼如下:
#server_info='<service url>:443'
credentials, _ = google.auth.default()
request = google.auth.transport.requests.Request()
channel = google.auth.transport.grpc.secure_authorized_channel(
credentials, request, server_info,
ssl_credentials=grpc.ssl_channel_credentials())
stub = myClient_pb2_grpc.MyGrpcClientPBStub(channel)
我已為此服務分配了自己的“Cloud Run Invoker”角色。我也是與此服務關聯的服務帳戶的所有者。
我運行gcloud auth application-default并執行客戶端代碼會產生錯誤:
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
debug_error_string = "UNKNOWN:Error received from peer ipv4:xxx.xxx.xx.xx:443:
我已嘗試手動下載此專案的關聯服務帳戶的 .json 密鑰并將其分配給 GOOGLE_APPLICATION_CREDENTIALS 環境變數。并執行客戶端代碼會產生錯誤:
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
debug_error_string = "UNKNOWN:Error received from peer <service url>:443
任何正確驗證的指標將不勝感激。
uj5u.com熱心網友回復:
這很令人困惑,而且記錄不充分。
問題是您需要一個 ID 令牌,其中包含audienceCloud Run 服務地址的(宣告)。您從中獲取的憑據google.auth.credentials.Credentials提供訪問令牌。
請參閱此內容grpc_client.py和相關README內容,并注意他參考的博客文章現在是gRPC auth with OpenID Connect tokens。
注意我不清楚為什么StatusCode.UNAUTHENTICATED在使用用戶憑據作為應用程式默認憑據 (ADC) 和StatusCode.UNAUTHORIZED使用 ADC 的服務帳戶時會出現不同的錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/523250.html
標籤:Google Cloud Collective Python验证grpc谷歌云运行grpc-python
下一篇:如何正確地將環境變數發送到影像?
