Skip to content

Commit 3e0eb46

Browse files
LucasRoesleralexellis
authored andcommitted
Update refernce documentation for secrets
**What** - Add notes and describe how to read secrets from files in openfaas - Add a final note to the end of the authentication refernce directing people to the `secrets` reference. **Why** - This improves the walk-through and makes it clear how to write a function that uses secrets _and_ how to deploy it Signed-off-by: Lucas Roesler <[email protected]>
1 parent 7f4efe7 commit 3e0eb46

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/reference/authentication.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ Functions are exposed at:
2525

2626
Functions exposed on OpenFaaS often do not need to have authentication enabled, this is because they may be responding to webhooks from an external system such as GitHub or Patreon. Neither GitHub, nor Patreon will support authenticating with OAuth or basic authentication strategies, but rely on HMAC.
2727

28-
HMAC involves a shared symmetric secret - both parties store the key securely. The sender computes a hash of the body of the request with their symmetric key and sends this data to the receiver along with the has value in the HTTP header. The receiver then computes a hash of the body with their copy of the key and checks that this matches what the sender supplied in the HTTP header.
29-
28+
HMAC involves a shared symmetric secret - both parties store the key securely. The sender computes a hash of the body of the request with their symmetric key and sends this data to the receiver along with the has value in the HTTP header. The receiver then computes a hash of the body with their copy of the key and checks that this matches what the sender supplied in the HTTP header. See the reference on [secrets](./secrets.md) for a walk-through on using secret values with functions.

docs/reference/secrets.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ docker secret create secret-api-key ~/secrets/secret_api_key.txt
3838

3939
## Use the secret in your function
4040

41+
Secrets are mounted as files to `/var/openfaas/secrets` inside your function. Using secrets is as simple as adding code to read the value from `/var/openfaas/secrets/secret-api-key`.
42+
43+
_Note_: prior to version `0.8.2` secrets were mounted to `/run/secrets`. The example functions demonstrate a smooth upgrade implementation.
44+
45+
A simple `go` implementation could look like this
46+
47+
```go
48+
func getAPISecret(secretName string) (secretBytes []byte, err error) {
49+
// read from the openfaas secrets folder
50+
secretBytes, err = ioutil.ReadFile("/var/openfaas/secrets/" + secretName)
51+
if err != nil {
52+
// read from the original location for backwards compatibility with openfaas <= 0.8.2
53+
secretBytes, err = ioutil.ReadFile("/run/secrets/" + secretName)
54+
}
55+
56+
return secretBytes, err
57+
}
58+
```
59+
60+
This example comes from the [`ApiKeyProtected`](https://github.com/openfaas/faas/tree/master/sample-functions/ApiKeyProtected-Secrets) sample function.
61+
62+
## Deploy a function with secrets
63+
4164
Now, update your stack file to include the secret:
4265

4366
```yaml

0 commit comments

Comments
 (0)