In this section, you’ll learn how to use Hashicorp Vault as a secrets backend for both local development and on Astro Private Cloud. To do this, you will:
astro dev init.http://127.0.0.1:8200/.If you don’t already have a Vault server deployed but would like to test this feature, Astronomer recommends that you either:
To use Vault as a secrets backend, Astronomer recommends configuring a Vault AppRole with a policy that grants only the minimum necessary permissions for Astro Private Cloud. 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-id and secret-id for your AppRole by running the following commands:
Save these values for Step 3.
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:
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:
In your Astro project, add the Hashicorp Airflow provider to your project by adding the following to your requirements.txt file:
Then, add the following environment variables to your Dockerfile:
This tells Airflow to look for variable and connection information at the 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 Astro Private Cloud, 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 Astro Private Cloud in Step 4, you can set these values as secrets in the UI.
"kv_engine_version": 2, but this secret was written using v1. You can change this to accommodate how you write and read your secrets.For more information on the Airflow provider for Hashicorp Vault and how to further customize your integration, see the Apache Airflow documentation.
To test Vault, write a simple Dag which calls your test secret and add this Dag to your project’s dags directory. For example, you can use the following Dag to print the value of a variable to your task logs:
Once you’ve added this Dag to your project:
Run astro dev restart to push your changes to your local Airflow environment.
In the Airflow UI (http://localhost:8080/admin/), trigger your new Dag.
Click test-task > View Logs. If you ran the example Dag above, you should see the contents of your secret in the task logs:
Once you confirm that the setup was successful, you can delete this example Dag.
Once you’ve confirmed that the integration with Vault works locally, you can complete a similar set up with a Deployment on Astro Private Cloud.
Dockerfile to your Deployment environment variables. Specify AIRFLOW__SECRETS__BACKEND_KWARGS as secret to ensure that your Vault credentials are stored securely.Dockerfile.Now, any Airflow variable or connection that you write to your Vault server can be successfully accessed and pulled by any Dag in your Deployment on Astro Private Cloud.