Hashicorp Vault Secrets Backend¶
To enable Hashicorp vault to retrieve Airflow connection/variable, specify VaultBackend
as the backend
in [secrets]
section of airflow.cfg
.
Here is a sample configuration:
The default KV version engine is 2
, pass kv_engine_version: 1
in backend_kwargs
if you use
KV Secrets Engine Version 1
.
You can also set and pass values to Vault client by setting environment variables. All the environment variables listed at https://www.vaultproject.io/docs/commands/#environment-variables are supported.
Hence, if you set VAULT_ADDR
environment variable like below, you do not need to pass url
key to backend_kwargs
:
Optional lookup¶
Optionally connections, variables, or config may be looked up exclusive of each other or in any combination. This will prevent requests being sent to Vault for the excluded type.
If you want to look up some and not others in Vault you may do so by setting the relevant *_path
parameter of the ones to be excluded as null
.
For example, if you want to set parameter connections_path
to "airflow-connections"
and not look up variables, your configuration file should look like this:
Storing and Retrieving Connections¶
If you have set connections_path
as connections
and mount_point
as airflow
, then for a connection id of
smtp_default
, you would want to store your secret as:
Note that the Key
is conn_uri
, Value
is postgresql://airflow:airflow@host:5432/airflow
and
mount_point
is airflow
.
You can make a mount_point
for airflow
as follows:
Verify that you can get the secret from vault
:
The value of the Vault key must be the connection URI representation of the connection object to get connection.
Storing and Retrieving Variables¶
If you have set variables_path
as variables
and mount_point
as airflow
, then for a variable with
hello
as key, you would want to store your secret as:
Verify that you can get the secret from vault
:
Note that the secret Key
is value
, and secret Value
is world
and
mount_point
is airflow
.