Skip to content

Commit 4d046f7

Browse files
weltekialexellis
authored andcommitted
Improve docs for uplink REST API
- Improve installation instructions - Add OAuth section - Add metrics response example Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent 781573a commit 4d046f7

File tree

1 file changed

+174
-45
lines changed

1 file changed

+174
-45
lines changed

docs/uplink/rest-api.md

Lines changed: 174 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,47 @@ A quick note on TLS: when you expose the uplink API over the Internet, you shoul
66

77
## Installation
88

9-
The Uplink Client API can be enabled through the helm chart. Update the `values.yaml`:
9+
The REST API is part of the client-api component, and is disabled by default.
10+
You'll need to configure authentication, then update the values.yaml file and install the chart again.
11+
12+
An access token needs to be created for the Client API before it can be deployed.
13+
14+
```sh
15+
# Generate a new access token
16+
export token=$(openssl rand -base64 32|tr -d '\n')
17+
echo -n $token > $HOME/.inlets/client-api
18+
19+
# Store the access token in a secret in the inlets namespace.
20+
kubectl create secret generic \
21+
client-api-token \
22+
-n inlets \
23+
--from-file client-api-token=$HOME/.inlets/client-api
24+
```
25+
26+
This token can be used to authenticate with the API.
27+
28+
> See the [OAuth configuration](#configure-oauth) section for instructions on how to enable OAuth.
29+
30+
Add the following parameters to your uplink `values.yaml` file and update the deployment:
1031

1132
```yaml
1233
clientApi:
13-
enable: true
34+
enable: true
35+
36+
# Domain used for client API ingress
37+
domain: clientapi.example.com
1438

15-
# Domain used for client API ingress
16-
domain: clientapi.example.com
39+
tls:
40+
ingress:
41+
# Optionally enable ingress for the Client API
42+
enabled: true
1743
```
1844
1945
## Authentication
2046
21-
The Inlets Uplink client API supports authentication through API tokens.
47+
The Inlets Uplink client API supports authentication through a static API token or using OAuth.
48+
49+
### Static API token
2250
2351
The authentication token can be retrieved from the cluster at any time by an administrator.
2452
@@ -28,76 +56,145 @@ export TOKEN=$(kubectl get secret -n inlets client-api-token \
2856
| base64 --decode)
2957
```
3058

31-
## Tunnels
59+
Use the token as bearer token in the `Authorization` header when making requests to the API.
60+
61+
### OAuth
62+
63+
If you have OAuth enabled you can obtain a token from your provider that can be used to invoke the Uplink Client API.
64+
65+
The example uses the client credentials grant. Replace the token url, client id and client secret with the values obtained from your identity provider.
66+
67+
```sh
68+
export IDP_TOKEN_URL="https://myprovider.example.com/token"
69+
export CLIENT_ID="inlets-uplink"
70+
export CLIENT_SECRET="$(cat ./client-secret.txt)"
71+
72+
curl -S -L -X POST "${IDP_TOKEN_URL}" \
73+
--header 'Content-Type: application/x-www-form-urlencoded' \
74+
--data-urlencode "client_id=${CLIENT_ID}" \
75+
--data-urlencode "client_secret=${CLIENT_SECRET}" \
76+
--data-urlencode 'scope=openid' \
77+
--data-urlencode 'grant_type=client_credentials'
78+
```
79+
80+
Use the token as bearer token in the `Authorization` header when making requests to the API.
81+
82+
```sh
83+
export CLIENT_API="https://clienapi.example.com"
84+
export NAME="acmeco"
85+
export NAMESPACE="acmeco"
86+
87+
curl -i \
88+
-H "Authorization: Bearer ${TOKEN}" \
89+
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
90+
```
91+
92+
## Tunnel management
93+
94+
We will be create an tunnel named `acmeco` in the `acmeco` namespace in the API examples.
3295

3396
### Get a tunnel
3497

3598
```sh
99+
export CLIENT_API="https://clienapi.example.com"
100+
export NAME="acmeco"
101+
export NAMESPACE="acmeco"
102+
36103
curl -i \
37-
-H "Authorization: Bearer ${TOKEN}" \
38-
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
104+
-H "Authorization: Bearer ${TOKEN}" \
105+
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
39106
```
40107

41108
Adding the query parameter `metrics=1` includes additional tunnel metrics in the response like RX and TX and TCP connection rate.
42109

43110
Path parameters:
44111

45-
* `name` - Name of the tunnel.
112+
- `name` - Name of the tunnel.
46113

47114
Query parameters:
48115

49-
* `namespace` - Namespace where the tunnel should be looked up.
50-
* `metrics` - Include tunnel metrics in the response.
116+
- `namespace` - Namespace where the tunnel should be looked up.
117+
- `metrics` - Include tunnel metrics in the response.
118+
119+
Example response with metrics:
120+
121+
```json
122+
{
123+
"name": "acmeco",
124+
"namespace": "acmeco",
125+
"tcpPorts": [80, 443],
126+
"authToken": "TAjFZExVq6qUfnqojwR2HOej347fRXqV3vLexlyoP6GcRZ2SjIUALY8Jdx8",
127+
"connectedClients": 1,
128+
"created": "2024-09-10T14:48:21Z",
129+
"metrics": {
130+
"rx": 195482,
131+
"tx": 32348,
132+
"tcpConnectionRate": 62.99
133+
}
134+
}
135+
```
136+
137+
The metrics section includes rx/tx bytes per second and tcp connection rate over the last 5 minutes.
51138

52139
### List tunnels
53140

54141
```sh
142+
export CLIENT_API="https://clienapi.example.com"
143+
export NAMESPACE="acmeco"
144+
55145
curl -i \
56-
-H "Authorization: Bearer ${TOKEN}" \
57-
"$CLIENT_API/v1/tunnels?namespace=$NAMESPACE"
146+
-H "Authorization: Bearer ${TOKEN}" \
147+
"$CLIENT_API/v1/tunnels?namespace=$NAMESPACE"
58148
```
59149

60150
Query parameters:
61151

62-
* `namespace` - Namespace where the tunnel should be looked up.
152+
- `namespace` - Namespace where the tunnel should be looked up.
63153

64154
### Create a tunnel
65155

66156
```sh
157+
export CLIENT_API="https://clienapi.example.com"
158+
67159
curl -i \
68-
-X POST \
69-
-H "Authorization: Bearer ${TOKEN}" \
70-
"$CLIENT_API/v1/tunnels"
71-
-d '{ "name": "acmeco", "namespace": "acmeco", "tcpPorts": [ 80, 443 ] }'
160+
-X POST \
161+
-H "Authorization: Bearer ${TOKEN}" \
162+
"$CLIENT_API/v1/tunnels"
163+
-d '{ "name": "acmeco", "namespace": "acmeco", "tcpPorts": [ 80, 443 ] }'
72164
```
73165

74166
### Update a tunnel
75167

76168
```sh
169+
export CLIENT_API="https://clienapi.example.com"
170+
77171
curl -i \
78-
-X PUT \
79-
-H "Authorization: Bearer ${TOKEN}" \
80-
"$CLIENT_API/v1/tunnels"
81-
-d '{ "name": "acmeco", "namespace": "acmeco", "tcpPorts": [ 80, 443, 4222 ] }'
172+
-X PUT \
173+
-H "Authorization: Bearer ${TOKEN}" \
174+
"$CLIENT_API/v1/tunnels"
175+
-d '{ "name": "acmeco", "namespace": "acmeco", "tcpPorts": [ 80, 443, 4222 ] }'
82176
```
83177

84178
### Delete a tunnel
85179

86180
```sh
181+
export CLIENT_API="https://clienapi.example.com"
182+
export NAME="acmeco"
183+
export NAMESPACE="acmeco"
184+
87185
curl -i \
88-
-X DELETE \
89-
-H "Authorization: Bearer ${TOKEN}" \
90-
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
186+
-X DELETE \
187+
-H "Authorization: Bearer ${TOKEN}" \
188+
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
91189
```
92190

93191
Path parameters:
94192

95-
* `name` - Name of the tunnel.
193+
- `name` - Name of the tunnel.
96194

97195
Query parameters:
98196

99-
* `namespace` - Namespace where the tunnel should be looked up.
100-
197+
- `namespace` - Namespace where the tunnel should be looked up.
101198

102199
## Namespace management
103200

@@ -109,19 +206,23 @@ The `kube-system` and `inlets` namespace can not be used as tunnel namespaces.
109206
List all inlets uplink namespaces. This endpoint will list all namespaces with a label `inlets.dev/uplink=1`.
110207

111208
```sh
209+
export CLIENT_API="https://clienapi.example.com"
210+
112211
curl -i \
113-
-H "Authorization: Bearer ${TOKEN}" \
114-
"$CLIENT_API/v1/namespace
212+
-H "Authorization: Bearer ${TOKEN}" \
213+
"$CLIENT_API/v1/namespace
115214
```
116215
117216
### Create a namespace
118217
119218
```sh
219+
export CLIENT_API="https://clienapi.example.com"
220+
120221
curl -i \
121-
-X POST \
122-
-H "Authorization: Bearer ${TOKEN}" \
123-
"$CLIENT_API/v1/tunnels/$NAME?namespace=$NAMESPACE"
124-
-d '{ "name": "acmeco" }'
222+
-X POST \
223+
-H "Authorization: Bearer ${TOKEN}" \
224+
"$CLIENT_API/v1/namespace
225+
-d '{ "name": "acmeco" }'
125226
```
126227

127228
Every namespace created through the API will have the `inlets.dev/uplink=1` label set.
@@ -130,21 +231,49 @@ The API supports adding additional namespace labels and annotations:
130231

131232
```json
132233
{
133-
"name": "acmeco",
134-
"annotations": {
135-
"customer": "acmeco"
136-
},
137-
"labels": {
138-
"customer": "acmeco"
139-
}
234+
"name": "acmeco",
235+
"annotations": {
236+
"customer": "acmeco"
237+
},
238+
"labels": {
239+
"customer": "acmeco"
240+
}
140241
}
141242
```
142243

143244
### Delete a namespace
144245

145246
```sh
247+
export CLIENT_API="https://clienapi.example.com"
248+
export NAME="acmeco"
249+
146250
curl -i \
147-
-X DELETE \
148-
-H "Authorization: Bearer ${TOKEN}" \
149-
"$CLIENT_API/v1/namespace/$NAME"
150-
```
251+
-X DELETE \
252+
-H "Authorization: Bearer ${TOKEN}" \
253+
"$CLIENT_API/v1/namespace/$NAME"
254+
```
255+
256+
## Configure OAuth
257+
258+
You can configure any OpenID Connect (OIDC) compatible identity provider for use with Inlets Uplink.
259+
260+
1. Register a new client (application) for Inlets Uplink with your identity provider.
261+
2. Enable the required authentication flows.
262+
The Client Credentials flow is ideal for serve-to-server interactions where there is no direct user involvement. This is the flow we recommend and use in our examples any other authentication flow can be picked depending on your use case.
263+
3. Configure Client API
264+
265+
Update your `values.yaml` file and add to following parameters to the `clientApi` section:
266+
267+
```yaml
268+
clientApi:
269+
# OIDC provider url.
270+
issuerURL: "https://myprovider.example.com"
271+
272+
# The audience is generally the same as the value of the domain field, however
273+
# some issuers like keycloak make the audience the client_id of the application/client.
274+
audience: "clienapi.example.com"
275+
```
276+
277+
The `issuerURL` needs to be set to the url of your provider, eg. `https://accounts.google.com` for google or `https://example.eu.auth0.com/` for Auth0.
278+
279+
The `audience` is usually the client apis public URL although for some providers it can also be the client id.

0 commit comments

Comments
 (0)