Skip to content

Commit e02198e

Browse files
authored
Merge pull request #388 from raptorsun/lcore-429
LCORE-429: add docs on configuring authentication
2 parents c09653b + e3bc9b3 commit e02198e

File tree

1 file changed

+125
-19
lines changed

1 file changed

+125
-19
lines changed

README.md

Lines changed: 125 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,44 @@ Lightspeed Core Stack (LCS) is an AI-powered assistant that provides answers to
1313

1414
<!-- vim-markdown-toc GFM -->
1515

16+
* [lightspeed-stack](#lightspeed-stack)
17+
* [About The Project](#about-the-project)
1618
* [Architecture](#architecture)
1719
* [Prerequisites](#prerequisites)
1820
* [Installation](#installation)
1921
* [Configuration](#configuration)
20-
* [Integration with Llama Stack](#integration-with-llama-stack)
21-
* [Llama Stack as separate server](#llama-stack-as-separate-server)
22-
* [Llama Stack project and configuration](#llama-stack-project-and-configuration)
23-
* [Check connection to Llama Stack](#check-connection-to-llama-stack)
24-
* [Llama Stack as client library](#llama-stack-as-client-library)
25-
* [System prompt](#system-prompt)
26-
* [Safety Shields](#safety-shields)
22+
* [Integration with Llama Stack](#integration-with-llama-stack)
23+
* [Llama Stack as separate server](#llama-stack-as-separate-server)
24+
* [Llama Stack project and configuration](#llama-stack-project-and-configuration)
25+
* [Check connection to Llama Stack](#check-connection-to-llama-stack)
26+
* [Llama Stack as client library](#llama-stack-as-client-library)
27+
* [System prompt](#system-prompt)
28+
* [Safety Shields](#safety-shields)
29+
* [Authentication](#authentication)
30+
* [K8s based authentication](#k8s-based-authentication)
31+
* [JSON Web Keyset based authentication](#json-web-keyset-based-authentication)
32+
* [No-op authentication](#no-op-authentication)
2733
* [Usage](#usage)
28-
* [Make targets](#make-targets)
29-
* [Running Linux container image](#running-linux-container-image)
34+
* [Make targets](#make-targets)
35+
* [Running Linux container image](#running-linux-container-image)
3036
* [Endpoints](#endpoints)
31-
* [OpenAPI specification](#openapi-specification)
32-
* [Readiness Endpoint](#readiness-endpoint)
33-
* [Liveness Endpoint](#liveness-endpoint)
37+
* [OpenAPI specification](#openapi-specification)
38+
* [Readiness Endpoint](#readiness-endpoint)
39+
* [Liveness Endpoint](#liveness-endpoint)
3440
* [Publish the service as Python package on PyPI](#publish-the-service-as-python-package-on-pypi)
35-
* [Generate distribution archives to be uploaded into Python registry](#generate-distribution-archives-to-be-uploaded-into-python-registry)
36-
* [Upload distribution archives into selected Python registry](#upload-distribution-archives-into-selected-python-registry)
37-
* [Packages on PyPI and Test PyPI](#packages-on-pypi-and-test-pypi)
41+
* [Generate distribution archives to be uploaded into Python registry](#generate-distribution-archives-to-be-uploaded-into-python-registry)
42+
* [Upload distribution archives into selected Python registry](#upload-distribution-archives-into-selected-python-registry)
43+
* [Packages on PyPI and Test PyPI](#packages-on-pypi-and-test-pypi)
3844
* [Contributing](#contributing)
3945
* [Testing](#testing)
4046
* [License](#license)
4147
* [Additional tools](#additional-tools)
42-
* [Utility to generate OpenAPI schema](#utility-to-generate-openapi-schema)
43-
* [Path](#path)
44-
* [Usage](#usage-1)
45-
48+
* [Utility to generate OpenAPI schema](#utility-to-generate-openapi-schema)
49+
* [Path](#path)
50+
* [Usage](#usage-1)
51+
* [Project structure](#project-structure)
52+
* [Configuration classes](#configuration-classes)
53+
* [REST API](#rest-api)
4654

4755
<!-- vim-markdown-toc -->
4856

@@ -227,6 +235,104 @@ utilized:
227235
1. If the `shield_id` starts with `inout_`, it will be used both for input and output.
228236
1. Otherwise, it will be used for input only.
229237

238+
## Authentication
239+
240+
Currently supported authentication modules are:
241+
* `k8s` Kubernetes based authentication
242+
* `jwk-token` JSON Web Keyset based authentication
243+
* `noop` No operation authentication (default)
244+
* `noop-with-token` No operation authentication with token
245+
246+
### K8s based authentication
247+
248+
K8s based authentication is suitable for running the Lightspeed Stack in Kubernetes environments.
249+
The user accessing the service must have a valid Kubernetes token and the appropriate RBAC permissions to access the service.
250+
The user must have `get` permission on the Kubernetes RBAC non-resource URL `/ls-access`.
251+
Here is an example of granting `get` on `/ls-access` via a ClusterRole’s nonResourceURLs rule.
252+
Example:
253+
```yaml
254+
# Allow GET on non-resource URL /ls-access
255+
apiVersion: rbac.authorization.k8s.io/v1
256+
kind: ClusterRole
257+
metadata:
258+
name: lightspeed-access
259+
rules:
260+
- nonResourceURLs: ["/ls-access"]
261+
verbs: ["get"]
262+
---
263+
# Bind to a user, group, or service account
264+
apiVersion: rbac.authorization.k8s.io/v1
265+
kind: ClusterRoleBinding
266+
metadata:
267+
name: lightspeed-access-binding
268+
roleRef:
269+
apiGroup: rbac.authorization.k8s.io
270+
kind: ClusterRole
271+
name: lightspeed-access
272+
subjects:
273+
- kind: User # or ServiceAccount, Group
274+
name: SOME_USER_OR_SA
275+
apiGroup: rbac.authorization.k8s.io
276+
```
277+
278+
Configuring K8s based authentication requires the following steps:
279+
1. Enable K8s authentication module
280+
```yaml
281+
authentication:
282+
module: "k8s"
283+
```
284+
2. Configure the Kubernetes authentication settings.
285+
When deploying Lightspeed Stack in a Kubernetes cluster, it is not required to specify cluster connection details.
286+
It automatically picks up the in-cluster configuration or through a kubeconfig file.
287+
This step is not neccessary.
288+
When running outside a kubernetes cluster or connecting to external Kubernetes clusters, Lightspeed Stack requires the cluster connection details in the configuration file:
289+
- `k8s_cluster_api` Kubernetes Cluster API URL. The URL of the K8S/OCP API server where tokens are validated.
290+
- `k8s_ca_cert_path` Path to the CA certificate file for clusters with self-signed certificates.
291+
- `skip_tls_verification` Whether to skip TLS verification.
292+
```yaml
293+
authentication:
294+
module: "k8s"
295+
skip_tls_verification: false
296+
k8s_cluster_api: "https://your-k8s-api-server:6443"
297+
k8s_ca_cert_path: "/path/to/ca.crt"
298+
```
299+
300+
### JSON Web Keyset based authentication
301+
302+
JWK (JSON Web Keyset) based authentication is suitable for scenarios where you need to authenticate users based on tokens. This method is commonly used in web applications and APIs.
303+
304+
To configure JWK based authentication, you need to specify the following settings in the configuration file:
305+
- `module` must be set to `jwk-token`
306+
- `jwk_config` JWK configuration settings must set at least `url` field:
307+
- `url`: The URL of the JWK endpoint.
308+
- `jwt_configuration`: JWT configuration settings.
309+
- `user_id_claim`: The key of the user ID in JWT claim.
310+
- `username_claim`: The key of the username in JWT claim.
311+
312+
```yaml
313+
authentication:
314+
module: "jwk-token"
315+
jwk_config:
316+
url: "https://your-jwk-url"
317+
jwt_configuration:
318+
user_id_claim: user_id
319+
username_claim: username
320+
```
321+
322+
### No-op authentication
323+
324+
Lightspeed Stack provides 2 authentication module to bypass the authentication and authorization checks:
325+
- `noop` No operation authentication (default)
326+
- `noop-with-token` No operation authentication accepting a bearer token
327+
328+
If authentication module is not specified, Lightspeed Stack will use `noop` by default.
329+
To activate `noop-with-token`, you need to specify it in the configuration file:
330+
331+
```yaml
332+
authentication:
333+
module: "noop-with-token"
334+
```
335+
230336
# Usage
231337

232338
```

0 commit comments

Comments
 (0)