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 |
---|---|---|---|
vaultName | Y | Azure Key Vault名称 | “mykeyvault” |
spnTenantId | Y | Service Principal Tenant Id | “spnTenantId” |
spnClientId | Y | Service Principal App Id | “spnAppId” |
spnCertificate | Y | PKCS 12 encoded bytes of the certificate. See for details on encoding this in a Kubernetes secret. | secretKeyRef: … See configure the component for more information. |
登录到 Azure 并设置默认订阅
# Log in Azure
az login
# Set your subscription to the default subscription
在一个区域中创建 Azure Key Vault
az keyvault create --location [region] --name [your_keyvault] --resource-group [your resource group]
创建一个服务主体
Save both the appId and tenant from the output which will be used in the next step
获取 [your_service_principal_name] 的对象ID
{
...
"objectId": "[your_service_principal_object_id]",
"objectType": "ServicePrincipal",
...
}
授予服务主体对你的 Azure Key Vault 的 GET 权限
az keyvault set-policy --name [your_keyvault] --object-id [your_service_principal_object_id] --secret-permissions get
现在,你的服务主体已经可以访问你的keyvault,你可以配置密钥仓库组件,以使用存储在keyvault中的密钥来安全地访问其他组件。
使用 Azure 门户或 Azure CLI 从 Azure Key Vault 下载 PFX 格式的证书:
使用 Azure 门户:
转到 Azure 门户上的密钥库,然后导航到 Certificates标签下的 Settings。 找到服务主体创建时创建的证书,命名为[certificate_name],点击它。
使用 Azure CLI:
将下载的 PFX 证书从 Azure Keyvault 复制到你的组件目录或本地磁盘上的安全位置。
在组件目录下创建一个名为
azurekeyvault.yaml
的文件apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: azurekeyvault
namespace: default
spec:
metadata:
- name: vaultName
value: [your_keyvault_name]
- name: spnTenantId
value: "[your_service_principal_tenant_id]"
- name: spnClientId
value: "[your_service_principal_app_id]"
- name: spnCertificateFile
value : "[pfx_certificate_file_fully_qualified_local_path]"
在元数据字段中填写上述设置过程中密钥库的详细信息。
在Kubernetes中,将服务主体的证书存储到Kubernetes Secret Store中,然后用Kubernetes secretstore中的这个证书启用Azure Key Vault密钥仓库。
使用以下命令创建一个kubernetes密钥:
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
- 创建一个
azurekeyvault.yaml
组件文件
组件yaml使用auth
属性引用Kubernetes secretstore,secretKeyRef
引用存储在Kubernetes secret store中的证书。
- 应用组件
kubectl apply -f azurekeyvault.yaml