Professional Cloud Security Engineer
Service account impersonation replaces permanent credentials by issuing short-lived credentials that expire automatically after a set duration. The IAM Credentials API generates OAuth 2.0 access tokens for API authorization, OIDC ID tokens for identity verification, and cryptographic signatures for data payloads. Developers can invoke impersonation locally by passing the --impersonate-service-account flag in the Google Cloud CLI, while automated workloads query the local instance metadata server. CI/CD pipelines can also request temporary tokens directly through API methods like generateAccessToken and generateIdToken to avoid embedding static keys in configuration files.
Impersonation creates a direct relationship between the calling identity and the target privilege-bearing service account. To establish this delegation path, the caller must hold specific permissions such as iam.serviceAccounts.getAccessToken, iam.serviceAccounts.signBlob, or iam.serviceAccounts.getOpenIdToken. Workloads running outside Google Cloud should pair this workflow with Workload Identity Federation rather than storing private keys. Security policies must strictly block self-impersonation, a misconfiguration where a service account mints tokens for itself and creates an endless token-refresh cycle that bypasses lifetime limits.
Security operations teams evaluate impersonated requests by analyzing entry fields in Cloud Audit Logs. When an identity acts through impersonation, the log records the target service account inside the principal email field because that identity authorized the underlying API call. The actual human operator or originating system is recorded inside the service account delegation info metadata structure. Analysts inspect the earliest entry in this delegation chain to identify the true originating caller during incident investigations.
[Originating Principal] -> [Delegation Chain / Impersonation] -> [Target Service Account] -> [Resource Action]
Enterprise governance frameworks prevent credential leakage by enforcing strict guardrails across project hierarchies:
iam.disableServiceAccountKeyCreation constraint via the Organization Policy Service to block the export of static private keys.Administrators must grant impersonation roles directly on the individual target service account resource rather than at the project, folder, or organization level. Applying the Service Account Token Creator (roles/iam.serviceAccountTokenCreator) role or the Service Account OpenID Connect Identity Token Creator (roles/iam.serviceAccountOpenIdTokenCreator) role to an entire project allows the user to impersonate every service account within that boundary. Granting the role on the specific service account restricts delegation exclusively to that identity. This resource-level scoping ensures that human operators only access the exact permissions required for their specific workload.
Security architects must separate token generation permissions from workload attachment permissions to prevent unintended privilege escalation:
Gauge your current knowledge
Gauge your current knowledge