Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Authentication Issue - Cloud Run Functions

I'm a beginner in this topic, and I want to test my Cloud Function from the command line (with curl), but it keeps returning "401 Unauthorized"

I have assigned different roles to both my own account and the service account:

My account: Owner, Cloud Functions Admin, Service Account User (I’m not sure if the last one is necessary)

Service account: Service Account Token Creator (I think more roles are needed)

(By the way, for another function I selected "Allow unauthenticated invocations" and the same Service Account, but I still get the "401 Unauthorized" message when testing.)

Could someone help me get the authentication working? I've been trying for hours, but I keep getting the "401 Unauthorized" message.

0 1 355
1 REPLY 1

Hi @NSzabolcs

Welcome to Google Cloud Community!

The error 401 message occurs when the user is not authenticated properly. This might be due to a  misconfigurations in IAM permissions, authentication token generation, or the understanding of unauthenticated function access.You may need to make sure the service account you're using has the correct permissions to actually invoke the Cloud Function, and that we're presenting the right credentials. You can follow these steps to help you resolve the problem:

  • Ensure the service account used for generating the identity token has the roles/run.invoker role specifically granted on the target Cloud Function. You may refer to this documentation on how to grant the permission.
  • Correctly Generate and Utilize Identity Tokens
  • For the function allowing unauthenticated access, double-check the function URL, deployment status, and any potential network restrictions (VPC Service Controls, firewall rules) that might still be blocking access.

If the steps did not work, you may contact Google Cloud Support. They can investigate your specific project and account for any underlying issues. When contacting them, please provide detailed information.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

Top Solution Authors