In scenarios such as zero trust networks or when exposing the Dapr sidecar to external traffic through a frontend, it’s recommended to only enable the Dapr sidecar APIs being used by the app. Doing so reduces the attack surface and helps keep the Dapr APIs scoped to the actual needs of the application.
Dapr allows you to control which APIs are accessible to the application by setting an API allowlist or denylist using a Dapr Configuration.
If no API allowlist or denylist is specified, the default behavior is to allow access to all Dapr APIs.
For example, the following configuration enables all APIs for both HTTP and gRPC:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myappconfig
namespace: default
spec:
tracing:
samplingRate: "1"
The following example enables the state v1.0
HTTP API and blocks all other HTTP APIs:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myappconfig
namespace: default
spec:
api:
allowed:
- name: state
version: v1.0
protocol: http
The following example enables the state v1
gRPC API and blocks all other gRPC APIs:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myappconfig
namespace: default
spec:
api:
allowed:
- name: state
version: v1
protocol: grpc
The following example disables the state v1.0
HTTP API, allowing all other HTTP APIs:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myappconfig
namespace: default
spec:
api:
denied:
- name: state
version: v1.0
protocol: http
The following example disables the state v1
gRPC API, allowing all other gRPC APIs:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myappconfig
namespace: default
spec:
api:
denied:
- name: state
version: v1
protocol: grpc
The name
field takes the name of the Dapr API you would like to enable.
See this list of values corresponding to the different Dapr APIs:
API group | HTTP API | gRPC API |
---|---|---|
Service Invocation | invoke (v1.0 ) | invoke (v1 ) |
State | state (v1.0 and v1.0-alpha1 ) | state (v1 and v1alpha1 ) |
Pub/Sub | publish (v1.0 and v1.0-alpha1 ) | publish (v1 and v1alpha1 ) |
Output Bindings | bindings (v1.0 ) | bindings (v1 ) |
Subscribe | n/a | subscribe (v1alpha1 ) |
Secrets | secrets (v1.0 ) | secrets (v1 ) |
Actors | actors (v1.0 ) | actors (v1 ) |
Metadata | metadata (v1.0 ) | metadata (v1 ) |
Configuration | configuration (v1.0 and v1.0-alpha1 ) | configuration (v1 and v1alpha1 ) |
Distributed Lock | lock (v1.0-alpha1 )unlock (v1.0-alpha1 ) | lock (v1alpha1 )unlock (v1alpha1 ) |
Cryptography | crypto (v1.0-alpha1 ) | crypto (v1alpha1 ) |
Workflow | workflows (v1.0 ) | workflows (v1 ) |
Conversation | conversation (v1.0-alpha1 ) | conversation (v1alpha1 ) |
Health | healthz (v1.0 ) | n/a |
Shutdown | shutdown (v1.0 ) | shutdown (v1 ) |