Azure Key Vault secret store

Detailed information on the Azure Key Vault secret store component

Component format

To setup Azure Key Vault secret store create a component of type secretstores.azure.keyvault. See this guide on how to create and apply a secretstore configuration. See this guide on referencing secrets to retrieve and use the secret with Dapr components.

See also configure the component guide in this page.

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

Warning

The above example uses secrets as plain strings. It is recommended to use a local secret store such as Kubernetes secret store or a local file to bootstrap secure key storage.

Authenticating with Azure AD

The Azure Key Vault secret store component supports authentication with Azure AD only. Before you enable this component, make sure you’ve read the Authenticating to Azure document and created an Azure AD application (also called Service Principal). Alternatively, make sure you have created a managed identity for your application platform.

Spec metadata fields

FieldRequiredDetailsExample
vaultNameYThe name of the Azure Key Vault“mykeyvault”
azureEnvironmentNOptional name for the Azure environment if using a different Azure cloud“AZUREPUBLICCLOUD” (default value), “AZURECHINACLOUD”, “AZUREUSGOVERNMENTCLOUD”, “AZUREGERMANCLOUD”

Additionally, you must provide the authentication fields as explained in the Authenticating to Azure document.

Create the Azure Key Vault and authorize the Service Principal

Prerequisites

Make sure you have followed the steps in the Authenticating to Azure document to create an Azure AD application (also called Service Principal). You will need the following values:

  • SERVICE_PRINCIPAL_ID: the ID of the Service Principal that you created for a given application

Steps

  1. Set a variable with the Service Principal that you created:
  1. SERVICE_PRINCIPAL_ID="[your_service_principal_object_id]"
  1. Set a variable with the location where to create all resources:
  1. LOCATION="[your_location]"

(You can get the full list of options with: az account list-locations --output tsv)

  1. Create a Resource Group, giving it any name you’d like:
  1. RG_NAME="[resource_group_name]"
  2. RG_ID=$(az group create \
  3. --name "${RG_NAME}" \
  4. --location "${LOCATION}" \
  5. | jq -r .id)
  1. Create an Azure Key Vault (that uses Azure RBAC for authorization):
  1. KEYVAULT_NAME="[key_vault_name]"
  2. az keyvault create \
  3. --name "${KEYVAULT_NAME}" \
  4. --enable-rbac-authorization true \
  5. --resource-group "${RG_NAME}" \
  6. --location "${LOCATION}"
  1. Using RBAC, assign a role to the Azure AD application so it can access the Key Vault.
    In this case, assign the “Key Vault Crypto Officer” role, which has broad access; other more restrictive roles can be used as well, depending on your application.
  1. az role assignment create \
  2. --assignee "${SERVICE_PRINCIPAL_ID}" \
  3. --role "Key Vault Crypto Officer" \
  4. --scope "${RG_ID}/providers/Microsoft.KeyVault/vaults/${KEYVAULT_NAME}"

Configure the component

To use a client secret, create a file called azurekeyvault.yaml in the components directory, filling in with the Azure AD application that you created following the Authenticating to Azure document:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: azurekeyvault
  5. namespace: default
  6. spec:
  7. type: secretstores.azure.keyvault
  8. version: v1
  9. metadata:
  10. - name: vaultName
  11. value: "[your_keyvault_name]"
  12. - name: azureTenantId
  13. value: "[your_tenant_id]"
  14. - name: azureClientId
  15. value: "[your_client_id]"
  16. - name: azureClientSecret
  17. value : "[your_client_secret]"

If you want to use a certificate saved on the local disk, instead, use this template, filling in with details of the Azure AD application that you created following the Authenticating to Azure document:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: azurekeyvault
  5. namespace: default
  6. spec:
  7. type: secretstores.azure.keyvault
  8. version: v1
  9. metadata:
  10. - name: vaultName
  11. value: "[your_keyvault_name]"
  12. - name: azureTenantId
  13. value: "[your_tenant_id]"
  14. - name: azureClientId
  15. value: "[your_client_id]"
  16. - name: azureCertificateFile
  17. value : "[pfx_certificate_file_fully_qualified_local_path]"

In Kubernetes, you store the client secret or the certificate into the Kubernetes Secret Store and then refer to those in the YAML file. You will need the details of the Azure AD application that was created following the Authenticating to Azure document.

To use a client secret:

  1. Create a Kubernetes secret using the following command:

    1. kubectl create secret generic [your_k8s_secret_name] --from-literal=[your_k8s_secret_key]=[your_client_secret]
    • [your_client_secret] is the application’s client secret as generated above
    • [your_k8s_secret_name] is secret name in the Kubernetes secret store
    • [your_k8s_secret_key] is secret key in the Kubernetes secret store
  2. Create an azurekeyvault.yaml component file.

    The component yaml refers to the Kubernetes secretstore using auth property and secretKeyRef refers to the client secret stored in the Kubernetes secret store.

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: azurekeyvault
    5. namespace: default
    6. spec:
    7. type: secretstores.azure.keyvault
    8. version: v1
    9. metadata:
    10. - name: vaultName
    11. value: "[your_keyvault_name]"
    12. - name: azureTenantId
    13. value: "[your_tenant_id]"
    14. - name: azureClientId
    15. value: "[your_client_id]"
    16. - name: azureClientSecret
    17. secretKeyRef:
    18. name: "[your_k8s_secret_name]"
    19. key: "[your_k8s_secret_key]"
    20. auth:
    21. secretStore: kubernetes
  3. Apply the azurekeyvault.yaml component:

    1. kubectl apply -f azurekeyvault.yaml

To use a certificate:

  1. Create a Kubernetes secret using the following command:

    1. kubectl create secret generic [your_k8s_secret_name] --from-file=[your_k8s_secret_key]=[pfx_certificate_file_fully_qualified_local_path]
    • [pfx_certificate_file_fully_qualified_local_path] is the path of PFX file you obtained earlier
    • [your_k8s_secret_name] is secret name in the Kubernetes secret store
    • [your_k8s_secret_key] is secret key in the Kubernetes secret store
  2. Create an azurekeyvault.yaml component file.

    The component yaml refers to the Kubernetes secretstore using auth property and secretKeyRef refers to the certificate stored in the Kubernetes secret store.

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Component
    3. metadata:
    4. name: azurekeyvault
    5. namespace: default
    6. spec:
    7. type: secretstores.azure.keyvault
    8. version: v1
    9. metadata:
    10. - name: vaultName
    11. value: "[your_keyvault_name]"
    12. - name: azureTenantId
    13. value: "[your_tenant_id]"
    14. - name: azureClientId
    15. value: "[your_client_id]"
    16. - name: azureCertificate
    17. secretKeyRef:
    18. name: "[your_k8s_secret_name]"
    19. key: "[your_k8s_secret_key]"
    20. auth:
    21. secretStore: kubernetes
  3. Apply the azurekeyvault.yaml component:

    1. kubectl apply -f azurekeyvault.yaml

References

Last modified September 20, 2021 : Merge pull request #1800 from greenie-msft/gRPC_proxying_video (36dff3c)