Azure Key Vault secret store

Note

Azure Managed Identity can be used for Azure Key Vault access on Kubernetes. Instructions .

  1. Login to Azure and set the default subscription

  2. Create an Azure Key Vault in a region

  3. Create a service principal

    Create a service principal with a new certificate and store the 1-year certificate inside your keyvault’s certificate vault. You can skip this step if you want to use an existing service principal for keyvault instead of creating new one

    1. az ad sp create-for-rbac --name [your_service_principal_name] --create-cert --cert [certificate_name] --keyvault [your_keyvault] --skip-assignment --years 1
    2. {
    3. "appId": "a4f90000-0000-0000-0000-00000011d000",
    4. "displayName": "[your_service_principal_name]",
    5. "name": "http://[your_service_principal_name]",
    6. "password": null,
    7. "tenant": "34f90000-0000-0000-0000-00000011d000"
    8. }

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

  4. Grant the service principal the GET permission to your Azure Key Vault

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

    Now that your service principal has access to your keyvault you are ready to configure the secret store component to use secrets stored in your keyvault to access other components securely.

  5. Download the certificate in PFX format from your Azure Key Vault either using the Azure portal or the Azure CLI:

  • Using the Azure portal:

    Go to your key vault on the Azure portal and navigate to the Certificates tab under Settings. Find the certificate that was created during the service principal creation, named [certificate_name] and click on it.

    Click Download in PFX/PEM format to download the certificate.

    1. az keyvault secret download --vault-name [your_keyvault] --name [certificate_name] --encoding base64 --file [certificate_name].pfx
  1. Copy downloaded PFX cert from your Azure Keyvault into your components directory or a secure location on your local disk

  2. Create a file called azurekeyvault.yaml in the components directory

Fill in the metadata fields with your Key Vault details from the above setup process.

In Kubernetes mode, you store the certificate for the service principal into the Kubernetes Secret Store and then enable Azure Key Vault secret store with this certificate in Kubernetes secretstore.

  1. Create a kubernetes secret using the following command:

  • [pfx_certificate_file_local_path] is the path of PFX cert file you downloaded above
  • [your_k8s_spn_secret_name] is secret name in Kubernetes secret store
  1. Create a azurekeyvault.yaml component file

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

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: azurekeyvault
  5. namespace: default
  6. type: secretstores.azure.keyvault
  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: spnCertificate
  15. secretKeyRef:
  16. name: [your_k8s_spn_secret_name]
  17. key: [pfx_certificate_file_local_name]
  18. auth:
  1. Apply azurekeyvault.yaml component