Authenticate to Secret Manager

This document describes how to authenticate to Secret Manager programmatically. How you authenticate to Secret Manager depends on the interface you use to access the API and the environment where your code is running.

For information on accessing the Secret Manager API, see Access the Secret Manager API.

For more information about Google Cloud authentication, see the Authentication methods.

API access

Secret Manager supports programmatic access. You can access the API in the following ways:

Client libraries

The Secret Manager client libraries provide high-level language support for authenticating to Secret Manager programmatically. To authenticate calls to Google Cloud APIs, client libraries support Application Default Credentials (ADC); the libraries look for credentials in a set of defined locations and use those credentials to authenticate requests to the API. With ADC, you can make credentials available to your application in a variety of environments, such as local development or production, without needing to modify your application code.

Google Cloud CLI

When you use the gcloud CLI to access Secret Manager, you authenticate to Google Cloud as a principal, which provides the credentials used by the gcloud CLI commands.

If your organization's security policies prevent user accounts from having the required permissions, you can use service account impersonation.

For more information, see Authenticate for the gcloud CLI. For more information about using the gcloud CLI with Secret Manager, see the gcloud CLI reference pages.

REST

You can authenticate to the Secret Manager API by using your gcloud CLI credentials or by using Application Default Credentials. For more information about authentication for REST requests, see Authenticate for using REST.

Set up authentication for Secret Manager

How you set up authentication depends on the environment where your code is running.

The following options for setting up authentication are the most commonly used. For more options and information about authentication, see Authentication methods.

For a local development environment

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

Client libraries or third-party tools

Set up Application Default Credentials (ADC) in your local environment:

  1. Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

    gcloud init

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

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