Learning Objectives
By the end of this chapter, you will be able to:
- View, edit, and create IAM policies at the Organization, Folder, Project, and resource level using both the Google Cloud Console and
gcloudcommands. - Distinguish basic, predefined, and custom roles, choose between them by blast radius and operational cost, and author custom roles bound to a specific permission set.
- Create user-managed service accounts and identify the default and Google-managed service accounts that Google Cloud provisions automatically.
- Bind service accounts as principals with the minimum predefined or custom roles that match the workload's API surface.
- Attach service accounts to Compute Engine instances, Google Kubernetes Engine node pools, Cloud Run services, Cloud Run jobs, Cloud Run functions, Cloud Build pipelines, and Eventarc triggers.
- Manage the IAM policy attached to a service account itself, including
roles/iam.serviceAccountUser,roles/iam.serviceAccountTokenCreator, androles/iam.workloadIdentityUser. - Configure single-step and chained service account impersonation for human operators and for automated callers.
- Issue short-lived access tokens, ID tokens, JWTs, and signed blobs through the IAM Credentials API, and federate external identities into Google Cloud with Workload Identity Federation.
Executive Summary
- An IAM policy is a list of role bindings attached to a resource node; the effective policy for any operation is the union of every binding inherited from the Organization down to the leaf resource, filtered by any Deny policy that matches the principal.
- Predefined roles are the default choice; basic roles cover too much surface, and custom roles cost ongoing maintenance because new permissions added to the platform are not auto-included.
- A service account is BOTH a principal (it can be granted roles) AND a resource (it has its own IAM policy that controls who can act as it). The two policy surfaces are managed separately and routinely confused.
- Service account impersonation and Workload Identity Federation replace JSON key files for nearly every supported use case; the
iam.disableServiceAccountKeyCreationorganization policy enforces this decision. - Short-lived credentials issued through the IAM Credentials API have a default one-hour access token lifetime and can be extended to twelve hours with an organization policy; ID tokens follow the same lifetime envelope.
Assumptions
- The landing zone, billing, observability, and workload placement from earlier chapters are in place. The reader has a Project linked to a Cloud Billing account, an Organization node, and at least one Compute Engine instance, one GKE cluster, and one Cloud Run service to attach identities to.
- All
gcloudexamples assume a configuration with a default Project and region already set viagcloud config set projectandgcloud config set compute/region. Where a command targets a different scope, the scope flag is shown explicitly. - Terms defined in earlier chapters (principal, role, permission, binding, predefined role, custom role, IAM Deny policy, conditional binding, default service account, service agent, Workload Identity Federation, Identity-Aware Proxy) are reused without redefinition.
