airflow.providers.microsoft.azure.secrets.key_vault

此模組包含 Azure Key Vault 後端。

模組內容

類別

AzureKeyVaultBackend

從 Azure Key Vault 密鑰中檢索 Airflow 連線或變數。

class airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend(connections_prefix='airflow-connections', variables_prefix='airflow-variables', config_prefix='airflow-config', vault_url='', sep='-', *, tenant_id='', client_id='', client_secret='', managed_identity_client_id='', workload_identity_tenant_id='', **kwargs)[原始碼]

基底: airflow.secrets.BaseSecretsBackendairflow.utils.log.logging_mixin.LoggingMixin

從 Azure Key Vault 密鑰中檢索 Airflow 連線或變數。

Azure Key Vault 可以設定為 airflow.cfg 中的密鑰後端

[secrets]
backend = airflow.providers.microsoft.azure.secrets.key_vault.AzureKeyVaultBackend
backend_kwargs = {"connections_prefix": "airflow-connections", "vault_url": "<azure_key_vault_uri>"}

例如,如果密鑰前綴為 airflow-connections-smtp-default,如果您提供 {"connections_prefix": "airflow-connections"} 並請求 conn_id smtp-default,則可以存取此密鑰。如果變數前綴為 airflow-variables-hello,如果您提供 {"variables_prefix": "airflow-variables"} 並請求變數金鑰 hello,則可以存取此變數。

對於用戶端驗證,Azure Python SDK 中的 DefaultAzureCredential 用作憑證提供者,它支援服務主體、受控身分和使用者憑證

例如,若要指定具有密碼的服務主體,您可以設定環境變數 AZURE_TENANT_IDAZURE_CLIENT_IDAZURE_CLIENT_SECRET

另請參閱

如需用戶端驗證的詳細資訊,請參閱 DefaultAzureCredential 類別參考: https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python

參數
  • connections_prefix (str) – 指定要讀取以取得連線的密鑰前綴。如果設定為 None (null),則不會將連線請求傳送至 Azure Key Vault

  • variables_prefix (str) – 指定要讀取以取得變數的密鑰前綴。如果設定為 None (null),則不會將變數請求傳送至 Azure Key Vault

  • config_prefix (str) – 指定要讀取以取得變數的密鑰前綴。如果設定為 None (null),則不會將組態請求傳送至 Azure Key Vault

  • vault_url (str) – 要使用的 Azure Key Vault 的 URL

  • sep (str) – 用於串連 secret_prefix 和 secret_id 的分隔符號。預設值:「-」

  • tenant_id (str) – 要使用的 Azure Key Vault 的租用戶識別碼。如果未提供,則會回退到 DefaultAzureCredential

  • client_id (str) – 要使用的 Azure Key Vault 的用戶端識別碼。如果未提供,則會回退到 DefaultAzureCredential

  • managed_identity_client_id (str) – 使用者指派受控身分的用戶端識別碼。如果與 workload_identity_tenant_id 一起提供,它們將傳遞至 DefaultAzureCredential

  • workload_identity_tenant_id (str) – 應用程式 Microsoft Entra 租用戶的識別碼。也稱為其「目錄」識別碼。如果與 managed_identity_client_id 一起提供,它們將傳遞至 DefaultAzureCredential

client()[原始碼]

建立 Azure Key Vault 用戶端。

get_conn_value(conn_id)[原始碼]

從 Azure Key Vault 密鑰取得 Airflow 連線的序列化表示。

參數

conn_id (str) – 要檢索的 Airflow 連線識別碼

get_variable(key)[原始碼]

從 Azure Key Vault 密鑰取得 Airflow 變數。

參數

key (str) – 變數金鑰

傳回

變數值

傳回類型

str | None

get_config(key)[原始碼]

取得 Airflow 組態。

參數

key (str) – 組態選項金鑰

傳回

組態選項值

傳回類型

str | None

static build_path(path_prefix, secret_id, sep='-')[原始碼]

給定 path_prefix 和 secret_id,為 Azure Key Vault 後端建立有效的密鑰名稱。

也將路徑中的底線取代為破折號,以支援環境變數之間的輕鬆切換,因此 connection_default 變為 connection-default

參數
  • path_prefix (str) – 要檢索的密鑰的路徑前綴

  • secret_id (str) – 密鑰名稱

  • sep (str) – 用於串連 path_prefix 和 secret_id 的分隔符號

這個條目是否有幫助?