Azure Key Vault 密钥仓库

Note

Azure Managed Identity 可用于 Kubernetes 上的 Azure Key Vault 访问, 在 查看说明。 Instructions here.

要设置Azure Key Vault密钥仓库,请创建一个类型为的组件。 See on how to create and apply a secretstore configuration. See this guide on referencing secrets to retrieve and use the secret with Dapr components.

也请参见本页面中的指南。

Warning

以上示例将密钥明文存储, It is recommended to use a local secret store such as or a local file to bootstrap secure key storage.

字段必填详情Example
vaultNameYAzure Key Vault名称“mykeyvault”
spnTenantIdYService Principal Tenant Id“spnTenantId”
spnClientIdYService Principal App Id“spnAppId”
spnCertificateYPKCS 12 encoded bytes of the certificate. See for details on encoding this in a Kubernetes secret.secretKeyRef: …
See configure the component for more information.
  1. 登录到 Azure 并设置默认订阅

    1. # Log in Azure
    2. az login
    3. # Set your subscription to the default subscription
  2. 在一个区域中创建 Azure Key Vault

    1. az keyvault create --location [region] --name [your_keyvault] --resource-group [your resource group]
  3. 创建一个服务主体

    Save both the appId and tenant from the output which will be used in the next step

  4. 获取 [your_service_principal_name] 的对象ID

    1. {
    2. ...
    3. "objectId": "[your_service_principal_object_id]",
    4. "objectType": "ServicePrincipal",
    5. ...
    6. }
  5. 授予服务主体对你的 Azure Key Vault 的 GET 权限

    1. az keyvault set-policy --name [your_keyvault] --object-id [your_service_principal_object_id] --secret-permissions get

    现在,你的服务主体已经可以访问你的keyvault,你可以配置密钥仓库组件,以使用存储在keyvault中的密钥来安全地访问其他组件。

  6. 使用 Azure 门户或 Azure CLI 从 Azure Key Vault 下载 PFX 格式的证书:

  • 使用 Azure 门户:

    转到 Azure 门户上的密钥库,然后导航到 Certificates标签下的 Settings。 找到服务主体创建时创建的证书,命名为[certificate_name],点击它。

  • 使用 Azure CLI:

  1. 将下载的 PFX 证书从 Azure Keyvault 复制到你的组件目录或本地磁盘上的安全位置。

  2. 在组件目录下创建一个名为azurekeyvault.yaml的文件

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: azurekeyvault
    5. namespace: default
    6. spec:
    7. metadata:
    8. - name: vaultName
    9. value: [your_keyvault_name]
    10. - name: spnTenantId
    11. value: "[your_service_principal_tenant_id]"
    12. - name: spnClientId
    13. value: "[your_service_principal_app_id]"
    14. - name: spnCertificateFile
    15. value : "[pfx_certificate_file_fully_qualified_local_path]"

在元数据字段中填写上述设置过程中密钥库的详细信息。

在Kubernetes中,将服务主体的证书存储到Kubernetes Secret Store中,然后用Kubernetes secretstore中的这个证书启用Azure Key Vault密钥仓库。

  1. 使用以下命令创建一个kubernetes密钥:

    1. kubectl create secret generic [your_k8s_spn_secret_name] --from-file=[your_k8s_spn_secret_key]=[pfx_certificate_file_fully_qualified_local_path]
  • [pfx_certificate_file_fully_qualified_local_path]是你在上面下载的PFX证书文件的路径
  • [your_k8s_spn_secret_name]是Kubernetes密钥仓库中的密钥名称
  • [your_k8s_spn_secret_key] is secret key in Kubernetes secret store
  1. 创建一个azurekeyvault.yaml组件文件

组件yaml使用auth属性引用Kubernetes secretstore,secretKeyRef引用存储在Kubernetes secret store中的证书。

  1. 应用组件
  1. kubectl apply -f azurekeyvault.yaml