Using access control, you can configure policies that restrict what the operations calling applications can perform, via service invocation, on the called application. You can define an access control policy specification in the Configuration schema to limit access:
An access control policy is specified in Configuration and applied to the Dapr sidecar for the called application. Access to the called app is based on the matched policy action.
You can provide a default global action for all calling applications. If no access control policy is specified, the default behavior is to allow all calling applications to access to the called app.
See examples of access policies.
trustDomain
A “trust domain” is a logical group that manages trust relationships. Every application is assigned a trust domain, which can be specified in the access control list policy spec. If no policy spec is defined or an empty trust domain is specified, then a default value “public” is used. This trust domain is used to generate the identity of the application in the TLS cert.
Dapr requests the sentry service to generate a SPIFFE ID for all applications. This ID is attached in the TLS cert.
The SPIFFE ID is of the format: **spiffe://\<trustdomain>/ns/\<namespace\>/\<appid\>**
.
For matching policies, the trust domain, namespace, and app ID values of the calling app are extracted from the SPIFFE ID in the TLS cert of the calling app. These values are matched against the trust domain, namespace, and app ID values specified in the policy spec. If all three of these match, then more specific policies are further matched.
The following tables lists the different properties for access control, policies, and operations:
Property | Type | Description |
---|---|---|
defaultAction | string | Global default action when no other policy is matched |
trustDomain | string | Trust domain assigned to the application. Default is “public”. |
policies | string | Policies to determine what operations the calling app can do on the called app |
Property | Type | Description |
---|---|---|
app | string | AppId of the calling app to allow/deny service invocation from |
namespace | string | Namespace value that needs to be matched with the namespace of the calling app |
trustDomain | string | Trust domain that needs to be matched with the trust domain of the calling app. Default is “public” |
defaultAction | string | App level default action in case the app is found but no specific operation is matched |
operations | string | operations that are allowed from the calling app |
Property | Type | Description |
---|---|---|
name | string | Path name of the operations allowed on the called app. Wildcard “*” can be used in a path to match. Wildcard “**” can be used to match under multiple paths. |
httpVerb | list | List specific http verbs that can be used by the calling app. Wildcard “*” can be used to match any http verb. Unused for grpc invocation. |
action | string | Access modifier. Accepted values “allow” (default) or “deny” |
The action corresponding to the most specific policy matched takes effect as ordered below:
Below are some example scenarios for using access control list for service invocation. See configuration guidance to understand the available configuration settings for an application sidecar.
Deny access to all apps except where trustDomain
= public
, namespace
= default
, appId
= app1
With this configuration, all calling methods with appId
= app1
are allowed. All other invocation requests from other applications are denied.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: deny
trustDomain: "public"
policies:
- appId: app1
defaultAction: allow
trustDomain: 'public'
namespace: "default"
Deny access to all apps except trustDomain
= public
, namespace
= default
, appId
= app1
, operation
= op1
With this configuration, only the method op1
from appId
= app1
is allowed. All other method requests from all other apps, including other methods on app1
, are denied.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: deny
trustDomain: "public"
policies:
- appId: app1
defaultAction: deny
trustDomain: 'public'
namespace: "default"
operations:
- name: /op1
httpVerb: ['*']
action: allow
Deny access to all apps except when a specific verb for HTTP and operation for GRPC is matched
With this configuration, only the scenarios below are allowed access. All other method requests from all other apps, including other methods on app1
or app2
, are denied.
trustDomain
= public
, namespace
= default
, appID
= app1
, operation
= op1
, httpVerb
= POST
/PUT
trustDomain
= "myDomain"
, namespace
= "ns1"
, appID
= app2
, operation
= op2
and application protocol is GRPCOnly the httpVerb
POST
/PUT
on method op1
from appId
= app1
are allowe. All other method requests from all other apps, including other methods on app1
, are denied.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: deny
trustDomain: "public"
policies:
- appId: app1
defaultAction: deny
trustDomain: 'public'
namespace: "default"
operations:
- name: /op1
httpVerb: ['POST', 'PUT']
action: allow
- appId: app2
defaultAction: deny
trustDomain: 'myDomain'
namespace: "ns1"
operations:
- name: /op2
action: allow
Allow access to all methods except trustDomain
= public
, namespace
= default
, appId
= app1
, operation
= /op1/*
, all httpVerb
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: allow
trustDomain: "public"
policies:
- appId: app1
defaultAction: allow
trustDomain: 'public'
namespace: "default"
operations:
- name: /op1/*
httpVerb: ['*']
action: deny
Allow access to all methods for trustDomain
= public
, namespace
= ns1
, appId
= app1
and deny access to all methods for trustDomain
= public
, namespace
= ns2
, appId
= app1
This scenario shows how applications with the same app ID while belonging to different namespaces can be specified.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: allow
trustDomain: "public"
policies:
- appId: app1
defaultAction: allow
trustDomain: 'public'
namespace: "ns1"
- appId: app1
defaultAction: deny
trustDomain: 'public'
namespace: "ns2"
Allow access to all methods except trustDomain
= public
, namespace
= default
, appId
= app1
, operation
= /op1/**/a
, all httpVerb
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
accessControl:
defaultAction: allow
trustDomain: "public"
policies:
- appId: app1
defaultAction: allow
trustDomain: 'public'
namespace: "default"
operations:
- name: /op1/**/a
httpVerb: ['*']
action: deny
In these examples, you learn how to apply access control to the hello world tutorials.
Access control lists rely on the Dapr Sentry service to generate the TLS certificates with a SPIFFE ID for authentication. This means the Sentry service either has to be running locally or deployed to your hosting environment, such as a Kubernetes cluster.
The nodeappconfig
example below shows how to deny access to the neworder
method from the pythonapp
, where the Python app is in the myDomain
trust domain and default
namespace. The Node.js app is in the public
trust domain.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: nodeappconfig
spec:
tracing:
samplingRate: "1"
accessControl:
defaultAction: allow
trustDomain: "public"
policies:
- appId: pythonapp
defaultAction: allow
trustDomain: 'myDomain'
namespace: "default"
operations:
- name: /neworder
httpVerb: ['POST']
action: deny
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: pythonappconfig
spec:
tracing:
samplingRate: "1"
accessControl:
defaultAction: allow
trustDomain: "myDomain"
When walking through this tutorial, you:
In a command prompt, set these environment variables:
```bash
export DAPR_TRUST_ANCHORS=`cat $HOME/.dapr/certs/ca.crt`
export DAPR_CERT_CHAIN=`cat $HOME/.dapr/certs/issuer.crt`
export DAPR_CERT_KEY=`cat $HOME/.dapr/certs/issuer.key`
export NAMESPACE=default
```
```powershell
$env:DAPR_TRUST_ANCHORS=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\ca.crt)
$env:DAPR_CERT_CHAIN=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\issuer.crt)
$env:DAPR_CERT_KEY=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\issuer.key)
$env:NAMESPACE="default"
```
Run daprd to launch a Dapr sidecar for the Node.js app with mTLS enabled, referencing the local Sentry service:
daprd --app-id nodeapp --dapr-grpc-port 50002 -dapr-http-port 3501 --log-level debug --app-port 3000 --enable-mtls --sentry-address localhost:50001 --config nodeappconfig.yaml
Run the Node.js app in a separate command prompt:
node app.js
In another command prompt, set these environment variables:
```bash
export DAPR_TRUST_ANCHORS=`cat $HOME/.dapr/certs/ca.crt`
export DAPR_CERT_CHAIN=`cat $HOME/.dapr/certs/issuer.crt`
export DAPR_CERT_KEY=`cat $HOME/.dapr/certs/issuer.key`
export NAMESPACE=default
$env:DAPR_TRUST_ANCHORS=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\ca.crt)
$env:DAPR_CERT_CHAIN=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\issuer.crt)
$env:DAPR_CERT_KEY=$(Get-Content -raw $env:USERPROFILE\.dapr\certs\issuer.key)
$env:NAMESPACE="default"
Run daprd to launch a Dapr sidecar for the Python app with mTLS enabled, referencing the local Sentry service:
daprd --app-id pythonapp --dapr-grpc-port 50003 --metrics-port 9092 --log-level debug --enable-mtls --sentry-address localhost:50001 --config pythonappconfig.yaml
Run the Python app in a separate command prompt:
python app.py
You should see the calls to the Node.js app fail in the Python app command prompt, due to the deny operation action in the nodeappconfig
file. Change this action to allow and re-run the apps to see this call succeed.
You can create and apply the above nodeappconfig.yaml
and pythonappconfig.yaml
configuration files, as described in the configuration.
For example, the Kubernetes Deployment below is how the Python app is deployed to Kubernetes in the default namespace with this pythonappconfig
configuration file.
Do the same for the Node.js deployment and look at the logs for the Python app to see the calls fail due to the deny operation action set in the nodeappconfig
file.
Change this action to allow and re-deploy the apps to see this call succeed.
apiVersion: apps/v1
kind: Deployment
metadata:
name: pythonapp
namespace: default
labels:
app: python
spec:
replicas: 1
selector:
matchLabels:
app: python
template:
metadata:
labels:
app: python
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "pythonapp"
dapr.io/config: "pythonappconfig"
spec:
containers:
- name: python
image: dapriosamples/hello-k8s-python:edge
Watch this video on how to apply access control list for service invocation.