-
Overview
- A special account used by services and applications
- Apps use service account credentials for authentication
- Firewall rules can be applied based on service accounts
- A service account is an identity used to run API requests
- Service accounts can create and manage instances and other resources based on assigned roles
- An instance can have only one service account
- Service account must be created in the same project as the instance
- User-managed and Google-managed service accounts can be assigned to instances
-
User-managed
- Includes service accounts explicitly created and the Compute Engine default service account
- Users can create and manage own service accounts using Cloud IAM
- Grant service accounts IAM roles and set up instances to run as the service account
- Apps can use a account's credentials to make requests to Google APIs
- New projects come with the Compute Engine default service account
- Default service account is automatically added to projects
- Limit Google APIs the default service account can access
- Delete default service account might cause some applications fail
- Default service account is automatically created
- Default service account is enabled by default on instances created by the gcloud and Console
- Users can specify a service account when creating an instance
- Access scopes define the default OAuth scopes for client libraries and gcloud requests
- Access scopes limit access to API methods when authenticating through OAuth
- Access scopes does not extend to other authentication protocols like gRPC
- Set full cloud-platform access scope on instance, and securely limit access using IAM roles
- Default service account is not enabled on instances created using API directly
- Default service account can be enabled by explicitly specifying it as part of the request payload
-
Google-managed
- Created and managed by Google and assigned to projects automatically
- Represent Google services and each account has some level of access to Google Cloud project
- The default services account is used to run internal Google processes on the user's behalf
- The default services account is used by Compute Engine to perform its service duties
- It relies on the Service Agent IAM Policy granted on the Google Cloud Project
- By default, the account is automatically granted the project editor role
- This service account is only deleted when the project is deleted
- Users can change the roles granted to this account, including revoking all access to project
- Managed instance groups and autoscaling use the credentials of this account
-
Permissions
- When an instance runs as a service account, the level of access is determined by the IAM roles
- If the service account has no IAM roles, no API methods can be run using the service account
- Access scopes determine the default OAuth scopes for gcloud and client library requests
- Access scopes potentially further limit access to API methods when authenticating through OAuth
- Access scopes do not extend to other authentication protocols like gRPC
- The best practice is to set the full cloud-platform access scope on instance, and limit using IAM roles
- If cloud-platform access scope is enabled, access is limited to predefined IAM roles assigned
- If a more restrictive scope is granted, requests for more generous access via predefined roles are denied
-
Roles
- Grant appropriate IAM roles to service account to enable access to relevant API methods
- IAM roles are account-specific, and any instance running as a service account can use the role
- If there isn't a predefined IAM role for the access level needed, grant a primitive role
- Access scopes must be set on an instance to authorize access
- A service account's access level is determined by the IAM roles granted to the service account
- An instance's access scopes determine the default OAuth scopes for gcloud and client library requests
- Access scopes further limit access to API methods when authenticating through OAuth
- Access scopes are the legacy method of specifying permissions for instance
- Access scopes are not a security mechanism. They define the default OAuth scopes used
- Access scopes have no effect when making requests not authenticated through OAuth
- Must set up access scopes when configuring an instance to run as a service account
- Set full cloud-platform access scope on the instance, and securely limit API access with Cloud IAM roles
- Access scopes apply on a per-instance basis
- Access scopes persists only for the life of the instance
- Access scopes have no effect if related API is not enabled