Как запросить сервер gRP C от Go, работающий в Cloud Run - PullRequest
1 голос
/ 11 января 2020

Я сделал сервер gRP C по go lang.
https://github.com/takat0-h0rikosh1/grpc-with-go

Это приложение cafe-cli.

Я зарегистрировал контейнер в GCR и развертывание в Cloud Run.

# docker build
docker 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/cafe
Please 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] cancel
Please enter your numeric choice:  1

To 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-service
Allow unauthenticated invocations to [cafe-service] (y/N)?  N

Deploying 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 and
is serving 100 percent of traffic at https://cafe-service-xxx-uc.a.run.app

Как запросить на этом сервере gRP C?
Я попробовал следующее.

$ 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 list
Failed 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 list
Failed to dial target host "cafe-service-xxx-uc.a.run.app:443": context deadline exceeded

Что я должен сделать

Ответы [ 2 ]

0 голосов
/ 14 января 2020

Неправильный заголовок авторизации в вашей команде curl. Он пропускает $ перед командой gcloud. Используйте это вместо:

curl -H \
  "Authorization: Bearer $(gcloud auth print-identity-token)" \
  https://cafe-service-xxx-uc.a.run.app
0 голосов
/ 11 января 2020

Первое, что нужно попробовать - это создать новую службу и разрешить неаутентифицированные:

"Разрешить неаутентифицированные вызовы для [] (y / N)? Y"

Во-вторых, если вы попытаетесь получить доступ к gRP C с аутентификацией, проверьте:

https://medium.com/google-cloud/grpc-authentication-with-cloud-run-72e4d6c44739

...