Prepare and test your skills
Prepare and test your skills
Resource Hierarchy and Policy Inheritance is how Google Cloud organizes resources into a lineage and controls access down that lineage. The lineage flows from the Organization resource (opens in a new tab) at the top, through folders, to projects, and finally to service resources. An IAM allow policy (opens in a new tab) attached at a higher node cascades to everything below it, so effective permissions are found by evaluating the full chain from organization to resource.
The Google Cloud resource hierarchy defines three management layers that structure billing, visibility, and security. All resources that belong to an organization are grouped under the organization node, which provides central visibility and control over every folder, project, and service resource. An organization can contain folders, each folder can contain projects and nested folders, and each project contains service resources such as Compute Engine virtual machines, Pub/Sub topics, Cloud Storage buckets, and Cloud VPN endpoints.
| Level | Contains | Control provided |
|---|---|---|
| Organization resource | Folders and projects for the whole company | Central visibility, billing structure, and top-level security model |
| Folders | Related projects and nested folders | Grouped policies that cascade across multiple projects and separation by team or environment |
| Projects | Service resources such as VMs, topics, buckets, and endpoints | Isolation between environments like production versus staging and between teams |
A parent folder can contain up to 300 folders, and folders can be nested up to 10 levels deep. If an organization has more than 300 tenants, tenants can be arranged into nested hierarchies to stay within the limit. The hierarchy is designed to mirror business processes and reporting structure, so teams that manage networks, clusters, or tenant workloads each receive their own branch.
An IAM allow policy in Google Cloud binds principals to roles on a specific node, and that binding flows to all descendants of the node. Access is evaluated when a principal attempts to access a resource, based on policies attached along the resource lineage from the organization through folders and projects to the resource itself. Setting a policy on a folder therefore grants access for every project and service resource under that folder without repeating the grant on each child.
The access model consists of four core concepts:
Organization policies follow a similar inheritance pattern where a setting on a parent applies to all child folders and projects. For example, if a Restrict TLS Versions constraint denies TLS 1.0 at the organization level, it is also denied for all descendant folders and projects. A child can set its own organization policy to change that inherited restriction, and that child policy then applies to its own descendants through the same inheritance.
Exam tip: Use a folder-level grant when the same access applies to every project in a team or environment, and use a project-level grant when access must be limited to one environment or workload.
Using hierarchy to enforce isolation and least privilege means using folders for broad delegation and projects for strong isolation. A common enterprise pattern creates three top-level folders for the Network Team, the Cluster Team, and Tenants, with each holding subfolders and one project per environment such as development, staging, and production. The Network Team folder hosts VPCs per environment, the Cluster Team uses per-environment folders that group cluster projects, and the Tenants folder holds a subfolder per tenant with its own projects or subfolders.
Projects are the primary boundary for segregation because IAM configuration, workload blast radius, and quotas are enforced per project. Placing different clusters in different projects ensures a misconfiguration in one project does not affect all clusters at once, a compromised workload has limited impact on other projects, and one autoscaled workload cannot exhaust quota for the entire environment. Per-environment folders still allow low-risk policies and aggregated log sinks to be applied to all production clusters at once. Tags (opens in a new tab) provide fine-grained control by annotating resources and conditionally allowing policies, while Google Groups let a group receive a job-function role once so membership changes do not require policy edits.
Service Account Security and Workload Identity is the practice of giving applications their own non-human identities while avoiding long-lived secrets. A service account (opens in a new tab) is an IAM identity for software rather than a person, and Workload Identity Federation for GKE (opens in a new tab) lets pods in Google Kubernetes Engine (GKE) act as a Google service account without downloading keys. Together they enforce least privilege by granting each workload only the permissions and scopes it needs to call specific Google Cloud APIs.
Risks of long-lived service account keys come from downloadable credentials that create lasting exposure if they leak. When a key is used, its value is stored in gcloud CLI configuration files separately from the downloaded key file, and copies often remain in local file systems, internal code repositories, or build artifacts. An attacker with read access to any of those locations can copy the key and reuse it from outside the environment until the key is deleted or rotated. Because the key does not expire on its own, one compromise can provide extended access to every resource the service account can reach.
Eliminating service account keys means replacing them with short-lived, automatically managed authentication and blocking new keys with policy. The preferred approach is to use more secure alternatives such as Workload Identity Federation for GKE or attached service accounts on Compute Engine, so no downloadable secret ever leaves Google Cloud. To enforce this, set the organization policy constraint constraints/iam.disableServiceAccountKeyCreation to prevent creation of new keys, and tightly control who can access and impersonate existing service accounts. When keys cannot be removed immediately, rotate each key every 90 days or less and treat rotation as a temporary control, not a fix.
| Authentication option | Credential handling | How access is controlled |
|---|---|---|
| Service account key authentication | Long-lived private key stored in a downloaded file and in gcloud CLI config; copyable from filesystem or repository | Bearer key grants the full permissions of the service account until deleted |
| Workload Identity Federation for GKE with the GKE metadata server | No downloaded key; the metadata server issues short-lived tokens to the pod automatically | IAM allow policy maps a specific Kubernetes identity to a specific Google service account for defined APIs |
Exam tip: Key rotation every 90 days reduces exposure, but disabling key creation with constraints/iam.disableServiceAccountKeyCreation is stronger because no long-lived secret exists to steal.
Least-privilege service accounts for GKE node pools ensure that the nodes themselves cannot become an over-privileged path to Google Cloud. A GKE node pool configuration must specify a custom service account with only the minimal permissions required to run nodes, and it must not use the default Compute Engine service account. Security Command Center flags a violation as OVER_PRIVILEGED_ACCOUNT when the node pool uses the default account or no dedicated account, and as OVER_PRIVILEGED_SCOPES when OAuth scopes are too broad. The same least-privilege rule applies to workload identities: avoid the primitive roles Owner (roles/owner), Editor (roles/editor), and Viewer (roles/viewer) on user-created service accounts ending in iam.gserviceaccount.com, and replace them with granular predefined or custom roles.
If the default service account must remain temporarily, limit its OAuth access scopes to only the allowed list:
https://www.googleapis.com/auth/devstorage.read_only for read-only storage accesshttps://www.googleapis.com/auth/logging.write for writing logshttps://www.googleapis.com/auth/monitoring for writing monitoring metricsThe node pool depends on the assigned service account for its cloud permissions, so shrinking either IAM roles or OAuth scopes directly shrinks the blast radius if a node or pod is compromised.
Workload Identity Federation for GKE is the keyless way for a Kubernetes workload to authenticate to Google Cloud. The flow starts at the pod, which requests credentials from the GKE metadata server; the metadata server then issues a short-lived token that the workload presents to a Google Cloud API, and IAM checks whether an allow policy permits that Kubernetes identity to impersonate the target service account. Access is granted only to the specific APIs named in the IAM policy, with no manual key distribution and no secret to rotate. Migration means updating existing applications to use this federation instead of mounted key files, and Security Command Center flags clusters without it as GKE_METADATA_SERVER_DISABLED.
Ongoing hygiene keeps remaining service accounts from drifting back to high risk. Service accounts that show no usage should be identified with service-account insights and removed, temporary grants should use time-bound IAM conditions and be revoked within 24 hours, and privileged use should be audited by enabling ADMIN_READ, DATA_READ, and DATA_WRITE audit logs for iam.googleapis.com, sts.googleapis.com, and iamcredentials.googleapis.com.
Role Differentiation and Least Privilege Enforcement means giving each identity only the permissions it needs to do its job and nothing more. Identity and Access Management (IAM) (opens in a new tab) enforces this by binding a principal, such as a user, group, or service account, to a role on a specific resource. A role is a collection of permissions, so when a principal is granted a role, the principal receives every permission contained in that role.
Grants follow the Google Cloud resource hierarchy of organizations, folders, and projects. A role granted at a higher level is inherited by resources below it, so a project inherits roles granted on its parent folder and organization. This inheritance controls both convenience and risk, because a broad grant at the top affects many resources while a narrow grant on one project affects only that project.
Role types in IAM differ by how broad their permissions are, who defines them, and how their names are formatted. Primitive roles are broad and cover many services, predefined roles are narrower and tied to specific services or job functions, and custom roles are defined by the customer for a specific need. The production rule is to avoid primitive roles and choose a predefined or custom role that contains only the required permissions.
| Role type | Permission scope | Example identifiers |
|---|---|---|
| Primitive, also called basic | Broad access across a project, including many permissions at once | Owner (roles/owner), Editor (roles/editor), Viewer |
| Predefined | Narrower permissions for a specific service or task, managed for common job functions | Project Creator (roles/resourcemanager.projectCreator), Service Usage Admin (roles/serviceusage.serviceUsageAdmin), roles/gkehub.gatewayReader, roles/gkehub.gatewayEditor, roles/gkehub.gatewayAdmin, roles/gkehub.viewer |
| Custom | Customer-defined set of permissions for cases where predefined roles are too broad or too narrow | Project-level custom roles named projects/PROJECT_ID/roles/IDENTIFIER, organization-level custom roles named organizations/ORG_ID/roles/IDENTIFIER, while predefined roles use roles/SERVICE.IDENTIFIER |
Primitive roles grant wide capability that is rarely needed for daily work. For example, the Owner role contains the serviceusage.services.enable permission, but that same permission is also available through the narrower Service Usage Admin role. Choosing the narrower role keeps the same task possible while removing unrelated permissions, which is the core of least privilege.
Exam tip: In production environments, do not grant Owner, Editor, or Viewer; grant a predefined or custom role that meets the need instead.
Enforcing least privilege on projects, folders, and organizations means selecting the lowest resource level and the smallest role that still allows the work. The grant is created with the Google Cloud console or with the add-iam-policy-binding command that specifies the resource type, resource ID, principal, role name, and optional condition. Resource types include projects, resource-manager folders, and organizations, and project IDs are alphanumeric while folder and organization IDs are numeric.
A console grant follows an ordered sequence:
user:my-user@example.com or a workforce group identifier.None when no condition is needed.Inherited roles cannot be edited from the child resource where they appear. To change an inherited grant, go to the resource where the role was originally granted and edit it there. To see grants for Google-provided service agents, select the Include Google-provided role grants option so the service agent email address becomes visible.
Service account permissions in IAM separate what the service account can access from who can use the service account. The service account itself is granted roles for the resources its code must reach, such as a Compute Engine instance that needs to call Google APIs. Those roles can be revoked or expanded later, so access can start small and grow only as proven necessary.
A second layer controls which principal can attach the service account to another resource. A user who will attach the service account to a Compute Engine instance needs the Service Account User role (roles/iam.serviceAccountUser) on the service account. Related task roles follow the same pattern, including Create Service Accounts (roles/iam.serviceAccountCreator) with Project IAM Admin (roles/resourcemanager.projectIamAdmin) to create service accounts, and Service Account Token Creator to let a service account create tokens. Keeping these two layers separate prevents a user who can deploy a virtual machine from automatically gaining all of the service account's data permissions.
constraints/iam.disableServiceAccountKeyCreation prevents creation of new service account keys and is stronger than rotating keys every 90 days.An Identity and Access Management (IAM) allow policy attached to an organization, folder, or project flows to all descendants of that node. Effective permissions are determined by evaluating the policies along the full lineage from the Organization resource through folders and projects to the resource.
Use a folder-level Identity and Access Management (IAM) grant when the same access applies to every project in a team or environment. Use a project-level grant when access must be limited to one environment or workload, because projects are the primary boundary for segregation of configuration, blast radius, and quotas.
Workload Identity Federation for Google Kubernetes Engine (GKE) lets a pod request credentials from the GKE metadata server, which issues a short-lived token that the workload presents to a Google Cloud API. Identity and Access Management (IAM) then checks whether an allow policy permits that Kubernetes identity to impersonate the target service account for the specific APIs named, so no downloadable key is distributed or rotated.
Identity and Access Management (IAM) primitive roles grant broad access across a project, predefined roles grant narrower permissions for a specific service or job function, and custom roles are customer-defined sets of permissions for cases where predefined roles are too broad or too narrow. In production, the primitive Owner, Editor, and Viewer roles should be replaced with narrower predefined or custom roles that contain only the required permissions.
An enterprise is running containerized microservices in a Google Kubernetes Engine (GKE) cluster. Currently, these microservices access Google Cloud APIs by mounting long-lived service account private key JSON files stored as Kubernetes secrets.
The security compliance team has flagged this practice due to the severe risk of credential leakage and unauthorized key export. They require an authentication architecture that eliminates static keys and enforces least privilege access for each individual microservice workload.
Which solution should the cloud architect implement?
Implement an automated Cloud Function to regenerate and rotate service account JSON keys every 24 hours, updating the Kubernetes secrets accordingly.
Enable Workload Identity on the GKE cluster, configure each pod to use a dedicated Kubernetes Service Account (KSA), bind the KSA to a Google Service Account (GSA) using the Workload Identity User role, and annotate the KSA.
Grant the necessary IAM roles directly to the default Compute Engine service account attached to the GKE cluster node pool.
Store the service account private key JSON files in Secret Manager and configure microservices to dynamically fetch the keys using Secret Manager API at startup.
Last updated