A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/iam/docs/service-account-impersonation below:

Service account impersonation | IAM Documentation

Service account impersonation

Stay organized with collections Save and categorize content based on your preferences.

When an authenticated principal, such as a user or another service account, authenticates as a service account to gain the service account's permissions, it's called impersonating the service account. Impersonating a service account lets an authenticated principal access whatever the service account can access. Only authenticated principals with the appropriate permissions can impersonate service accounts.

Impersonation is useful when you want to change a user's permissions without changing your Identity and Access Management (IAM) policies. For example, you can use impersonation to temporarily grant a user elevated access, or to test whether a specific set of permissions is sufficient for a task. You can also use impersonation to locally develop applications that can only run as a service account, or to authenticate applications that run outside of Google Cloud.

Google Cloud service account impersonation is similar to Amazon Web Services (AWS) Security Token Service API methods like AssumeRole.

How service account impersonation works

Service account impersonation always involves two identities: an authenticated principal, and the service account that the principal impersonates. To impersonate the service account, the authenticated principal gets a token for the service account, then uses that token to authenticate as the service account.

There are multiple ways to impersonate a service account:

If a principal accesses resources while impersonating a service account, most audit logs include both their identity and the identity of the service account they're impersonating. For more information, see Interpreting audit logs.

When you use the Google Cloud console, you always authenticate with your user credentials; you can't impersonate a service account to access resources in the Google Cloud console.

Authentication without impersonation

There are several ways for a workload or user to authenticate as a service account without impersonating the service account:

In these cases, the audit logs record only the identity of the service account. They don't record any other identities—for example, the identities of the users who executed code on the workload, or the identities of the people who used the service account key to authenticate. As a result, using service account keys or giving developers permission to execute code on privileged resources—for example, an SSH session to a VM instance—can create privilege-escalation and non-repudiation risks.

Required permissions

To impersonate a service account, you need the iam.serviceAccounts.getAccessToken permission. This permission is in roles like the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator).

For more information about roles required for impersonation, see Roles for service account authentication.

Use cases for service account impersonation

Service account impersonation is useful when you need to do tasks like the following:

Grant temporary elevated access

In some cases, you might want to let a user access specific resources temporarily. For example, you might want to give someone additional access so that they can resolve an incident, or let someone access sensitive data for a limited time after they've logged a justification.

Service account impersonation is one of the ways that you can give users this temporary elevated access. To use a service account for temporary elevated access, you first grant it the IAM roles that you want to temporarily give to users. Then, you let users impersonate the service account, either by giving them permission to impersonate the service account or by using a token broker to issue a short-lived credential for the service account.

To learn more about methods for giving users temporary elevated access, see Temporary elevated access overview.

Test permissions

In some cases, you might want to check whether a specific set of permissions is sufficient for a task. For example, you might want to confirm that a service account can still run an application if you remove certain excess permissions. Or, you might be helping a user to troubleshoot a task and want to verify that they can run a certain command with their current IAM roles.

You can use service account impersonation to test a specific set of permissions. First, create a service account and grant it one or more IAM roles with the permissions that you want to test. Then, impersonate the service account and attempt the task. This method lets you test permissions without needing to create test user accounts or modify your own IAM permissions.

To learn how to impersonate service accounts, see Use service account impersonation.

Develop applications locally

When developing applications locally, you can typically authenticate using your user credentials. However, in some situations, that might not be possible—for example, if you want to authenticate to a service that requires a token with a custom audience, which users typically can't configure. In these cases, you need to authenticate as a service account instead of authenticating with your user credentials.

For these situations, we recommend using service account impersonation. Using service account impersonation lets you avoid using service account keys, which create additional security risk.

To learn how to impersonate service accounts to develop applications, see Service account impersonation.

Authenticate external applications

To access Google Cloud resources, applications running outside of Google Cloud need to authenticate to Google Cloud. One way to authenticate these applications is to use service account impersonation.

To let your application impersonate a service account, you first need to set up Workload Identity Federation, which provides an authenticated identity for your application. Then, you can use a credential configuration file to configure your application to impersonate a service account.

Although it's possible to use service account keys to authenticate external applications, we strongly recommend against it. Service account keys create additional security risk, and should be avoided when possible.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-02 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[[["Service account impersonation allows an authenticated principal to assume the permissions of a service account, granting them access to resources the service account can access."],["Impersonation is useful for scenarios like temporarily granting elevated access to users, testing permission sets, developing applications locally, and authenticating external applications."],["There are multiple ways to impersonate a service account, including using the Google Cloud CLI, creating short-lived credentials via the Service Account Credentials API, or leveraging credential configuration files with Workload Identity Federation."],["Authenticating as a service account without impersonation can be achieved by using an attached service account or a service account key, but service account keys pose a higher security risk."],["To impersonate a service account, the principal needs the `iam.serviceAccounts.getAccessToken` permission, typically found in roles like the Service Account Token Creator role."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4