透過管理的身份或 Azure Key Vault 秘密儲存庫,安全地建立與 Azure 及非 Microsoft 服務的 Dapr 元件的連線。
在開始之前,先了解 DAPR 元件所提供的支援。
建議
為了獲得最安全的連線,我們建議盡可能使用提供管理身份支援的 Azure 元件。 當管理身份驗證不支援時,僅使用 Azure Key Vault 機密儲存庫。
| 服務類型 | 建議 |
|---|---|
| 具有管理識別支援的 Azure 元件 | 使用受控識別流程 (建議) |
| 不支援受控身分的 Azure 元件 | 使用Azure Key Vault秘密儲存 |
| 非 Azure 元件 | 使用Azure Key Vault秘密儲存 |
使用管理式身份(建議)
針對 Azure 託管服務,Dapr 可使用範圍限定容器應用程式的受控身分識別,向後端服務提供者進行驗證。 使用受控識別時,您不需要在元件資訊清單中包含祕密資訊。 建議使用受管理的身份,因為它可以排除在元件中儲存敏感性輸入,且不需要管理秘密存放區。
備註
針對利用使用者指派的受控識別進行驗證的任何元件,azureClientId 中繼資料欄位 (受控識別的用戶端識別碼) 為必要欄位。
使用 Dapr 祕密存放區元件參考
當你為未啟用 Entra ID 的服務或不支援管理身份驗證的元件建立 Dapr 元件時,某些元資料欄位需要敏感的輸入值。 針對此方法,參考可安全地存取秘密資訊的現有 Dapr 秘密存放區元件,以擷取這些秘密。
若要建立參考:
- 使用 Azure 容器應用程式 架構建立一個 Dapr 秘密儲存元件。 所有支援的 Dapr 祕密存放區的元件類型都是以
secretstores開頭。 - 建立額外元件 (視需要) 以參考您建立的 Dapr 祕密存放區元件,來擷取敏感的中繼資料輸入。
建立 Dapr 秘密存放區元件
在 Azure 容器應用程式 建立秘密儲存元件時,你可以在元資料區塊中提供敏感資訊,以下任一方式:
- 對於 Azure Key Vault 秘密儲存,請使用管理身份來建立連線。
- 對於非 Azure 秘密儲存庫,請使用平台管理的 Kubernetes 秘密,直接作為元件清單的一部分定義。
Azure Key Vault 秘密存儲
以下元件架構展示了使用 Azure Key Vault 秘密儲存庫的最簡單設定。
publisher-app 和 subscriber-app 都設定為同時擁有系統或使用者指派的管理身份,並對Azure Key Vault實例擁有適當的權限。
componentType: secretstores.azure.keyvault
version: v1
metadata:
- name: vaultName
value: [your_keyvault_name]
- name: azureEnvironment
value: "AZUREPUBLICCLOUD"
- name: azureClientId # Only required for authenticating user-assigned managed identity
value: [your_managed_identity_client_id]
scopes:
- publisher-app
- subscriber-app
平台管理的 Kubernetes 密鑰
作為 Kubernetes 秘密、本地環境變數及本地檔案 Dapr 秘密儲存的替代方案,Azure 容器應用程式 提供一種平台管理方式來建立及使用 Kubernetes 秘密。 此方法可用於連接非 Azure 服務。 或者在開發或測試場景中,它也能透過 CLI 快速部署元件,無需設置秘密儲存或管理身份。
此元件設定會將敏感性值定義為可從中繼資料區段參考的祕密參數。
componentType: secretstores.azure.keyvault
version: v1
metadata:
- name: vaultName
value: [your_keyvault_name]
- name: azureEnvironment
value: "AZUREPUBLICCLOUD"
- name: azureTenantId
value: "[your_tenant_id]"
- name: azureClientId
value: "[your_client_id]"
- name: azureClientSecret
secretRef: azClientSecret
secrets:
- name: azClientSecret
value: "[your_client_secret]"
scopes:
- publisher-app
- subscriber-app
參考 Dapr 祕密存放區元件
使用上述其中一種方法建立 Dapr 祕密存放區之後,您可以從相同環境中的其他 Dapr 元件參考該祕密存放區。 以下範例示範使用 Microsoft Entra ID 認證。
componentType: pubsub.azure.servicebus.queue
version: v1
secretStoreComponent: "[your_secret_store_name]"
metadata:
- name: namespaceName
# Required when using Azure Authentication.
# Must be a fully-qualified domain name
value: "[your_servicebus_namespace.servicebus.windows.net]"
- name: azureTenantId
value: "[your_tenant_id]"
- name: azureClientId
value: "[your_client_id]"
- name: azureClientSecret
secretRef: azClientSecret
scopes:
- publisher-app
- subscriber-app