Secrets backend tool integration benefits
Integrating a secrets backend tool with Astronomer Software allows you to:- Store Airflow variables and connections in a centralized location alongside secrets from other tools and systems used by your organization, including Kubernetes secrets, SSL certificates, and more.
- Comply with internal security postures and policies that protect your organization.
- Recover in the case of an incident.
- Automatically pull Airflow variables and connections that are already stored in your secrets backend when you create a new Deployment instead of having to set them manually in the Airflow UI.
- Hashicorp Vault
- AWS Systems Manager Parameter Store
- Google Cloud Secret Manager
- Azure Key Vault
If you enable a secrets backend on Astronomer Software, you can continue to define Airflow variables and connections either as environment variables or in the Airflow UI as needed. If you define variables and connections in the Airflow UI, they are stored as encrypted values in the Airflow metadata database.
- Secrets backend
- Environment variable
- The Airflow UI
Setup
- Hashicorp Vault
- AWS Secrets Manager
- AWS Parameter Store
- Google Cloud Secret Manager
- Azure Key Vault
In this section, you’ll learn how to use Hashicorp Vault as a secrets backend for both local development and on Astronomer Software. To do this, you will:To store a connection in Vault as a secret, run the following Vault CLI command with your own values:To confirm that your secret was written to Vault successfully, run:Then, add the following environment variables to your This tells Airflow to look for variable and connection information at the For more information on the Airflow provider for Hashicorp Vault and how to further customize your integration, see the Apache Airflow documentation.Once you’ve added this DAG to your project:
- Create an AppRole in Vault which grants Astronomer minimal required permissions.
- Write a test Airflow variable or connection as a secret to your Vault server.
- Configure your Astro project to pull the secret from Vault.
- Test the backend in a local environment.
- Deploy your changes to Astronomer Software.
Prerequisites
- A Deployment on Astronomer.
- The Astro CLI.
- A Hashicorp Vault server.
- An Astro project initialized with
astro dev init. - The Vault CLI.
- Your Vault Server’s URL. If you’re using a local server, this should be
http://127.0.0.1:8200/.
- Sign up for a Vault trial on Hashicorp Cloud Platform (HCP) or
- Deploy a local Vault server. See Starting the server in Hashicorp documentation.
Step 1: Create a Policy and AppRole in Vault
To use Vault as a secrets backend, Astronomer recommends configuring a Vault AppRole with a policy that grants only the minimum necessary permissions for Astronomer Software. To do this:-
Create a Vault policy with the following permissions:
- Create a Vault AppRole and attach the policy you just created to it.
-
Retrieve the
role-idandsecret-idfor your AppRole by running the following commands:Save these values for Step 3.
Step 2: Write an Airflow variable or connection to Vault
To test whether your Vault server is set up properly, create a test Airflow variable or connection to store as a secret.To store an Airflow variable in Vault as a secret, run the following Vault CLI command with your own values:Step 3: Set up Vault locally
In your Astro project, add the Hashicorp Airflow provider to your project by adding the following to yourrequirements.txt file:Dockerfile:secret/variables/* and secret/connections/* paths in your Vault server. In the next step, you’ll test this configuration in a local Airflow environment.If you want to deploy your project to a hosted Git repository before deploying to Astronomer Software, be sure to save
<your-approle-id> and <your-approle-secret> securely. Astronomer recommends adding them to your project’s .env file and specifying this file in .gitignore.When you deploy to Astronomer Software in Step 4, you can set these values as secrets in the Software UI. By default, Airflow uses
"kv_engine_version": 2, but this secret was written using v1. You can change this to accommodate how you write and read your secrets.Step 4: Run an example DAG to test Vault locally
To test Vault, write a simple DAG which calls your test 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 restartto 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 5: Deploy on Astronomer Software
Once you’ve confirmed that the integration with Vault works locally, you can complete a similar set up with a Deployment on Astronomer Software.- In the Software UI, add the same environment variables found in your
Dockerfileto your Deployment environment variables. SpecifyAIRFLOW__SECRETS__BACKEND_KWARGSas secret to ensure that your Vault credentials are stored securely. - In your Astro project, delete the environment variables from your
Dockerfile. - Deploy your changes to Astronomer Software.