This page explains service accounts, types of service accounts, and the IAM roles that are available to service accounts.
Before you begin
- Understand the basic concepts of Cloud IAM.
What are Service accounts?
A service account is a special Google account that belongs to your application or a virtual machine (VM), instead of to an individual end user. Your application uses the service account to call the Google API of a service, so that the users aren't directly involved.
For example, a Google Compute Engine VM may run as a service account, and that account can be given permissions to access the resources it needs. This way the service account is the identity of the service, and the service account's permissions control which resources the service can access.
A service account is identified by its email address, which is unique to the account.
Service account keys
Each service account is associated with a key pair, which is managed by Google Cloud Platform (GCP). It is used for service-to-service authentication within GCP. Google rotates the keys daily.
You may optionally create one or more external key pairs for use from outside
GCP (for example, for use
Application Default Credentials). When
you create a new key pair, you download the private key (which is not retained
by Google). With external keys, you are responsible for security of the private
key and other management operations such as key rotation. External keys can be
managed by the IAM API,
gcloud command-line tool, or the Service Accounts page
in the Google Cloud Platform Console. You can create up to 10 service account keys per
service account to facilitate key rotation.
Types of service accounts
User-managed service accounts
When you create a new Cloud project using Cloud Platform Console and if Compute Engine API is enabled for your project, a Compute Engine Service account is created for you by default. It is identifiable using the email:
If your project contains an App Engine application, the default App Engine service account is created in your project by default. It is identifiable using the email:
You can create up to 100 service accounts per project (including the default
Compute Engine service account and the App Engine service account) using the IAM
API, the Cloud Platform console, or the
gcloud tool. These default service
accounts and the service accounts you explicitly create are the user-managed
Google-managed service accounts
In addition to the user-managed service accounts, you might see some additional service accounts in your project’s IAM policy or in Cloud Platform Console. These service accounts are created and owned by Google. These accounts represent different Google services and each account is automatically granted IAM roles to access your Google Cloud Platform project.
Google APIs service account
An example of a Google-managed service account is a Google API service account identifiable using the email:
This service account is designed specifically to run internal Google processes on your behalf and is not listed in the Service Accounts section of Cloud Platform Console. By default, the account is automatically granted the project editor role on the project and is listed in the IAM section of Cloud Platform Console. This service account is deleted only when the project is deleted. Google services rely on the account having access to your project, so you should not remove or change the service account’s role on your project.
Service account permissions
For instance, Alice can have the editor role on a service account and Bob can have viewer role on a service account. This is just like granting roles for any other Cloud Platform resource.
The default Compute Engine and App Engine service accounts are granted editor roles on the project when they are created so that the code executing in your App or VM instance have the necessary permissions. In this case the service accounts are identities that are granted the editor role for a resource (project).
If you want to allow your automation to access a Cloud Storage bucket, you grant the service account (that your automation uses) the permissions to read the Cloud Storage bucket. In this case the service account is the identity that you are granting permissions for another resource (Cloud Storage bucket).
The Service Account Actor role
iam.serviceAccountActor roles gives permissions to obtain credentials for
a service account and run operations as the service account. You can grant the
iam.serviceAccountActor role at the project level (for all service accounts in
the project) or at the service account level.
iam.serviceAccountActorrole to a user for a project gives the user access to all service accounts in the project, including service accounts that maybe created in the future.
iam.serviceAccountActorrole to a user for a specific service account gives a user access to the service account.
When granted together with the
compute.instanceAdmin role, the
iam.serviceAccountActor role gives users the ability to create and manage
Compute Engine instances that use a service account.
After you grant the IAM roles to the service accounts you can assign the service account to one or more new virtual machine instances. For instructions on how to do this, see Setting up a new instance to run as a service account.
After setting up an instance to run as a service account, you can use the service account credentials to authenticate applications running on the instance. For instructions see Authenticating applications using service account credentials.
Users who are serviceAccountActors for a service account can access all the
resources for which the service account has access. Therefore be cautious when
iam.serviceAccountActor role to a user.
Service accounts represent your service-level security. People who have IAM policies to manage and use the service accounts and people who hold private external keys for those service accounts determine the security of the service. As such, it is best-practice to use the IAM API to audit the service accounts, the keys, and the policies on those service accounts. If your service accounts do not need external keys, delete them. If users do not need permission to manage or use service accounts, then remove them from the IAM Policy.
Access scopes are the legacy method of specifying permissions for your VM. Before the existence of IAM roles, access scopes were the only mechanism for granting permissions to service accounts. Although they are not the primary way of granting permissions now, you must still set access scopes when configuring up an instance to run as a service account. For information on access scopes see Google Compute Engine documentation
Application Default Credentials
Application default credentials is a mechanism to make it easy to use service accounts when operating inside and outside Google Cloud Platform, as well as across multiple Cloud Platform projects. The most common use case is testing code on a local machine, and then moving to a development project in Google Cloud Platform, and then moving to a production project in Cloud Platform. Using Application Default Credentials ensures that the service account works seamlessly, that is, uses a locally-stored service account key when testing on your local machine but uses the project's default Compute Engine service account when running on Google Compute Engine. For more information, see Application Default Credentials.
For best practices on using service accounts, see Understanding Service Accounts.
Read the following guides to understand how to: