我通过 go lang 制作了 gRPC 服务器。https://github.com/takat0-h0rikosh1/grpc-with-go这是一个 cafe-cli 应用程序。我将容器注册到 GCR,并部署到 Cloud Run。# docker builddocker build -t cafe .# register image$ docker tag cafe gcr.io/xxx/cafe$ docker push gcr.io/xxx/cafe # deploy to cloud run$ gcloud beta run deploy --project xxx --image gcr.io/xxx/cafePlease choose a target platform: [1] Cloud Run (fully managed) [2] Cloud Run for Anthos deployed on Google Cloud [3] Cloud Run for Anthos deployed on VMware [4] cancelPlease enter your numeric choice: 1To specify the platform yourself, pass `--platform managed`. Or, to make this the default target platform, run `gcloud config set run/platform managed`.Service name (cafe): cafe-serviceAllow unauthenticated invocations to [cafe-service] (y/N)? NDeploying container to Cloud Run service [cafe-service] in project [xxx] region [us-central1]✓ Deploying new service... Done. ✓ Creating Revision... ✓ Routing traffic...Done.Service [cafe-service] revision [cafe-service-00001-pal] has been deployed andis serving 100 percent of traffic at https://cafe-service-xxx-uc.a.run.app如何向这个 gRPC 服务器请求?我尝试了以下。$ curl -H \ "Authorization: Bearer (gcloud auth print-identity-token)" \ https://cafe-service-xxx-uc.a.run.app<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><title>401 Unauthorized</title></head><body text=#000000 bgcolor=#ffffff><h1>Error: Unauthorized</h1><h2>Your client does not have permission to the requested URL <code>/</code>.</h2><h2></h2></body></html>$ grpcurl -plaintext cafe-service-xxx-uc.a.run.app:443 listFailed to dial target host "cafe-service-xxx-uc.a.run.app:443": context deadline exceeded$ grpcurl -authority (gcloud auth print-identity-token) -plaintext cafe-service-xxx-uc.a.run.app:443 listFailed to dial target host "cafe-service-xxx-uc.a.run.app:443": context deadline exceeded我必须做什么?
2 回答

素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
首先要尝试的是创建一个新服务并允许未经身份验证:
“允许未经身份验证的调用 [] (y/N)?y”
其次,如果您尝试使用 auth 访问 gRPC,请检查:
https://medium.com/google-cloud/grpc-authentication-with-cloud-run-72e4d6c44739

慕斯709654
TA贡献1840条经验 获得超5个赞
您的 curl 命令中的 Authorization 标头是错误的。它$在 gcloud 命令之前缺少 a 。改用这个:
curl -H \
"Authorization: Bearer $(gcloud auth print-identity-token)" \
https://cafe-service-xxx-uc.a.run.app
- 2 回答
- 0 关注
- 166 浏览
添加回答
举报
0/150
提交
取消