# Least privilege for Cloud Functions means Cloud Functions Admin for few, Invoker per function and no allUsers

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Cloud Functions separates administering functions from invoking them. Google's documentation, read 16 Nov 2026, says HTTP functions require authentication by default, that the Owner and Cloud Functions Admin roles hold setIamPolicy, and that the Domain Restricted Sharing policy blocks unauthenticated invocation.

## Cloud Functions uses IAM for administration and a separate invoker role for calling

Google's documentation says IAM authorizes administrative actions on functions created with the Cloud Functions v2 API, such as creating, updating and deleting. Roles can be granted on the function or the project.

By default, entities that need to invoke an HTTP function must present authentication credentials and have the required permissions. Event-driven functions can only be invoked by the event source they subscribe to.

To invoke an HTTP function, the documented role is roles/run.invoker, granted on the specific function.

The identities that call this service (people, services, workloads, third parties) are covered in the [Google Cloud service identities guide](/guides/google-cloud-service-identities/) and the [workload identities guide](/guides/google-cloud-workload-identities/).

## Roles and flags to avoid, with the documented reason

Three choices change who can reach a function.

- Owner and Cloud Functions Admin: Google says cloudfunctions.functions.setIamPolicy, needed to control access to a function, is in both roles. Anyone with it can change who invokes the function.
- allUsers as invoker: Google shows it as the way to allow unauthenticated invocation, and says roles cannot be granted to allUsers and allAuthenticatedUsers at the project level.
- The --allow-unauthenticated flag at deploy: Google says using it modifies IAM permissions, and that later deployments of the same function do not change its status.
- Basic roles on the project: highly permissive, per Google's IAM overview.

## A minimal binding for a caller of one HTTP function

Google's page shows the invoker grant as a command of the form gcloud run services add-iam-policy-binding FUNCTION_NAME --member=<caller> --role=roles/run.invoker, where the member is a specific principal rather than allUsers.

| Task | Role | Resource | Note from Google's documentation |
| --- | --- | --- | --- |
| Call one HTTP function | roles/run.invoker | The function | Callers must also present credentials |
| Change who can call or manage a function | roles/cloudfunctions.admin | The function or project | Contains cloudfunctions.functions.setIamPolicy |
| Public endpoint (deliberate) | roles/run.invoker to allUsers | The function | Blocked where Domain Restricted Sharing applies |

## Organization policy and per-function grants narrow access

Google's documentation says that in a project subject to the Domain Restricted Sharing organization policy, unauthenticated invocation of a function cannot be allowed. That makes the organization policy a guardrail on top of the function's IAM policy.

Grant roles on the single function instead of the project. A project-level role covers every function, including ones added later.

## Checking what is used

The IAM recommender in Google's documentation compares granted permissions with those used in the last 90 days and suggests removing or replacing roles with excess permissions. Run it for the project and read the service accounts that functions run as.

Then read each function's IAM policy and check for allUsers or allAuthenticatedUsers invoker entries that no longer serve a public endpoint.

Treat the three rights as three reviews. Administration is reviewed by listing who holds setIamPolicy on the function or project. Invocation is reviewed by listing the invoker entries on each function and removing callers that no longer call. Deployment is reviewed by listing who can act as the function's runtime service account, since deploying a function that runs as a powerful account lets the deployer use that account.

## Related pages

- [Least privilege for Cloud KMS](/services/gcp-cloud-kms/)
- [Least privilege for Pub/Sub](/services/gcp-pubsub/)
- [Least privilege for Amazon S3](/services/aws-s3/)
- [All of them](/services/)

## Sources

- Cloud Functions access with IAM: https://cloud.google.com/functions/docs/securing/managing-access-iam (read 16 Nov 2026)
- IAM roles overview: https://cloud.google.com/iam/docs/roles-overview (read 16 Nov 2026)
- Role recommendations overview: https://cloud.google.com/iam/docs/recommender-overview (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://leastprivilegeprinciple.com/services/gcp-cloud-functions/
