Skip to content

Commit 6ea7dc0

Browse files
authored
docs: external authentication, RBAC, SSO (#13866)
* docs: add rate limiting and signup env vars * docs: configure global vars in k8s secrets * docs: per-process login rate limiting * docs: initial rbac and sso content * docs: move jwt page to auth and add redirect * docs: add keycloak example * docs: authorization plugin interface
1 parent c17051c commit 6ea7dc0

9 files changed

Lines changed: 851 additions & 337 deletions

docs/docs/Deployment/deployment-multi-worker.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ See [Troubleshoot multi-worker deployments](./troubleshoot#multi-worker-deployme
273273
| `LANGFLOW_REDIS_QUEUE_POLLING_WATCHDOG_INTERVAL_S` | `15.0` | How often in seconds the watchdog scans for stale jobs. Lower values reclaim resources faster at the cost of more Redis reads. |
274274
| `LANGFLOW_GUNICORN_PRELOAD` | `False` | **Experimental.** Loads the app in the Gunicorn master process before workers fork, reducing per-worker startup overhead. Pairs well with `LANGFLOW_WORKERS`. Non-Windows only. |
275275

276+
:::note
277+
Rate limit counters are stored _per-process_ by default.
278+
To share counters across all workers, point `LANGFLOW_RATE_LIMIT_STORAGE_URI` at the same Redis instance:
279+
280+
```text
281+
LANGFLOW_RATE_LIMIT_STORAGE_URI=redis://your-redis-host:6379/2
282+
```
283+
284+
For more information, see [Login rate limiting](/api-keys-and-authentication#login-rate-limiting).
285+
:::
286+
276287
## Monitor the job queue
277288

278289
The `GET /monitor/job_queue` endpoint returns a metrics snapshot for the running worker. It requires superuser authentication and returns HTTP 403 otherwise.

docs/docs/Develop/api-keys-and-authentication.mdx

Lines changed: 221 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import Tabs from '@theme/Tabs';
77
import TabItem from '@theme/TabItem';
88
import Icon from "@site/src/components/icon";
99

10+
This page documents Langflow's built-in authentication, including user accounts, Langflow API keys, and the environment variables that control access to your server.
11+
To connect Langflow to an external identity provider or SSO system, see [SSO and external authentication](./external-authentication).
12+
1013
:::warning
1114
Never expose Langflow ports directly to the internet without proper security measures.
1215
Set `LANGFLOW_AUTO_LOGIN=False`, use a non-default `LANGFLOW_SECRET_KEY`, and deploy your Langflow server behind a reverse proxy with authentication enabled.
@@ -150,7 +153,7 @@ This section describes the available authentication configuration variables.
150153

151154
You can use the [`.env.example`](https://github.com/langflow-ai/langflow/blob/main/.env.example) file in the Langflow repository as a template for your own `.env` file.
152155

153-
For JWT authentication configuration, including algorithm selection and key management, see [JWT authentication](/jwt-authentication).
156+
For JWT token signing configuration, including algorithm selection and key management, see [Configure JWT token signing](#configure-jwt-token-signing).
154157

155158
### LANGFLOW_AUTO_LOGIN {#langflow-auto-login}
156159

@@ -212,7 +215,7 @@ These defaults don't apply when using the Langflow CLI command [`langflow superu
212215

213216
This environment variable stores a secret key used for encrypting sensitive data like API keys and for JWT signing when using the HS256 algorithm.
214217
Langflow uses the [Fernet](https://pypi.org/project/cryptography/) library for secret key encryption.
215-
For JWT-specific configuration, see [JWT authentication](/jwt-authentication).
218+
For JWT-specific configuration, see [Configure JWT token signing](#configure-jwt-token-signing).
216219

217220
If no secret key is provided, Langflow automatically generates one.
218221

@@ -298,6 +301,18 @@ LANGFLOW_NEW_USER_IS_ACTIVE=False
298301
Only superusers can manage user accounts for a Langflow server, but user management only matters if your server has authentication enabled.
299302
For more information, see [Start a Langflow server with authentication enabled](#start-a-langflow-server-with-authentication-enabled).
300303

304+
### LANGFLOW_ENABLE_SIGNUP {#langflow-enable-signup}
305+
306+
This variable controls whether public self-registration is allowed at the `POST /api/v1/users/` endpoint.
307+
308+
| Value | Description |
309+
|-------|-------------|
310+
| `True` (default) | Anyone can create a new Langflow account by calling the registration endpoint directly. |
311+
| `False` | Public registration is disabled. Only superusers can create new accounts through the admin interface. |
312+
313+
Self-registration is always disabled when `LANGFLOW_AUTO_LOGIN=True`, because single-user mode has no multi-account concept.
314+
Superusers can create accounts regardless of this setting.
315+
301316
### LANGFLOW_API_KEY_SOURCE {#langflow-api-key-source}
302317

303318
This variable controls how Langflow validates API keys.
@@ -457,19 +472,21 @@ SSRF protection prevents requests to internal or private network resources, such
457472

458473
| Variable | Format | Default | Description |
459474
|----------|--------|---------|-------------|
460-
| `LANGFLOW_SSRF_PROTECTION_ENABLED` | Boolean | `False` | Enable SSRF protection for the **API Request** component. When enabled, the component blocks requests to private IP addresses. When disabled, requests are not blocked. |
475+
| `LANGFLOW_SSRF_PROTECTION_ENABLED` | Boolean | `True` | Enable SSRF protection for the **API Request** component. When enabled, the component blocks requests to private IP addresses. When disabled, requests are not blocked. |
461476
| `LANGFLOW_SSRF_ALLOWED_HOSTS` | List[String] | Not set | A comma-separated list of allowed hosts, IP addresses, or CIDR ranges that can bypass SSRF protection checks. For example: `192.168.1.0/24,10.0.0.5,*.internal.company.local`.|
462477

463478
### Login rate limiting {#login-rate-limiting}
464479

465-
The following environment variables configure IP-based rate limiting on the `/login` endpoint to protect against brute-force attacks.
480+
The following environment variables configure IP-based rate limiting to protect against brute-force attacks on the `/login` endpoint and abuse of public flow endpoints.
466481
When the limit is exceeded, Langflow returns HTTP 429 with a `Retry-After: 60` header.
467482

468483
| Variable | Format | Default | Description |
469484
|----------|--------|---------|-------------|
485+
| `LANGFLOW_RATE_LIMIT_ENABLED` | Boolean | `True` | Enable rate limiting globally. Set to `False` to disable all rate limiting (not recommended in production). |
470486
| `LANGFLOW_RATE_LIMIT_PER_MINUTE` | Integer | `5` | Maximum number of login attempts allowed per minute from a single IP address. |
471487
| `LANGFLOW_RATE_LIMIT_STORAGE_URI` | String | `memory://` | Storage backend for rate limit counters. Use `memory://` for single-server deployments or `redis://host:port` for multi-server deployments where the limit should be shared across instances. |
472488
| `LANGFLOW_RATE_LIMIT_TRUST_PROXY` | Boolean | `False` | When `true`, Langflow reads the client IP from the rightmost `X-Forwarded-For` header entry instead of the direct connection IP. Enable only when Langflow is behind a trusted reverse proxy or load balancer. Do not enable if users can reach Langflow directly, as this allows header spoofing. |
489+
| `LANGFLOW_PUBLIC_FLOW_RATE_LIMIT_PER_MINUTE` | Integer | `20` | Maximum number of unauthenticated public-flow runs allowed per minute from a single IP address. Public flows run as the flow owner and consume resources, so anonymous callers are rate-limited separately from the `/login` endpoint. |
473490

474491
### LANGFLOW_WEBHOOK_AUTH_ENABLE {#langflow-webhook-auth-enable}
475492

@@ -485,6 +502,206 @@ To allow webhooks to run without authentication (not recommended; use only in tr
485502

486503
When webhook authentication is enabled, you must provide a Langflow API key with each webhook request as an HTTP header or query parameter. For more information, see [Require authentication for webhooks](/webhook#require-authentication-for-webhooks).
487504

505+
## Configure JWT token signing {#configure-jwt-token-signing}
506+
507+
Langflow issues short-lived JSON Web Tokens (JWTs) when a user logs in. The default HS256 algorithm works for most deployments. Switch to RS256 or RS512 for production deployments that require asymmetric keys or need to share the public key with other services.
508+
509+
<details closed>
510+
<summary>About the JWT structure and contents</summary>
511+
512+
When a user logs in at the `/api/v1/login` endpoint, Langflow validates the credentials and creates a JWT containing the user's identity and expiration time. This token is then used for subsequent API requests instead of sending credentials with each request.
513+
514+
A JWT consists of three parts separated by dots (`.`):
515+
516+
```
517+
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
518+
```
519+
520+
* The header contains the token type and signing algorithm.
521+
* The payload contains _claims_ — token data for user information and expiration time.
522+
* The signature ensures the token hasn't been tampered with.
523+
524+
Each part of the JWT is Base64URL-encoded. You can paste this example JWT to decode the actual JSON data at [jwt.io](https://jwt.io/).
525+
526+
</details>
527+
528+
The following environment variables control JWT signing. `LANGFLOW_SECRET_KEY` is also used for data encryption and is documented separately in [`LANGFLOW_SECRET_KEY`](#langflow-secret-key).
529+
530+
| Variable | Description | Default |
531+
|---|---|---|
532+
| `LANGFLOW_ALGORITHM` | JWT signing algorithm: `HS256`, `RS256`, or `RS512` | `HS256` |
533+
| `LANGFLOW_PRIVATE_KEY` | RSA private key for RS256/RS512 signing | Auto-generated |
534+
| `LANGFLOW_PUBLIC_KEY` | RSA public key for RS256/RS512 verification | Derived from private key |
535+
| `LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS` | Access token expiration time | `3600` (1 hour) |
536+
| `LANGFLOW_REFRESH_TOKEN_EXPIRE_SECONDS` | Refresh token expiration time | `604800` (7 days) |
537+
538+
### HS256 (default)
539+
540+
HS256 is the default JWT algorithm, suitable for single-server deployments.
541+
Langflow automatically generates and persists a secret key via `LANGFLOW_SECRET_KEY`.
542+
No configuration is necessary beyond what is already covered in the [`LANGFLOW_SECRET_KEY`](#langflow-secret-key) section above.
543+
544+
To explicitly set the algorithm in your `.env`:
545+
546+
```bash
547+
LANGFLOW_ALGORITHM=HS256
548+
LANGFLOW_SECRET_KEY="your-custom-secret-key"
549+
```
550+
551+
### RS256
552+
553+
RS256 uses an RSA private/public key pair. The private key signs tokens; the public key verifies them. Use RS256 for production deployments or multi-instance setups where you want to share the public key with other services.
554+
555+
To automatically generate a key pair, set the algorithm and Langflow creates and persists the keys in [`LANGFLOW_CONFIG_DIR`](/logging) on startup:
556+
557+
```bash
558+
LANGFLOW_ALGORITHM=RS256
559+
```
560+
561+
To supply your own private key (public key is derived automatically):
562+
563+
```bash
564+
LANGFLOW_ALGORITHM=RS256
565+
LANGFLOW_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
566+
MIIEvgIBADANBgkqhkiG9w0BAQEF...
567+
-----END PRIVATE KEY-----"
568+
```
569+
570+
To supply a full key pair:
571+
572+
```bash
573+
LANGFLOW_ALGORITHM=RS256
574+
LANGFLOW_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
575+
MIIEvgIBADANBgkqhkiG9w0BAQEF...
576+
-----END PRIVATE KEY-----"
577+
LANGFLOW_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
578+
MIIBIjANBgkqhkiG9w0BAQEFAAOC...
579+
-----END PUBLIC KEY-----"
580+
```
581+
582+
To generate an RSA key pair manually:
583+
584+
1. Generate a 2048-bit private key:
585+
```bash
586+
openssl genrsa -out private_key.pem 2048
587+
```
588+
589+
2. Extract the public key:
590+
```bash
591+
openssl rsa -in private_key.pem -pubout -out public_key.pem
592+
```
593+
594+
### RS512
595+
596+
RS512 uses the same RSA key format as RS256 but with SHA-512 hashing for greater cryptographic strength. Key generation and configuration follow the same pattern as RS256 — substitute `RS512` for `RS256` in all the examples above.
597+
598+
### Configure Docker and Kubernetes deployments
599+
600+
**Docker with HS256** — for single-server or development deployments:
601+
602+
```yaml
603+
services:
604+
langflow:
605+
image: langflowai/langflow:latest
606+
environment:
607+
- LANGFLOW_ALGORITHM=HS256
608+
- LANGFLOW_SECRET_KEY=${LANGFLOW_SECRET_KEY}
609+
volumes:
610+
- langflow_data:/app/langflow
611+
volumes:
612+
langflow_data:
613+
```
614+
615+
**Docker with RS256** — auto-generated keys (persisted in the volume):
616+
617+
```yaml
618+
services:
619+
langflow:
620+
image: langflowai/langflow:latest
621+
environment:
622+
- LANGFLOW_ALGORITHM=RS256
623+
volumes:
624+
- langflow_data:/app/langflow
625+
volumes:
626+
langflow_data:
627+
```
628+
629+
**Docker with RS256** — mount an existing key pair:
630+
631+
```yaml
632+
services:
633+
langflow:
634+
image: langflowai/langflow:latest
635+
environment:
636+
- LANGFLOW_ALGORITHM=RS256
637+
volumes:
638+
- ./keys/private_key.pem:/app/langflow/private_key.pem:ro
639+
- ./keys/public_key.pem:/app/langflow/public_key.pem:ro
640+
- langflow_data:/app/langflow
641+
volumes:
642+
langflow_data:
643+
```
644+
645+
**Kubernetes with RS256** — store keys as Secrets:
646+
647+
```yaml
648+
# jwt-secret.yaml
649+
apiVersion: v1
650+
kind: Secret
651+
metadata:
652+
name: langflow-jwt-keys
653+
type: Opaque
654+
stringData:
655+
algorithm: "RS256"
656+
private-key: |
657+
-----BEGIN PRIVATE KEY-----
658+
MIIEvgIBADANBgkqhkiG9w0BAQEF...
659+
-----END PRIVATE KEY-----
660+
public-key: |
661+
-----BEGIN PUBLIC KEY-----
662+
MIIBIjANBgkqhkiG9w0BAQEFAAOC...
663+
-----END PUBLIC KEY-----
664+
---
665+
# langflow-deployment.yaml
666+
apiVersion: apps/v1
667+
kind: Deployment
668+
metadata:
669+
name: langflow
670+
spec:
671+
template:
672+
spec:
673+
containers:
674+
- name: langflow
675+
image: langflowai/langflow:latest
676+
env:
677+
- name: LANGFLOW_ALGORITHM
678+
valueFrom:
679+
secretKeyRef:
680+
name: langflow-jwt-keys
681+
key: algorithm
682+
- name: LANGFLOW_PRIVATE_KEY
683+
valueFrom:
684+
secretKeyRef:
685+
name: langflow-jwt-keys
686+
key: private-key
687+
- name: LANGFLOW_PUBLIC_KEY
688+
valueFrom:
689+
secretKeyRef:
690+
name: langflow-jwt-keys
691+
key: public-key
692+
```
693+
694+
### Configure token expiration
695+
696+
Access tokens authenticate API requests and typically expire within 15 minutes to 1 hour.
697+
Refresh tokens obtain new access tokens without requiring the user to log in again and typically expire within 7 to 30 days.
698+
When an access token expires, the client can use the refresh token to get a new one from `/api/v1/refresh`.
699+
700+
```bash
701+
LANGFLOW_ACCESS_TOKEN_EXPIRE_SECONDS=3600 # 1 hour
702+
LANGFLOW_REFRESH_TOKEN_EXPIRE_SECONDS=604800 # 7 days
703+
```
704+
488705
## Start a Langflow server with authentication enabled
489706

490707
This section shows you how to use the [authentication environment variables](/api-keys-and-authentication#authentication-environment-variables) to deploy a Langflow server with authentication enabled.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Authentication and authorization overview
3+
slug: /authentication-overview
4+
---
5+
6+
Langflow uses *authentication* to verify who a user is before granting access, and *authorization* to control what an authenticated user is allowed to do.
7+
8+
Authentication and authorization are configured independently. Most deployments only require authentication. Authorization is an optional plugin that adds role-based access control (RBAC) to your server.
9+
10+
To configure authentication and authorization for your Langflow server, pick your authentication path below and follow the corresponding documentation.
11+
12+
* To secure a Langflow server with user accounts and API keys using Langflow's built-in authentication, see [API keys and authentication](./api-keys-and-authentication).
13+
Built-in authentication is always available and is the default setting. Users log in with a username and password, and Langflow issues a short-lived JWT session token and validates Langflow API keys against its own database.
14+
15+
* To connect Langflow to your company's SSO, OIDC, or identify provider, see [SSO and external authentication](./external-authentication).
16+
External authentication lets an upstream identity provider, OIDC proxy, or corporate SSO gateway handle login. Langflow accepts the token the proxy forwards, validates it against the identity provider's JWKS endpoint, and provisions a local user automatically.
17+
18+
* To configure RBAC on your Langflow server, see [Authorization](./authorization).
19+
After a user is authenticated by any of the authentication paths, the authorization layer decides what the user can do.
20+
RBAC enforcement requires a registered authorization plugin.
21+
22+
When multiple credentials are present, Langflow tries each credential in the order of built-in JWT, external token, and then Langflow API key.
23+
24+
## See also
25+
26+
- [Environment variables](/environment-variables)
27+
- [Security](/security)

0 commit comments

Comments
 (0)