Authenticating in the Yandex Cloud CLI with an IAM token from an environment variable
An IAM token is a unique sequence of characters used for authentication in Yandex Cloud that verifies the identity of a user or service account. IAM tokens are valid for a maximum of 12 hours.
Authentication with an IAM token from the YC_IAM_TOKEN environment variable is a convenient option for scripts, CI/CD workflows, automated tests, containers, and temporary runtime environments where it is impractical to use interactive authentication or store credentials in the CLI profile. For automation, use the IAM token of a service account that has the required roles. Configure a mechanism to issue a new IAM token before the current token expires.
Warning
Do not use the IAM token in source code or write it to logs. For CI/CD workflows, store the token in a secure secret vault.
If a token is compromised or no longer required, revoke it.
Getting started
-
Get an IAM token.
Authenticate with an IAM token
-
Add your IAM token to the
YC_IAM_TOKENenvironment variable:macOS/LinuxWindows (PowerShell)export YC_IAM_TOKEN="<IAM_token>"$env:YC_IAM_TOKEN = "<IAM_token>"The variable will be available in the current shell session and its child processes.
Warning
The value from the
YC_IAM_TOKENenvironment variable overrides the authentication credentials specified in the CLI profile. -
Run a CLI command, e.g., to get a list of VMs within a folder:
yc compute instance list
Delete the IAM token from the environment variable
To enable the CLI to use the profile credentials again, delete the YC_IAM_TOKEN environment variable:
unset YC_IAM_TOKEN
Remove-Item Env:YC_IAM_TOKEN
Warning
Deleting the environment variable does not invalidate the IAM token.