Skip to main content

Configure secret backends

Keep the connections and variables of your DAGs in FPT Key Vault or Azure Key Vault, and let Airflow read them through a secret backend. Set up the secret backend on the service, then check the setup with a test DAG.

Prerequisites​

  • An Orchestration service. See Create an Orchestration service.
  • For FPT Key Vault, the URL of your vault, the mount point and paths that hold your connections and variables, and a token for the vault.
  • For Azure Key Vault, the values of the Vault URL, Tenant ID, Client ID, and Client Secret fields.

Set up the secret backend on the service​

You can set up the secret backend when you create the service, on the Advanced screen of the form. See Secret backends. To set it up or change it later, use the Advanced tab of the service.

  1. Select Data platform → Workspace management, then select your workspace.

  2. On the Overview tab, under Services, select Orchestration.

  3. Select the Advanced tab.

  4. In Secret backends, select the edit icon.

    Update secrets backends panel with the Provider, Mount point, Connection path, Variable path, URL, Auth type, and Token fields and the Test connection and Save buttons

  5. In the Update secrets backends panel, select the Provider: FPT Key Vault or Azure Key Vault.

  6. Fill in the fields of your provider, as described in FPT Key Vault or Azure Key Vault.

  7. Select Test connection to check the connection to the secret backend.

  8. Select Save.

Save stays disabled until you run Test connection. To close the panel without saving, select the close icon. The panel has no Cancel button.

FPT Key Vault​

FieldDescription
Mount pointRequired. The mount point path of the secret backend, for example airflow-connections.
Connection pathRequired. The path or key of the Airflow connections.
Variable pathRequired. The path or key of the variables or secrets.
URLRequired. The endpoint address of the Vault, for example https://<VAULT-HOST>.
Auth typeThe authentication type with the Vault. Fixed to token.
TokenRequired. The token that authenticates with the Vault. The field is masked. The token needs read access to your connections and variables, as described in Give the token read access in Vault.

Azure Key Vault​

With Azure Key Vault, the panel shows these fields.

Update secrets backends panel with Azure Key Vault selected and the Connection prefix, Variable prefix, Vault URL, Tenant ID, Client ID, and Client Secret fields

FieldDescription
Connection prefixThe prefix of the secrets that hold the Airflow connections.
Variable prefixThe prefix of the secrets that hold the Airflow variables.
Vault URLThe URL of the Azure key vault.
Tenant IDThe tenant ID that the service uses to authenticate with the vault.
Client IDThe client ID that the service uses to authenticate with the vault.
Client SecretThe secret of that client. The field is masked.

Give the token read access in Vault​

With FPT Key Vault, the token needs read and list permissions on the paths that hold your connections and variables. Assign a policy to the token, for example the one below. Replace <MOUNT-POINT>, <CONNECTION-PATH>, and <VARIABLE-PATH> with the values that you entered for the secret backend.

{
"path": {
"<MOUNT-POINT>/data/<CONNECTION-PATH>/*": {
"capabilities": ["read", "list"]
},
"<MOUNT-POINT>/data/<VARIABLE-PATH>/*": {
"capabilities": ["read", "list"]
},
"<MOUNT-POINT>/metadata/<CONNECTION-PATH>": {
"capabilities": ["list"]
},
"<MOUNT-POINT>/metadata/<VARIABLE-PATH>": {
"capabilities": ["list"]
}
}
}

Check that a DAG can read a secret​

The test DAG test_vault_secret_backend reads the variable myvar with Variable.get and prints it in the log of its read_secret task. Create the variable myvar in Vault under your variable path, or change the name in the code. Then save the code below as read_vault_be.py.

from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.models import Variable
from datetime import datetime

def read_secret():
secret = Variable.get("myvar")
print(f"Secret from Vault: {secret}")

with DAG(
dag_id="test_vault_secret_backend",
start_date=datetime(2023, 1, 1),
schedule=None,
catchup=False
) as dag:

read_secret_task = PythonOperator(
task_id="read_secret",
python_callable=read_secret
)
  1. Put read_vault_be.py in the dags folder of the S3 storage that the service mounts. If your DAGs come from a Git repository, add the file to the repository instead.
  2. Sign in to the Airflow UI at the URL of the service. See View Orchestration details.
  3. In the left menu, select Dags.
  4. Select the DAG test_vault_secret_backend in the list.
  5. Turn on the DAG toggle if the DAG is off.
  6. Select Trigger.
  7. Open the latest run of the DAG.
  8. Select the read_secret task and view its log.
  9. Check that the log shows the line Secret from Vault: followed by the value of the variable.

Next steps​