> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to impersonate a service account

You can perform operations on behalf of a [service account](https://docs.nebius.com/iam/service-accounts/manage.md) without creating [authorized keys](https://docs.nebius.com/iam/service-accounts/authorized-keys.md) for it. To do this, *impersonate* the service account with your user account credentials.

When you impersonate a service account, IAM exchanges your user account's access token for an access token of the service account. Operations that you perform with this token are performed by the service account, and IAM checks the permissions of the service account. For example, if the service account is only in a group with the `viewer` role, you can read resources but not create or modify them, even if you are an administrator.

Impersonation is useful when you want to:

* Run commands or Terraform configurations as a service account without storing its credentials.
* Check which operations a service account can perform with its current group memberships.

## Prerequisites

> [tab] CLI
>
> 1. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.
>
> 2.
>
> 3. [Create a service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-cli) if you haven't already.
>
> 4. [Add the service account to a group](https://docs.nebius.com/iam/authorization/groups/members.md) that grants it the required permissions.

> [tab] Terraform
>
> 1. [Install and configure](https://docs.nebius.com/terraform-provider/install.md) the Nebius AI Cloud provider for Terraform.
>
> 2. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI. You need it to get an access token for your user account.
>
> 3.
>
> 4. [Create a service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-terraform) if you haven't already.
>
> 5. [Add the service account to a group](https://docs.nebius.com/iam/authorization/groups/members.md) that grants it the required permissions.

## How to impersonate a service account

> [tab] CLI
>
> To run a Nebius AI Cloud CLI command as the service account, add the `--impersonate-service-account-id` (or `-I` as a short version) parameter to the command. You can add it to any command.
>
> To run all commands of a CLI profile as the service account, add the `impersonate-service-account-id` key to the profile in the `~/.nebius/config.yaml` file:
>
> ```yaml theme={null}
> profiles:
>   <profile_name>:
>     impersonate-service-account-id: <service_account_ID>
> ```
>
> To check that impersonation works:
>
> 1. List service accounts in your project and copy the ID of the service account (`metadata.id`) to impersonate:
>
>    ```bash theme={null}
>    nebius iam service-account list
>    ```
>
> 2. Check that the command uses the identity of the service account:
>
>    ```bash theme={null}
>    nebius iam whoami --impersonate-service-account-id <service_account_ID>
>    ```
>
>    In this command, `<service_account_ID>` is the `metadata.id` value that you copied in the previous step.
>
>    The `service_account_profile.info.metadata.id` in the output should match the ID of the service account.
>
> To get an access token of the service account, for example, to use it in API requests or other tools, run:
>
> ```bash theme={null}
> nebius iam get-access-token --impersonate-service-account-id <service_account_ID>
> ```
>
> For more information about access tokens, see [Access tokens in Nebius AI Cloud](https://docs.nebius.com/iam/authorization/access-tokens.md).

> [tab] Terraform
>
> To manage resources with Terraform as the service account:
>
> 1. Add the `impersonate_service_account_id` argument to the provider configuration:
>
>    ```hcl theme={null}
>    provider "nebius" {
>      impersonate_service_account_id = "<service_account_ID>"
>    }
>    ```
>
>    To copy the service account ID from the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, and next to the ID, click .
>
> 2. Get an access token for your user account and save it to the `NEBIUS_IAM_TOKEN` environment variable:
>
>    ```bash theme={null}
>    export NEBIUS_IAM_TOKEN=$(nebius iam get-access-token)
>    ```
>
>    The provider uses this token to get an access token of the service account. For other ways to authenticate as your user account, see [Authentication for a user account](https://docs.nebius.com/terraform-provider/authentication.md#authentication-for-a-user-account).
>
> 3. Apply the changes:
>    ```bash theme={null} theme={null}
>    terraform apply
>    ```
>
> For all available provider arguments, see the [full reference](https://docs.nebius.com/terraform-provider/reference/provider.md).

## See also

* [How to authenticate as a service account](https://docs.nebius.com/iam/service-accounts/authentication.md)
* [Authentication in the Nebius AI Cloud provider for Terraform](https://docs.nebius.com/terraform-provider/authentication.md)
