Secrets management overview

Overview of secrets management API building block

Applications usually store sensitive information in secrets by using a dedicated secret store. For example, you authenticate databases, services, and external systems with connection strings, keys, tokens, and other application-level secrets stored in a secret store, such as AWS Secrets Manager, Azure Key Vault, Hashicorp Vault, etc.

To access these secret stores, the application imports the secret store SDK, often requiring a fair amount of unrelated boilerplate code. This poses an even greater challenge in multi-cloud scenarios, where different vendor-specific secret stores may be used.

Secrets management API

Dapr’s dedicated secrets building block API makes it easier for developers to consume application secrets from a secret store. To use Dapr’s secret store building block, you:

  1. Set up a component for a specific secret store solution.
  2. Retrieve secrets using the Dapr secrets API in the application code.
  3. Optionally, reference secrets in Dapr component files.

The following overview video and demo demonstrates how Dapr secrets management works.

Features

The secrets management API building block brings several features to your application.

Configure secrets without changing application code

You can call the secrets API in your application code to retrieve and use secrets from Dapr supported secret stores. Watch this video for an example of how the secrets management API can be used in your application.

For example, the diagram below shows an application requesting the secret called “mysecret” from a secret store called “vault” from a configured cloud secret store.

A service getting a secret from a configured cloud secret store through its Dapr sidecarOn the left, a green hexagon named App. A line with a head at each end joins it to a hexagon carrying the Dapr logo, named Dapr sidecar. A second such line joins the sidecar to a dashed area captioned Cloud secret stores, which holds the marks and names of four stores in two columns: AWS Secrets Manager, Azure Key Vault, Google Key Management and HashiCorp Vault. Below the service and its sidecar is a card holding the exchange between them: GET over the path /v1.0/secrets/vault/mysecret, and under it the value that comes back, mysecret "supersecret".AppDapr sidecarCloud secret storesAWS SecretsManagerAzureKey VaultGoogle KeyManagementHashiCorpVaultGET/v1.0/secrets/vault/mysecret

Applications can also use the secrets API to access secrets from a Kubernetes secret store. By default, Dapr enables a built-in Kubernetes secret store in Kubernetes mode, deployed via:

  • The Helm defaults, or
  • dapr init -k

If you are using another secret store, you can disable (not configure) the Dapr Kubernetes secret store by adding the annotation dapr.io/disable-builtin-k8s-secret-store: "true" to the deployment.yaml file. The default is false.

In the example below, the application retrieves the same secret “mysecret” from a Kubernetes secret store.

A service in a Kubernetes pod getting a secret from the built-in Kubernetes secret storeA dashed region captioned Kubernetes cluster. Inside it on the left, a dashed pod holds a green hexagon named App joined by a line with a head at each end to a hexagon carrying the Dapr logo, named Dapr sidecar. To the right of the pod, still inside the cluster, is the Kubernetes mark named Kubernetes secret store, joined to the sidecar by another line with a head at each end. Below the cluster is a card holding the exchange: GET over the path /v1.0/secrets/kubernetes/mysecret, and under it the value that comes back, mysecret "supersecret".Kubernetes clusterPodAppDapr sidecarKubernetessecret storeGET/v1.0/secrets/kubernetes/mysecret

In Azure, you can configure Dapr to retrieve secrets using managed identities to authenticate with Azure Key Vault. In the example below:

  1. An Azure Kubernetes Service (AKS) cluster is configured to use managed identities.
  2. Dapr uses pod identities to retrieve secrets from Azure Key Vault on behalf of the application.
A service in an AKS pod getting a secret from Azure Key Vault using a pod managed identityA dashed region captioned AKS cluster. Inside it, a dashed pod holds a green hexagon named App joined by a line with a head at each end to a hexagon carrying the Dapr logo, named Dapr sidecar. Under the sidecar, still inside the pod, is a box named Pod managed identity, joined to the sidecar. Outside the cluster on the right is the Azure Key Vault mark, named Azure Key Vault, joined to the sidecar by a line with a head at each end. Below the cluster is a card holding the exchange: GET over the path /v1.0/secrets/vault/mysecret, and under it the value that comes back, mysecret "supersecret".AKS clusterPodAppDapr sidecarPod managed identityAzureKey VaultGET/v1.0/secrets/vault/mysecret

In the examples above, the application code did not have to change to get the same secret. Dapr uses the secret management components via the secrets management building block API.

Try out the secrets API using one of our quickstarts or tutorials.

Reference secret stores in Dapr components

When configuring Dapr components such as state stores, you’re often required to include credentials in components files. Alternatively, you can place the credentials within a Dapr supported secret store and reference the secret within the Dapr component. This is the preferred approach and recommended best practice, especially in production environments.

When running in Kubernetes and referencing secrets from the built-in Kubernetes secret store, Dapr also automatically reloads components when the referenced secret values change, for example when a credential is rotated, without restarting the application. This is enabled by default using the hot reloading feature.

For more information, read referencing secret stores in components and updating referenced secrets.

Limit access to secrets

To provide more granular control on access to secrets, Dapr provides the ability to define scopes and restricting access permissions. Learn more about using secret scoping

Try out secrets management

Dapr University · Free self-paced track

Learn secrets management hands-on. Work through the secrets management API in a free lab that runs in your browser, with nothing to install.

Dapr Secrets

Read secrets through the Dapr Secrets API, see an app refused by secret scoping, then swap to HashiCorp Vault without touching your code.

Explore the free track

Quickstarts and tutorials

Want to put the Dapr secrets management API to the test? Walk through the following quickstart and tutorials to see Dapr secrets in action:

Quickstart/tutorialDescription
Secrets management quickstartRetrieve secrets in the application code from a configured secret store using the secrets management API.
Secret Store tutorialDemonstrates the use of Dapr Secrets API to access secret stores.

Start managing secrets directly in your app

Want to skip the quickstarts? Not a problem. You can try out the secret management building block directly in your application to retrieve and manage secrets. After Dapr is installed, you can begin using the secrets management API starting with the secrets how-to guide.

Next steps