2
votes

I built a sample container(sample of Go, https://cloud.google.com/run/docs/quickstarts/build-and-deploy) and deployed to cloud run (I unchecked "allow unauthenticated invocations").

However, when I open the endpoint URL of my service, I get a 401 page,

<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>
curl -H "Authorization: Bearer $(gcloud config config-helper --format 'value(credential.id_token)')" [SERVICE_URL]
  • My user account has "roles/run.invoker"
  • When I checked "allow unauthenticated invocations", I got an expected result.

Is there anything to open the endpoint?

1
Which account are you using gcloud auth list? The account with the asterisk must be authorized in Cloud Run. You can also run gcloud config config-helper and double check the core/account property.John Hanley
Also, for Cloud Run I think 401 means an error with authorization (bad / wrong credentials). 403 means not authorized (no credentials). I don't have a reference, just my own experience testing Cloud Run.John Hanley
Can you run it with curl -v to see the headers? One of the headers is supposed to tell you what went wrong.Ahmet Alp Balkan
> John Hanley Using account has "roles/run.invoker". I confirmed it by gcloud auth list and gcloud config config-helpershino
@wlhee Thank you for your advice !! I used Google Cloud Shell and its gcloud version is 242.0.0. I got an expected result when using my local machine.shino

1 Answers

0
votes
  1. Please make sure gcloud version is at least 243.0.0 by "gcloud --version"

  2. Please use "gcloud components update" to update if gcloud is too old

  3. [Updated] Using gcloud in Cloud Shell to call authentication-required Cloud Run service is also working now.

Thanks!