Skip to content

Commit 02ef0b0

Browse files
Updated token mounting docs (#4919)
Signed-off-by: Alice Gibbons <[email protected]> Co-authored-by: Marc Duiker <[email protected]>
1 parent 04e0f32 commit 02ef0b0

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

daprdocs/content/en/operations/security/api-token.md

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -52,45 +52,12 @@ annotations:
5252
5353
When deployed, Dapr sidecar injector will automatically create a secret reference and inject the actual value into `DAPR_API_TOKEN` environment variable.
5454

55-
## Rotate a token
56-
57-
### Self-hosted
58-
59-
To rotate the configured token in self-hosted, update the `DAPR_API_TOKEN` environment variable to the new value and restart the `daprd` process.
60-
61-
### Kubernetes
62-
63-
To rotate the configured token in Kubernetes, update the previously-created secret with the new token in each namespace. You can do that using `kubectl patch` command, but a simpler way to update these in each namespace is by using a manifest:
64-
65-
```yaml
66-
apiVersion: v1
67-
kind: Secret
68-
metadata:
69-
name: dapr-api-token
70-
type: Opaque
71-
data:
72-
token: <your-new-token>
73-
```
74-
75-
And then apply it to each namespace:
76-
77-
```shell
78-
kubectl apply --file token-secret.yaml --namespace <namespace-name>
79-
```
80-
81-
To tell Dapr to start using the new token, trigger a rolling upgrade to each one of your deployments:
82-
83-
```shell
84-
kubectl rollout restart deployment/<deployment-name> --namespace <namespace-name>
85-
```
86-
87-
> Assuming your service is configured with more than one replica, the key rotation process does not result in any downtime.
8855

8956
## Adding API token to client API invocations
9057

91-
Once token authentication is configured in Dapr, all clients invoking Dapr API need to append the `dapr-api-token` token to every request.
58+
Once token authentication is configured in Dapr, all clients invoking the Dapr APIs need to append the `dapr-api-token` token to every request.
9259

93-
> **Note:** The Dapr SDKs read the [DAPR_API_TOKEN]({{% ref environment %}}) environment variable and set it for you by default.
60+
> **Note:** The Dapr SDKs read the [DAPR_API_TOKEN]({{% ref environment %}}) environment variable and set it for you by default, however you still must ensure that your app has access to the environment variable.
9461

9562
<img src="/images/tokens-auth.png" width=800 style="padding-bottom:15px;">
9663

@@ -122,15 +89,18 @@ dapr-api-token[0].
12289

12390
### Kubernetes
12491

125-
In Kubernetes, it's recommended to mount the secret to your pod as an environment variable, as shown in the example below, where a Kubernetes secret with the name `dapr-api-token` is used to hold the token.
92+
In Kubernetes, it's required to mount the API token on your application pod as an environment variable, when your application is making outbound calls to the Dapr APIs (Service Invocation invoke, Pub/sub publish, etc.), otherwise the request will fail with an `Unauthorized` error. Mounting the environment variable is done by providing the name of the Kubernetes secret in your application pod specification, as shown in the example below, where a Kubernetes secret with the name `dapr-api-token` is used to hold the token.
12693

12794
```yaml
12895
containers:
12996
- name: mycontainer
13097
image: myregistry/myapp
131-
envFrom:
132-
- secretRef:
133-
name: dapr-api-token
98+
env:
99+
- name: DAPR_API_TOKEN
100+
valueFrom:
101+
secretKeyRef:
102+
name: dapr-api-token
103+
key: token
134104
```
135105

136106
### Self-hosted
@@ -141,6 +111,40 @@ In self-hosted mode, you can set the token as an environment variable for your a
141111
export DAPR_API_TOKEN=<my-dapr-token>
142112
```
143113

114+
## Rotate a token
115+
116+
### Self-hosted
117+
118+
To rotate the configured token in self-hosted, update the `DAPR_API_TOKEN` environment variable to the new value and restart the `daprd` process.
119+
120+
### Kubernetes
121+
122+
To rotate the configured token in Kubernetes, update the previously-created secret with the new token in each namespace. You can do that using `kubectl patch` command, but a simpler way to update these in each namespace is by using a manifest:
123+
124+
```yaml
125+
apiVersion: v1
126+
kind: Secret
127+
metadata:
128+
name: dapr-api-token
129+
type: Opaque
130+
data:
131+
token: <your-new-token>
132+
```
133+
134+
And then apply it to each namespace:
135+
136+
```shell
137+
kubectl apply --file token-secret.yaml --namespace <namespace-name>
138+
```
139+
140+
To tell Dapr to start using the new token, trigger a rolling upgrade to each one of your deployments:
141+
142+
```shell
143+
kubectl rollout restart deployment/<deployment-name> --namespace <namespace-name>
144+
```
145+
146+
> Assuming your service is configured with more than one replica, the key rotation process does not result in any downtime.
147+
144148
## Related Links
145149

146150
- Learn about [Dapr security concepts]({{% ref security-concept.md %}})

0 commit comments

Comments
 (0)