Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Functions Deploy "allow unauthenticated invocations..."

Whenever I have to deploy a new python function using the gcloud sdk I get this message

Allow unauthenticated invocations of new function [function-name]?

(y/N)?

WARNING: Function created with limited-access IAM policy. To enable unauthorized access consider

"gcloud alpha functions add-iam-policy-binding function-name --region=europe-west1 --member=allUsers --role=roles/cloudfunctions.invoker"

Is there any flag I can add to the command to make it a NO when deploying?

This is a sample command I use to deploy one function:

gcloud functions deploy function-name --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/{user_id}" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project
like image 991
Guanaco Devs Avatar asked May 01 '20 23:05

Guanaco Devs


People also ask

How do you deploy cloud functions?

In the Source code field, select ZIP from Cloud Storage. In the Cloud Storage location field, click Browse to select a ZIP file from Cloud Storage. Your function source files must be located at the root of the ZIP file - see Source directory structure. Click Deploy.

What is principal in GCP?

Principal. A principal can be a Google Account (for end users), a service account (for applications and compute workloads), a Google group, or a Google Workspace account or Cloud Identity domain that can access a resource. Each principal has its own identifier, which is typically an email address. Role.


3 Answers

  1. Select the service
  2. Click Show Info Panel to display the Permissions tab.
  3. In the Add members field, allUsers
  4. Select the Cloud Functions Invoker from roles
  5. Add

or

  gcloud functions add-iam-policy-binding FUNCTION \
  --member='serviceAccount:FUNCTION_IDENTITY' \
  --role='roles/cloudfunctions.invoker'

 gcloud run services add-iam-policy-binding [SERVICE_NAME] \
    --member="allUsers" \
    --role="roles/cloudfunctions.invoker"
like image 145
Tiago Medici Avatar answered Sep 19 '22 15:09

Tiago Medici


I just encountered this problem as well and discovered that you can supply --no-allow-unauthenticated to pre-emptively answer "no" to this question.

gcloud functions deploy MyFunction \
  --runtime=go116 --trigger-http --no-allow-unauthenticated
like image 11
David Avatar answered Oct 13 '22 07:10

David


From https://cloud.google.com/sdk/docs/scripting-gcloud#disabling_prompts:

You can disable prompts from gcloud CLI commands by setting the disable_prompts property in your configuration to True or by using the global --quiet or -q flag.

So for your example, you could run:

gcloud functions deploy function-name --quiet --region=europe-west1 --entry-point function-entry-point --trigger-resource "projects/my-project/databases/(default)/documents/user_ids/{user_id}" --trigger-event providers/cloud.firestore/eventTypes/document.create --runtime python37 --timeout 60 --project my-project
like image 10
Dustin Ingram Avatar answered Oct 13 '22 07:10

Dustin Ingram