Study guide
15.2 Assigning Service Accounts to Resources & Managing SA IAM Policies
Google Cloud Associate Cloud Engineer ACE
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Introduction & Exam Overview
1.1 About the GCP Associate Cloud Engineer Exam 1.2 How to Use This Study Guide & Build a Study Plan
2 Chapter 2: Resource Hierarchy, IAM Basics & Cloud Identity
2.1 The GCP Resource Hierarchy: Organizations, Folders & Projects 2.2 Organization Policies & Granting IAM Roles 2.3 Cloud Identity: Managing Users and Groups
3 Chapter 3: APIs, Quotas & Billing Configuration
3.1 Enabling APIs and Provisioning Cloud Operations Suite 3.2 Assessing and Requesting Quota Increases 3.3 Billing Accounts, Project Linking & Billing Exports 3.4 Billing Budgets and Alerts
4 Chapter 4: Planning Compute & Storage Resources
4.1 Choosing the Right Compute Option: GCE vs. GKE vs. Cloud Run vs. Cloud Functions 4.2 Spot VMs, Custom Machine Types & Cost-Optimized Compute Planning 4.3 Choosing a Data Storage Product: Cloud SQL, BigQuery, Firestore, Spanner & Bigtable 4.4 Cloud Storage Classes & Persistent Disk Types
5 Chapter 5: Planning Network Resources
5.1 Load Balancing Options and Use Cases 5.2 Regional Resource Placement & High Availability Planning 5.3 Network Service Tiers: Premium vs. Standard
6 Chapter 6: Deploying Compute Engine Workloads
6.1 Launching Compute Engine Instances: Disks, SSH Keys & Availability Policies 6.2 Managed Instance Groups, Instance Templates & Autoscaling 6.3 OS Login and VM Manager for Fleet Configuration
7 Chapter 7: Deploying Google Kubernetes Engine Workloads
7.1 Installing and Configuring kubectl 7.2 Deploying GKE Clusters: Autopilot, Regional, Private & GKE Enterprise 7.3 Deploying Containerized Applications to GKE
8 Chapter 8: Deploying Serverless & Event-Driven Applications
8.1 Deploying Applications to Cloud Run and Cloud Functions 8.2 Event-Driven Architectures: Pub/Sub, Cloud Storage Triggers & Eventarc
9 Chapter 9: Deploying Data Solutions
9.1 Deploying Data Products: Cloud SQL, Firestore, Spanner, BigQuery & AlloyDB 9.2 Deploying Pub/Sub, Dataflow & Loading Data into Google Cloud
10 Chapter 10: Deploying Networking Resources & Infrastructure as Code
10.1 Creating VPCs, Subnets & Shared VPC 10.2 Firewall Rules, Cloud VPN & VPC Network Peering 10.3 Infrastructure as Code: Terraform, Config Connector, Cloud Foundation Toolkit & Helm
11 Chapter 11: Managing Compute Engine & GKE in Production
11.1 Connecting to and Managing Running Compute Engine Instances 11.2 Working with Snapshots and Custom Images 11.3 Managing GKE Clusters: Node Pools, Workloads & Artifact Registry Access 11.4 Horizontal and Vertical Pod Autoscaling in GKE
12 Chapter 12: Managing Cloud Run, Storage & Database Operations
12.1 Managing Cloud Run Revisions, Traffic Splitting & Scaling 12.2 Managing and Securing Cloud Storage Objects & Lifecycle Policies 12.3 Querying, Estimating Costs, Backup & Job Monitoring for Databases (Cloud SQL, BigQuery, Spanner, Dataflow)
13 Chapter 13: Networking Operations, Monitoring & Logging
13.1 Networking Operations: Subnets, Static IPs, Cloud DNS & Cloud NAT 13.2 Cloud Monitoring: Alerts, Custom Metrics & Dashboards 13.3 Cloud Logging: Buckets, Log Analytics, Routers & Filtering 13.4 Diagnostics, Ops Agent, Managed Service for Prometheus & Audit Logs
14 Chapter 14: IAM Policies & Role Types
14.1 IAM Policies: Structure, Bindings & Policy Hierarchy 14.2 IAM Role Types: Basic, Predefined & Custom Roles
15 Chapter 15: Service Accounts & Security Configuration
15.1 Creating Service Accounts & Assigning Least-Privilege Permissions 15.2 Assigning Service Accounts to Resources & Managing SA IAM Policies 15.3 Service Account Impersonation & Short-Lived Credentials
16 Chapter 16: Exam Readiness — Scenarios & Test-Day Strategy
16.1 Common ACE Exam Scenarios & Decision Frameworks 16.2 Test-Day Logistics, Time Management & Final Review Checklist
15.2 Assigning Service Accounts to Resources & Managing SA IAM Policies
Key Takeaways Explain This Topic AI
Attaching a service account to a resource requires iam.serviceAccounts.actAs, granted through roles/iam.serviceAccountUser on that specific account.
Google enforces a two-key model -- resource-creation permission plus serviceAccountUser on the SA -- specifically to block privilege escalation.
Never grant serviceAccountUser at the project or folder level; bind it on the individual service account resource instead.
Compute Engine is the only major resource type that lets you swap its attached service account after creation, while stopped.
Anyone with shell access to a VM can query the metadata server for its attached service account's token, so restrict access with OS Login or IAP.
Last updated: July 2026
Why This Matters
The official exam guide lists two related bullets under domain 5: "Assigning service accounts to resources" and "Managing IAM of a service account." Where section 15.1 covered a service account as a principal (what it can do to other resources), this section covers the other half of the dual identity: a service account as a resource -- who is allowed to use it, attach it to a workload, or administer it. This distinction is the crux of Google Cloud's privilege-escalation defenses, and ACE loves to test it with "why did this action get denied?" scenarios.
Attaching a Service Account to a Resource
When you launch a Compute Engine VM, deploy a Cloud Function, or deploy a Cloud Run revision, you choose which service account the running workload will use to call other Google Cloud APIs. That is "attaching" a service account to a resource. gcloud functions deploy export-daily-report \
- -runtime=python312 \
- -trigger-http \
- -service-account=billing-exporter@acme-prod.iam.gserviceaccount.com
To attach any service account to any resource, the person performing the deployment needs the iam.serviceAccounts.actAs permission on that specific service account. That permission is bundled inside the Service Account User role ( roles/iam.serviceAccountUser ).
Why This Rule Exists: Privilege Escalation Prevention
Imagine a developer holds Compute Instance Admin ( roles/compute.instanceAdmin.v1 ), which lets them create VMs -- but nothing else. Without serviceAccountUser on a specific, highly-privileged service account, that developer cannot launch a VM using that account. If they could, they would effectively inherit all of that service account's permissions (for example, Project Owner) simply by attaching it to a VM they control -- a privilege-escalation path. Google Cloud closes this gap by requiring both:
Permission to create or manage the resource (for example, roles/compute.instanceAdmin.v1 ), and
iam.serviceAccounts.actAs on the specific service account being attached.
This is a two-key system, and ACE scenario questions often describe exactly this failure mode: "a user can create VMs but gets a permission-denied error when attaching Service Account X -- what role is missing?" The answer is almost always roles/iam.serviceAccountUser , scoped to that service account -- not a project-wide grant.
Granting the Role at the Right Scope
Google's best practice is explicit: do not grant serviceAccountUser at the project or folder level, because that would let a principal act as every service account in scope -- re-creating the same escalation risk you are trying to prevent. Instead, bind the role directly on the individual service account resource: gcloud iam service-accounts add-iam-policy-binding \
- billing-exporter@acme-prod.iam.gserviceaccount.com \
- -member="user:dana@acme.com" \
- -role="roles/iam.serviceAccountUser"
This creates an IAM policy on the service account itself (its resource-level policy), separate from the project's IAM policy. Both policies exist simultaneously and serve different purposes:
- Policy Location Controls
- Project IAM policy What the service account (as a principal) can do to other resources in the project
Service account's own IAM policy Who (as a principal) can act as, admin, or view this service account (the SA as a resource)
Changing the Attached Service Account Later
For almost every resource type, the service account is fixed at creation time -- to change it, you redeploy (a new Cloud Run revision, a new Cloud Function version). Compute Engine is the documented exception : you can change which service account is attached to an existing VM, but only while the instance is stopped: gcloud compute instances stop web-01 --zone=us-central1-a
- gcloud compute instances set-service-account web-01 \
- -zone=us-central1-a \
- -service-account=new-sa@acme-prod.iam.gserviceaccount.com \
- -scopes=cloud-platform
gcloud compute instances start web-01 --zone=us-central1-a
Expect the exam to test this exception directly: "Which of these resources allows the attached service account to be changed after creation?" The answer is Compute Engine instances.
Other Core Roles for Managing the SA as a Resource
- Role What It Allows
- roles/iam.serviceAccountAdmin View, edit, disable, delete the service account itself
- roles/iam.serviceAccountUser Attach or impersonate the service account ( actAs )
- roles/iam.serviceAccountKeyAdmin Create and delete keys for the service account
- roles/iam.serviceAccountViewer Read-only visibility into the service account's metadata
- Metadata Server Risk
Once a service account is attached to a Compute Engine VM, any code that runs on that VM -- including a user with SSH access -- can reach the instance's metadata server ( http://metadata.google.internal ) and retrieve a live access token for that service account. This is why Google recommends restricting shell access with OS Login or Identity-Aware Proxy (IAP) , and, where possible, blocking arbitrary processes from querying the metadata server.
Exam Scenario
A security review finds that a contractor with Compute Instance Admin was able to create a VM attached to the finance team's highly-privileged finance-etl service account, and used it to read data far outside their normal access. What single control, if correctly scoped, would have prevented this?
roles/iam.serviceAccountUser should never have been granted to the contractor on the finance-etl service account -- either it should not have been granted at all, or it should have been granted only on a narrowly-scoped, low-privilege service account instead.
Takeaways
Attaching a service account to a resource requires iam.serviceAccounts.actAs , granted through roles/iam.serviceAccountUser on that specific account.
Google enforces a two-key model -- resource-creation permission plus serviceAccountUser on the SA -- specifically to block privilege escalation.
Never grant serviceAccountUser at the project or folder level; bind it on the individual service account resource instead.
Compute Engine is the only major resource type that lets you swap its attached service account after creation, while the instance is stopped.
Anyone with shell access to a VM can query the metadata server for its attached service account's token, so restrict access with OS Login or IAP.