This documentation is for the Latest version of Cloud Run for Anthos, which uses Anthos fleets and Anthos Service Mesh. Learn more.

The past version has been archived but the documentation remains available for existing users.

Using OAuth2 access tokens

You can use access tokens to authenticate for a short period of time with Google Cloud APIs. If access tokens are not required, you should use a service account to authenticate your Cloud Run for Anthos services.

Fetching access tokens

When your code runs on Cloud Run for Anthos it can use the Compute Metadata Server to fetch access tokens. You cannot query the metadata server directly from your local computer.

Access tokens

By default, access tokens have the cloud-platform scope, which allows access to all Google Cloud APIs, assuming Identity and Access Management also allows access. In order to access other Google or Google Cloud APIs, you will need to fetch an access token with the appropriate scope.

You can use the Compute Metadata Server to fetch access tokens.

If you need an access token with a specific scope, you can generate one as follows:

curl "[SCOPES]" \
  -H "Metadata-Flavor: Google"

Where SCOPES is a comma separated list of OAuth scopes requested, for example:,

Consult the full list of Google OAuth scopes to find which scopes you need.

Next steps

Learn how to manage access to your services.