Skip to content

Commit e21b57b

Browse files
committed
Add token restriction example and background image
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 8f3e247 commit e21b57b

3 files changed

Lines changed: 71 additions & 6 deletions

File tree

_posts/2024-05-14-function-authentication.md renamed to _posts/2024-05-16-function-authentication.md

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
---
2-
title: Introducing built-in Function Authentication for OpenFaaS
2+
title: Introducing built-in authentication for OpenFaaS Functions
33
description:
4-
date: 2024-05-14
4+
date: 2024-05-16
55
categories:
66
- kubernetes
77
- faas
88
- functions
99
- authentication
1010
- authorization
1111
dark_background: true
12-
# image: "/images/2024-05-01-chargeback/background.png"
12+
image: "/images/2024-05-function-auth/background.png"
1313
author_staff_member: alex
1414
hide_header_image: true
1515
---
1616

1717
A long standing request from OpenFaaS users has been to add built-in authentication for functions. This would allow you to secure your function endpoints without having to write any additional code.
1818

19-
In this blog post we'll show you how to use an updated version of IAM for OpenFaaS to create a Policy that restricts access to a function only to authorized users with JSON Web Token (JWT) authentication.
19+
Once a function deployed via the OpenFaaS gateway, it will become available on the gateway via the path: `/function/NAME` and `/async-function/NAME`. This means that anyone with access to the gateway can invoke the function, and the function's handler is responsible for any authentication or authorization.
2020

21-
You'll need to have OpenFaaS for Enterprises pre-installed and configured to integrate with your existing Identify Provider (IdP) such as Okta, Keycloak, or Google.
21+
In this blog post we'll show you how to use a pre-release version of [IAM for OpenFaaS](https://docs.openfaas.com/openfaas-pro/iam/overview/) to create a Policy that restricts access to a function only to authorized users with JSON Web Token (JWT) authentication.
22+
23+
You'll need to have [OpenFaaS for Enterprises](https://docs.openfaas.com/openfaas-pro/introduction/) pre-installed and configured to integrate with your existing Identify Provider (IdP) such as Okta, Keycloak, or Google.
2224

2325
We will perform the initial one-time setup process:
2426

@@ -207,6 +209,65 @@ The resulting token will look like this:
207209

208210
Save the text from the "access_token" field as function-token.txt.
209211

212+
It will look something like this:
213+
214+
```json
215+
{
216+
"iss": "https://openfaas.example.com",
217+
"sub": "fed:a9e0e67a-5758-4373-a4ba-23957fa66e6b",
218+
"aud": [
219+
"https://openfaas.example.com"
220+
],
221+
"exp": 1715892121,
222+
"iat": 1715848921,
223+
"function": {
224+
"permissions": [
225+
"openfaas-fn:*",
226+
"dev:env"
227+
]
228+
}
229+
}
230+
```
231+
232+
As you can see, the union of permissions from the Policy are encoded into the Function Token.
233+
234+
If you wish to restrict the token so that it can only be used to invoke a single function, or a subset of functions, you can request a specific audience when you exchange the token.
235+
236+
```bash
237+
curl -S -L -X POST "${IDP_TOKEN_URL}" \
238+
--header 'Content-Type: application/x-www-form-urlencoded' \
239+
--data-urlencode "subject_token=${TOKEN}" \
240+
--data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:id_token" \
241+
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
242+
--data-urlencode 'scope=function' \
243+
--data-urlencode 'audience=openfaas-fn:env' \
244+
--data-urlencode 'audience=openfaas-fn:figlet'
245+
```
246+
247+
Here's how the token looks, with the audience also specified.
248+
249+
```json
250+
{
251+
"iss": "https://openfaas.example.com",
252+
"sub": "fed:a9e0e67a-5758-4373-a4ba-23957fa66e6b",
253+
"aud": [
254+
"https://openfaas.example.com"
255+
],
256+
"exp": 1715892177,
257+
"iat": 1715848977,
258+
"function": {
259+
"permissions": [
260+
"openfaas-fn:*",
261+
"dev:env"
262+
],
263+
"audience": [
264+
"openfaas-fn:env",
265+
"openfaas-fn:figlet"
266+
]
267+
}
268+
}
269+
```
270+
210271
## Invoke the function with the Function Token
211272

212273
You now have a token that can be used to invoke a function. You can use it with curl or any HTTP client.
@@ -232,6 +293,10 @@ If you already have IAM for OpenFaaS installed and configured for Single-Sign On
232293

233294
### Q&A
234295

296+
Q: Are Function Tokens production-ready? When will I be able to use them in production?
297+
298+
A: Function Tokens, once released will be suitable for use in production. They are an extension of the already released IAM for OpenFaaS features and use the same underlying technology for the new type of Function Token. The work is currently pre-release and available for testing, once it's released you will have access to it via the Helm chart.
299+
235300
Q: I use another version of OpenFaaS i.e. faasd, what can I do to authenticate functions?
236301

237302
A: OpenFaaS functions serve HTTP, therefore [you can use any standard authentication mechanism](https://docs.openfaas.com/reference/authentication/) such as Basic Auth, HMAC, API tokens, or OAuth2. We do not recommend using an API gateway or reverse proxy to implement authentication, as functions can be invoked directly at the Pod level, or via the OpenFaaS gateway's internal address, bypassing the proxy.

_sass/openfaas/includes/blog-page/highlighter.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
background-color: #fbf1c7;
1212
.w {
1313
color: #282828;
14-
background-color: #fbf1c7;
14+
// background-color: #fbf1c7;
1515
}
1616
.err {
1717
color: #9d0006;
106 KB
Loading

0 commit comments

Comments
 (0)