Skip to content

Commit cd24d6b

Browse files
LucasRoesleralexellis
authored andcommitted
Clean up language and add a failed invoke example
**What** - Some minor language tweaks - Add an example of the invoke failing because the header value is incorrect Signed-off-by: Lucas Roesler <[email protected]>
1 parent 571bdc2 commit cd24d6b

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

docs/reference/secrets.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ This page shows how to use secrets within your functions for API tokens, passwor
44

55
Using secrets is a two step process. First we need to define the secret in your cluster and then you need to 'use' the secret to your function. You can find a simple example function [ApiKeyProtected in the OpenFaaS repo](https://github.com/openfaas/faas/tree/master/sample-functions/ApiKeyProtected-Secrets). When we deploy this function we provide a secret key that it uses to authenticate requests.
66

7-
_Note_: The examples in the following section require `faas-cli` version `>=0.5.1`
8-
97
## Creating the secret
108

119
It is generally easiest to read your secret values from files. For our examples we have created a simple text file `~/secrets/secret_api_key.txt` that looks like
@@ -40,26 +38,44 @@ docker secret create secret_api_key ~/secrets/secret_api_key.txt
4038

4139
## Use the secret in your function
4240

43-
This is the simplest part, update your stack file to include the secret:
41+
Now, update your stack file to include the secret:
4442

45-
```yaml
46-
provider:
47-
name: faas
48-
gateway: http://localhost:8080
43+
```yaml
44+
provider:
45+
name: faas
46+
gateway: http://localhost:8080
4947

50-
functions:
51-
protectedapi:
52-
lang: Dockerfile
53-
skip_build: true
54-
image: functions/api-key-protected:latest
55-
secrets:
56-
- secret_api_key
57-
```
48+
functions:
49+
protectedapi:
50+
lang: Dockerfile
51+
skip_build: true
52+
image: functions/api-key-protected:latest
53+
secrets:
54+
- secret_api_key
55+
```
5856
5957
and then deploy `faas-cli deploy -f ./stack.yaml`
6058

61-
Once the deploy is done you can test the function using
59+
Once the deploy is done you can test the function using the cli. The function is very simply, it reads the secret value that is mounted into the container for you and then returns a success or failure message based on if your header matches that secret value. For example,
6260

6361
```sh
6462
faas-cli invoke protectedapi -H "X-Api-Key=R^YqzKzSJw51K9zPpQ3R3N"
6563
```
64+
65+
Resulting in
66+
67+
```txt
68+
Unlocked the function!
69+
```
70+
71+
When you use the wrong api key,
72+
73+
```sh
74+
faas-cli invoke protectedapi -H "X-Api-Key=thisiswrong"
75+
```
76+
77+
You get
78+
79+
```txt
80+
Access denied!
81+
```

0 commit comments

Comments
 (0)