This topic provides setup steps for configuring Google Cloud Secret Manager as a secrets backend on Astro. If you use a different secrets backend tool or want to learn the general approach on how to integrate one, see Configure a Secrets Backend.Documentation Index
Fetch the complete documentation index at: https://astronomer-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- A Deployment.
- The Astro CLI.
- An Astro project.
- Cloud SDK.
- A Google Cloud environment with Secret Manager configured.
- A service account with the Secret Manager Secret Accessor role on Google Cloud.
- (Optional) A JSON service account key for the service account. This is required to provide access to a secrets backend from a local machine, or when you’re not using Workload Identity.
- (Remote Execution Only) Helm installed
- (Remote Execution Only) The
values.yamlfile from the Register Agents modal in your Deployments>Agents page.
Step 1: Create an Airflow variable or connection in Google Cloud Secret Manager
To start, create an Airflow variable or connection in Google Cloud Secret Manager that you want to store as a secret. You can use the Cloud Console or the gcloud CLI. Secrets must be formatted such that:- Airflow variables are set as
airflow-variables-<variable-key>. - Airflow connections are set as
airflow-connections-<connection-id>.
my-secret-variable, you run the following gcloud CLI command:
Step 2: Set up GCP Secret Manager locally
- Astro
- Remote Execution
- Copy the complete JSON service account key for the service account that you want to use to access Secret Manager.
-
Add the following environment variables to your Astro project’s
.envfile, replacing<your-service-account-key>with the key you copied in Step 1: -
(Optional) Run
Variable.get("<your-variable-key>")to run a dag locally and confirm that your variables are accessible.
Step 3: (Astro Only) Configure Secret Manager on Astro using Workload Identity (Recommended)
- Set up Workload Identity for your Airflow Deployment. See Connect Astro to GCP data sources.
-
Run the following commands to set the secrets backend for your Astro Deployment:
-
(Optional) Remove the environment variables from your
.envfile or store your.envfile in a safe location to protect your credentials inAIRFLOW__SECRETS__BACKEND_KWARGS.
.env variable is only available in your local environment and not in the Astro UI . See Set Environment Variables Locally.
Step 4: Configure Secret Manager on Astro using a service account JSON key file
- Astro
- Remote Execution
- Set up the Secret Manager locally. See Set up GCP Secret Manager locally.
-
Run the following command to set the
SECRET_VAR_SERVICE_ACCOUNTenvironment variable on your Astro Deployment: -
(Optional) Remove the environment variables from your
.envfile or store your.envfile in a safe location to protect your credentials inAIRFLOW__SECRETS__BACKEND_KWARGS.