In this section, you’ll learn how to use Google Cloud Secret Manager as a secrets backend on Astro Private Cloud.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 initialized with
astro dev init. - Cloud SDK.
- A Google Cloud environment with Secret Manager configured.
- A service account with the Secret Manager Secret Accessor role on Google Cloud.
- A JSON service account key for the service account.
Step 1: Write an Airflow variable or connection to Google Cloud Secret Manager
To start, add an Airflow variable or connection as a secret to Google Cloud Secret Manager. You can do so in 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 would run the following gcloud CLI command:
Step 2: Set up Secret Manager locally
To test Google Secret Manager locally, configure it as a secrets backend in your Astro project. First, install the Airflow provider for Google by adding the following to your project’srequirements.txt file:
<your-key-file>. In the next step, you’ll test that this configuration is valid locally.
If you want to deploy your project to a hosted Git repository before deploying to Astronomer, be sure to save
<your-key-file>securely. Astronomer recommends adding it to your project’s.env fileand specifying this file in.gitignore. When you deploy to Astronomer, you should set these values as secrets in the Astro Private Cloud UI.Step 3: Run an example Dag to test Secret Manager locally
To test Secret Manager, create a secret containing either an Airflow variable or connection for testing. Once you create a test secret, write a simple Dag which calls the secret and add this Dag to your project’sdags directory. For example, you can use the following Dag to print the value of a variable to your task logs:
-
Run
astro dev stopfollowed byastro dev startto push your changes to your local Airflow environment. -
In the Airflow UI (
http://localhost:8080/admin/), trigger your new DAG. -
Click on
test-task> View Logs. If you ran the example Dag above, you should see the contents of your secret in the task logs:
Step 4: Deploy to Astro Private Cloud
Once you’ve confirmed that the integration with Google Cloud Secret Manager works locally, you can complete a similar set up with a Deployment on Astro Private Cloud.- In the Astro Private Cloud UI, add the same environment variables found in your
Dockerfileto your Deployment environment variables. Specify bothAIRFLOW__SECRETS__BACKENDandAIRFLOW__SECRETS__BACKEND_KWARGSas Secret to ensure that your credentials are stored securely. - In your Astro project, delete the environment variables from your
Dockerfile. - Deploy your changes to Astro Private Cloud.