Azure Key Vault 后端¶
要将 Azure Key Vault 用作 secrets 后端,请在 airflow.cfg
文件的 [secrets]
部分中,将 backend
指定为 AzureKeyVaultBackend
。
以下是配置示例
[secrets]
backend = airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend
backend_kwargs = {"connections_prefix": "airflow-connections", "variables_prefix": "airflow-variables", "vault_url": "https://example-akv-resource-name.vault.azure.net/"}
对于客户端身份验证,使用来自 Azure Python SDK 的 DefaultAzureCredential
作为凭据提供者,它支持服务主体、托管标识和用户凭据。
例如,要指定带密钥的服务主体,可以设置环境变量 AZURE_TENANT_ID
、AZURE_CLIENT_ID
和 AZURE_CLIENT_SECRET
。
可选查找¶
可选地,连接、变量或配置可以相互独立地查找,或以任意组合方式查找。这将阻止向 Azure Key Vault 发送被排除类型的请求。
如果您只想在 Azure Key Vault 中查找部分内容而不是全部,可以将要排除内容的相应 *_prefix
参数设置为 null
。
例如,如果您想将参数 connections_prefix
设置为 "airflow-connections"
并且不查找变量,您的配置文件应如下所示:
[secrets]
backend = airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend
backend_kwargs = {"connections_prefix": "airflow-connections", "variables_prefix": null, "vault_url": "https://example-akv-resource-name.vault.azure.net/"}
存储和检索连接¶
如果您将 connections_prefix
设置为 airflow-connections
,那么对于连接 ID 为 smtp_default
的连接,您需要将其存储在 airflow-connections-smtp-default
。
该机密的值必须是连接对象的连接 URI 表示形式。
存储和检索变量¶
如果您将 variables_prefix
设置为 airflow-variables
,那么对于变量键为 hello
的变量,您需要将其存储在 airflow-variables-hello
。
身份验证¶
有 3 种方式对 Azure Key Vault 后端进行身份验证。
设置
tenant_id
、client_id
、client_secret
(使用 ClientSecretCredential)设置
managed_identity_client_id
、workload_identity_tenant_id
(使用带这些参数的 DefaultAzureCredential)不提供额外的连接配置,以便回退到 DefaultAzureCredential
参考¶
有关客户端身份验证的更多详细信息,请参阅DefaultAzureCredential 类参考。