This page provides information and links for authenticating to the
Cloud Run Admin API. You can [access the Cloud Run Admin API](https://docs.cloud.google.com/run/docs/reference/cloud-run-admin-api-overview.md.txt) using the following methods:

- Google Cloud CLI
- REST API
- Cloud Client Libraries

This page doesn't cover authenticating to Cloud Run services. For that
information, see
[Authentication overview for Cloud Run services](https://docs.cloud.google.com/run/docs/authenticating/overview.md.txt).

## Authenticate to the Cloud Run Admin API

Authentication varies by the environment that you run your
service in. Click a tab for instructions for your use case:

### Google Cloud CLI

To authenticate a workload running on Google Cloud, use the credentials of the
[service identity](https://docs.cloud.google.com/run/docs/securing/service-identity.md.txt) attached to the Cloud Run service by following these
steps:

1. Install the Google Cloud CLI, then initialize it using the following command:

   ```yaml
   gcloud init
   ```
2. Set up authentication:

   1. Create the service account:

      ```bash
      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
      ```
      Replace <var translate="no">SERVICE_ACCOUNT_NAME</var> with a name for the service account.

      <br />

   2. Provide access to your project and your resources by granting a role to
      the service account:

      ```yaml
      gcloud projects add-iam-policy-binding PROJECT_ID 

      --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" 

      --role=ROLE
      ```
      Replace the following:

      <br />

      - <var translate="no">SERVICE_ACCOUNT_NAME</var>: the name of the service account
      - <var translate="no">PROJECT_ID</var>: the project ID where you created the service account
      - <var translate="no">ROLE</var>: the role required to access the Cloud Client Libraries.

      > [!NOTE]
      > **Note:** The `--role` flag determines the resources in your project that can be accessed by the service account. You can revoke these roles or grant additional roles later. In production environments, don't grant the Owner, Editor, or Viewer roles. Instead, grant a predefined role or custom role that meets your needs.

   3. To grant another role to the service account, run the command as you did
      in the previous step.

   4. Grant your account a role that lets you use the service account
      roles and attach the service account to other resources:

      ```yaml
      gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com 

      --member="user:USER_EMAIL" --role=roles/iam.serviceAccountUser
      ```
      Replace the following:

      <br />

      - <var translate="no">SERVICE_ACCOUNT_NAME</var>: the name of the service account
      - <var translate="no">PROJECT_ID</var>: the project ID where you created the service account
      - <var translate="no">USER_EMAIL</var>: the email address for your account
3. Create the resource that will run your code, and attach the service account to that resource.

### Local development


You can set up credentials for a local development environment in the following ways:

- User credentials for client libraries or third-party tools
- User credentials for REST requests from the command line

  #### Client libraries or third-party tools


  Set up
  [Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/application-default-credentials.md.txt)
  in your local environment:
  1.
     [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

     After installation,
     [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the Google Cloud CLI by running the following command:

     ```bash
     gcloud init
     ```


     If you're using an external identity provider (IdP), you must first
     [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).
  2.

     If you're using a local shell, then create local authentication credentials for your user
     account:

     ```bash
     gcloud auth application-default login
     ```

     You don't need to do this if you're using Cloud Shell.


     If an authentication error is returned, and you are using an external identity provider
     (IdP), confirm that you have
     [signed in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).


     A login screen is displayed. After you log in, your credentials
     are stored in the local credential file used by ADC.


  For more information, see
  [Set up ADC for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

  #### REST requests from the command line


  When you make a REST request from the command line,
  you can use your gcloud CLI credentials by including
  [`gcloud auth print-access-token`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/print-access-token.md.txt)
  as part of the command that sends the request.


  The following example lists service accounts for the specified project. You can use the
  same pattern for any REST request.


  Before using any of the request data,
  make the following replacements:
  - <var translate="no">PROJECT_ID</var>: Your Google Cloud project ID.

  To send your request, expand one of these options:

  #### curl (Linux, macOS, or Cloud Shell)


  Execute the following command:

  ```
  curl -X GET \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       "https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts"
  ```

  #### PowerShell (Windows)


  Execute the following command:

  ```
  $cred = gcloud auth print-access-token
  $headers = @{ "Authorization" = "Bearer $cred" }

  Invoke-WebRequest `
      -Method GET `
      -Headers $headers `
      -Uri "https://iam.googleapis.com/v1/projects/PROJECT_ID/serviceAccounts" | Select-Object -Expand Content
  ```


  For more information about authenticating using REST and gRPC, see
  [Authenticate for using REST](https://docs.cloud.google.com/docs/authentication/rest.md.txt).
  For information about the difference between your local ADC credentials and your
  gcloud CLI credentials, see
  [gcloud CLI credentials and ADC credentials](https://docs.cloud.google.com/docs/authentication/gcloud#gcloud-credentials).

### On-prem/other cloud

We recommend that you use Workload Identity Federation to set up authentication
from outside of Google Cloud. For more information, see
[Set up ADC for on-premises or another cloud provider](https://docs.cloud.google.com/docs/authentication/set-up-adc-on-premises.md.txt).