Access control with IAM
You (that is, the user or service account deploying the function) can set access control using roles at the project level. Grant a role to a project member or service account to determine the level of access to your Google Cloud project and its resources. By default, all Google Cloud projects come with a single user: the original project creator. No other users have access to the project, and therefore, access to functions, until a user is added as a project team member.
Access control for users
You can add users as team members to your project and grant them roles using Identity and Access Management (IAM).
Cloud Functions supports the basic roles of Editor, Owner, and Viewer, which give the following permissions:
- Editor and Owner: Read and write access to all functions-related resources. Lets users deploy, update, and delete functions. Additional access to other resources in the project.
- Viewer: Read-only access to functions and locations. Lets users list functions and see their details, but does not let them view the source code. Additional access to other resources in the project.
Cloud Functions also supports the Cloud Functions predefined Developer and Viewer roles, which give the following permissions:
- Developer: Read and write access to all functions-related resources. Lets users deploy, update, and delete functions. No access to other resources in the project.
- Viewer: Read-only access to functions and locations. Lets users list functions and see their details, but does not let them view the source code. No access to other resources in the project.
Access control for service accounts
A service account is a special type of Google Cloud account that acts as an identity for a non-human user that needs to authenticate and be authorized to access data and perform various actions. Some of these accounts are created and managed by Google itself and are known as service agents.
The following service accounts are used for Cloud Functions:
|App Engine default service account (1st gen only)||
|Compute Engine default service account (2nd gen only)||
|Google Cloud Functions Service Agent||
||Cloud Functions Service Agent|
||Cloud Build Service Account|
|Cloud Build Service Account||
||Cloud Build Service Agent|
|Google Container Registry Service Agent||
||Container Registry Service Agent|
|Artifact Registry Service Agent||
||Artifact Registry Service Agent|
Runtime service accounts
At runtime, Cloud Functions (1st gen) defaults to using the App Engine
default service account (
PROJECT_ID@appspot.gserviceaccount.com), which has
the Editor role on the project. Cloud Functions (2nd gen) defaults
to using the Compute Engine default service account
PROJECT_NUMBERfirstname.lastname@example.org), which also has
the Editor role on the project. You can change the roles of these service
accounts to limit or extend the permissions for your running functions. You can
also change which service account is used by
providing a non-default individual service account.
To learn more about service accounts, see the service accounts documentation.
Administrative service accounts
To perform administrative actions on your project during the creation,
updating, or deletion of functions, all projects in Cloud Functions
require the Google Cloud Functions Service Agent service account
In addition, all runtimes carry out container image building and storage within your project. To support this, you also need to provision the following:
- The basic Cloud Build service account (
- The Cloud Build Service Agent service account (
- The Google Container Registry Service Agent service account (
These service accounts should have the roles listed in the earlier table.
Google Cloud Functions Service Agent service account
By default, the Google Cloud Functions Service Agent service account
the cloudfunctions.serviceAgent role on your project. Creating, updating,
and deleting functions might fail if you change this account's permissions.
Here's a few of the notable permissions that the
||Manage repositories and store build images in Artifact Registry.|
||Required to use Cloud Build to perform builds in user project.|
||Create builds in Cloud Build custom workers.|
||Invoke an IAM-guarded 1st Gen HTTP function.|
||Provision functions with access to the consumer projects VPC.|
||Manage Eventarc triggers for 2nd Gen functions.|
||Create functions triggered by the Firebase Realtime Database.|
||Ability to get runtime service account credentials.|
||Needed for the agent to get an OpenID token on a user-specified authority. OpenID token is used for invoking IAM-enabled functions.|
||Manage subscriptions in the user's project.|
||Manage topics in the user's project.|
||Manage the Cloud Run Service for 2nd Gen functions.|
||Configure notifications on a Cloud Storage bucket that trigger a 1st Gen function.|
||Required for storing source code in user project.|
You can see the entire set of permissions under the predefined IAM roles or by running this command:
gcloud iam roles describe roles/cloudfunctions.serviceAgent
You can reset this service account to the default role by removing whatever role it currently has and adding the Cloud Functions Service Agent role:
gcloud projects add-iam-policy-binding PROJECT_ID \ --member serviceAccount:service-PROJECT_NUMBER@gcf-admin-robot.iam.gserviceaccount.com \ --role roles/cloudfunctions.serviceAgent
Troubleshooting permission errors
If you get permission errors when you deploy, update, delete, or execute functions in your project, perform the following steps:
Make sure that you have the Editor or Owner role on your project, or that you are using the Cloud Functions Developer role.
If you are using the Cloud Functions Developer role at the project level, also ensure that you have granted the user the IAM Service Account User role.
Currently, only execution permissions are allowed at the per-function level.
Verify that the Cloud Functions Service Agent service account (
service-PROJECT_NUMBER@gcf-admin-robot.iam.gserviceaccount.com) has the cloudfunctions.serviceAgent role for your project.
Make sure the Include Google-provided role grants box on the Permissions tab of the Console IAM page is checked to see this account. Or you can use
gcloud projects add-iam-policy-binding PROJECT_ID.
If you get an ”insufficient permissions” error, or have other authentication problems when you run your functions, make sure that the runtime service account has the correct permissions to access the resources your functions need. Then, repeat steps 2 and 3.
If you get a ”service unavailable” error during deployment, make
sure that the runtime service account
exists in your project. To recreate this service account if it was deleted, see
Undeleting a service account.
See also Troubleshooting Cloud Functions.