mirror of
https://github.com/open-webui/terminals.git
synced 2026-11-22 21:50:42 -05:00
refac
This commit is contained in:
1 parent
d940948f8f
commit
4c51e34c2a
1 file changed
+311
-233
@@ -1,127 +1,342 @@
|
||||
# Terminals
|
||||
|
||||
Per-user [Open Terminal](https://github.com/open-webui/open-terminal) orchestration for Docker and Kubernetes.
|
||||
Give each Open WebUI user their own [Open Terminal](https://github.com/open-webui/open-terminal) container. Terminals starts containers on demand, routes requests to the right user, and manages policies, persistent files, and idle cleanup on Docker or Kubernetes.
|
||||
|
||||
Terminals gives every Open WebUI user their own isolated container, with separate credentials, resource limits, and network rules. It handles the full lifecycle automatically: spinning up containers when a user connects, proxying traffic, enforcing limits, and cleaning up when they're done.
|
||||
|
||||
```
|
||||
Open WebUI → Terminals service → per-user containers
|
||||
(this project) (Open Terminal images)
|
||||
```text
|
||||
Open WebUI → Terminals → Open Terminal containers
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **Production use requires an [Open WebUI Enterprise License](LICENSE) with Terminals access.** Contact the Open WebUI team to get started.
|
||||
> Production use requires an [Open WebUI Enterprise License](LICENSE) with Terminals access.
|
||||
|
||||
## Quick Start
|
||||
[Quick start](#quick-start) · [Admin UI](#admin-ui) · [Policies](#policies) · [Storage](#storage-and-persistence) · [Kubernetes](#kubernetes-deployment) · [Configuration](#configuration) · [Troubleshooting](#troubleshooting)
|
||||
|
||||
The fastest way to get running is with Docker. Terminals will manage sibling containers through the Docker socket.
|
||||
## Quick start
|
||||
|
||||
### Docker (recommended for single-node)
|
||||
You need Docker running and an existing Open WebUI instance. These commands use a macOS/Linux shell or WSL, with `openssl` available to generate a key. No repository clone or separate database is needed.
|
||||
|
||||
### 1. Start Terminals
|
||||
|
||||
Run this in the directory where you want to keep your terminal data:
|
||||
|
||||
```bash
|
||||
docker run -p 3000:3000 \
|
||||
-e TERMINALS_DOCKER_HOST=host.docker.internal \
|
||||
mkdir -p data
|
||||
export API_KEY="$(openssl rand -hex 32)"
|
||||
|
||||
docker network create terminals
|
||||
|
||||
docker run -d \
|
||||
--name terminals \
|
||||
--restart unless-stopped \
|
||||
--network terminals \
|
||||
-p 127.0.0.1:3000:3000 \
|
||||
-e TERMINALS_API_KEY="$API_KEY" \
|
||||
-e TERMINALS_DOCKER_NETWORK=terminals \
|
||||
-e TERMINALS_DOCKER_HOST_DATA_DIR="$(pwd)/data/terminals" \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v "$(pwd)/data:/app/data" \
|
||||
ghcr.io/open-webui/terminals:latest
|
||||
|
||||
printf 'API key: %s\n' "$API_KEY"
|
||||
```
|
||||
|
||||
**Prerequisites:** Docker running on the host.
|
||||
Save the printed key. Use the same key when recreating the service. If the `terminals` network already exists, skip the network creation command.
|
||||
|
||||
The image stores SQLite at `/app/data/terminals.db` and accesses workspaces at
|
||||
`/app/data/terminals`. Set the optional `TERMINALS_DOCKER_HOST_DATA_DIR` only when
|
||||
the Docker daemon sees those workspaces at a different absolute path, as above.
|
||||
Both paths must refer to the same bind-mounted directory so provisioning and
|
||||
file resets access the same files. Leave it unset when running directly on the
|
||||
Docker host or when host and container paths match.
|
||||
The service and the terminal containers use the same Docker network, so no host gateway configuration is needed. The `data` directory holds the database and users' terminal files.
|
||||
|
||||
When upgrading an existing deployment, back up and move its database and
|
||||
workspaces from their previous effective paths before switching to this layout.
|
||||
Changing these settings does not migrate existing files or container mounts.
|
||||
### 2. Open the admin UI
|
||||
|
||||
### Kubernetes Operator (recommended for clusters)
|
||||
Open **[http://localhost:3000](http://localhost:3000)**, paste the key into **Admin key**, and click **Refresh**. An empty Active terminals list is expected until someone uses a terminal.
|
||||
|
||||
For Kubernetes deployments, the operator manages `Terminal` custom resources automatically, handling pod creation, storage, and cleanup through CRDs.
|
||||
Check that the service is running:
|
||||
|
||||
```bash
|
||||
# Install the CRD and operator
|
||||
kubectl apply -f manifests/terminal-crd.yaml
|
||||
kubectl apply -f manifests/operator-deployment.yaml
|
||||
curl -fsS http://localhost:3000/health
|
||||
```
|
||||
|
||||
Set `TERMINALS_BACKEND=kubernetes-operator` when deploying the Terminals service.
|
||||
Expected response: `{"status":true}`. If it is not ready, check `docker logs terminals`.
|
||||
|
||||
For OpenShift, use restricted mode and an OpenShift-compatible Open Terminal image. See [OpenShift deployment](docs/openshift.md).
|
||||
### 3. Connect Open WebUI
|
||||
|
||||
### From source (development)
|
||||
If Open WebUI runs in Docker, attach its container to the same network. Replace `open-webui` with your container's name; skip this if it is already attached:
|
||||
|
||||
```bash
|
||||
pip install -e .
|
||||
terminals serve
|
||||
docker network connect terminals open-webui
|
||||
```
|
||||
|
||||
## Choosing a Backend
|
||||
In Open WebUI, open **Settings → Admin → Integrations → Open Terminal** and add a connection:
|
||||
|
||||
| Backend | Best for | How it works |
|
||||
|---------|----------|-------------|
|
||||
| `docker` | Single-node, local dev | One container per user via Docker socket |
|
||||
| `kubernetes-operator` | Production K8s clusters | Operator watches `Terminal` CRDs for automated lifecycle |
|
||||
| `kubernetes` | K8s without CRDs | Direct Pod + PVC + Service per user (you manage resources) |
|
||||
| Field | Value |
|
||||
|-------|-------|
|
||||
| URL | `http://terminals:3000` when Open WebUI is on the Docker network above |
|
||||
| Auth | `Bearer` |
|
||||
| API Key | The key printed in step 1 |
|
||||
|
||||
Set the backend with `TERMINALS_BACKEND` (defaults to `docker`).
|
||||
If Open WebUI runs directly on the same host, use `http://localhost:3000` instead. The URL must be reachable from the Open WebUI server. The quick start binds the admin port to localhost; for remote access, expose it through your usual authenticated HTTPS deployment.
|
||||
|
||||
Verify the connection and save it. In a chat, select it from the terminal menu. Terminals creates the user's container on first use; the first request can take longer while its image is downloaded.
|
||||
|
||||
See the [Open WebUI connection guide](https://docs.openwebui.com/features/open-terminal/setup/connecting/) for the full UI walkthrough. Leave `TERMINALS_OPEN_WEBUI_URL` unset for this Bearer-key setup.
|
||||
|
||||
<details>
|
||||
<summary>Try a terminal directly with curl</summary>
|
||||
|
||||
This creates a terminal for the example user `demo-user`:
|
||||
|
||||
```bash
|
||||
curl -fsS http://localhost:3000/execute \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "X-User-Id: demo-user" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"command":"echo hello"}'
|
||||
```
|
||||
|
||||
The examples below use the same `$API_KEY` shell variable. In a new shell, set it to your saved key.
|
||||
|
||||
</details>
|
||||
|
||||
## Admin UI
|
||||
|
||||
The built-in UI at `/` has three sections:
|
||||
|
||||
- **Active terminals:** inspect user terminals and stop individual instances. Stopping a terminal keeps its persisted files; the next access starts it again.
|
||||
- **User data:** discover persisted files, including users with no active terminals. **Delete user data** confirms, stops the user's tracked terminals, then deletes their files across policies and contexts. If terminals remain, files are preserved.
|
||||
- **Policies:** create or edit terminal settings, configure scheduled resets, and roll out changes to idle terminals.
|
||||
|
||||
Use the Terminals admin API key. Set `TERMINALS_ENABLE_UI=false` for an API-only deployment.
|
||||
|
||||
## Policies
|
||||
|
||||
Policies let you define different environments, for example, a "data-science" environment with extra CPU and specific Python packages, or a "sandbox" environment with restricted network access.
|
||||
|
||||
Without any policies, Terminals uses the defaults from your configuration. Once you're ready to customize, manage policies through the REST API:
|
||||
A policy defines a terminal's image, environment variables, and resource limits. The default proxy routes work without creating a policy. Add policies in the admin UI or through the API when you need different environments:
|
||||
|
||||
```bash
|
||||
# Create a "data-science" policy
|
||||
curl -X PUT http://localhost:3000/api/v1/policies/data-science \
|
||||
curl -fsS -X PUT http://localhost:3000/api/v1/policies/data-science \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"image": "ghcr.io/open-webui/open-terminal:python-ds",
|
||||
"image": "ghcr.io/open-webui/open-terminal:latest",
|
||||
"cpu_limit": "2",
|
||||
"memory_limit": "4Gi",
|
||||
"env": {
|
||||
"OPENAI_API_KEY": "sk-proj-...",
|
||||
"OPEN_TERMINAL_ALLOWED_DOMAINS": "*.pypi.org,github.com"
|
||||
},
|
||||
"idle_timeout_minutes": 30
|
||||
}'
|
||||
```
|
||||
|
||||
Route requests through a policy by adding `/p/{policy_id}/` to the URL:
|
||||
Use `/p/{policy_id}/` to route a request through that policy:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/p/data-science/execute \
|
||||
-H "Authorization: Bearer $API_KEY" -H "X-User-Id: user-123" \
|
||||
curl -fsS http://localhost:3000/p/data-science/execute \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "X-User-Id: demo-user" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"command": "echo hello"}'
|
||||
-d '{"command":"echo hello"}'
|
||||
```
|
||||
|
||||
### Policy fields
|
||||
| Field | Purpose |
|
||||
|-------|---------|
|
||||
| `image` | Open Terminal image to run |
|
||||
| `env` | Environment variables passed to the terminal |
|
||||
| `cpu_limit`, `memory_limit` | Resource limits, such as `"2"` and `"4Gi"` |
|
||||
| `storage` | Storage size, such as `"5Gi"`; behavior depends on the backend below |
|
||||
| `storage_mode` | Direct Kubernetes: `per-user`, `shared`, or `shared-rwo` |
|
||||
| `idle_timeout_minutes` | Stop terminals after this many idle minutes; `0` disables idle cleanup |
|
||||
| `restricted` | Restricted Kubernetes/OpenShift defaults |
|
||||
| `pod_security_context`, `container_security_context` | Kubernetes security context overrides |
|
||||
| `podTemplate` | Kubernetes pod overrides, including volumes, scheduling, and health probes |
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `image` | string | Container image to use |
|
||||
| `env` | dict | Environment variables passed to the container |
|
||||
| `cpu_limit` | string | Max CPU (e.g. `"2"`) |
|
||||
| `memory_limit` | string | Max memory (e.g. `"4Gi"`) |
|
||||
| `storage` | string | Persistent volume size (omit for ephemeral storage) |
|
||||
| `storage_mode` | string | `per-user`, `shared`, or `shared-rwo` |
|
||||
| `idle_timeout_minutes` | int | Minutes of inactivity before the container is cleaned up |
|
||||
| `restricted` | bool | Enable restricted Kubernetes/OpenShift pod defaults for this policy |
|
||||
| `pod_security_context` | dict | Pod security context override for Kubernetes backends |
|
||||
| `container_security_context` | dict | Container security context override for Kubernetes backends |
|
||||
Service limits such as `TERMINALS_MAX_CPU`, `TERMINALS_MAX_MEMORY`, and `TERMINALS_ALLOWED_IMAGES` constrain policy settings.
|
||||
|
||||
> [!NOTE]
|
||||
> **Storage limits are fully enforced only on the Kubernetes backends** (via sized PVCs). On the `docker` backend, `storage` (and `TERMINALS_MAX_STORAGE`) caps the container's *writable layer* via Docker's `StorageOpt`, which requires a storage driver that supports it (e.g. overlay2 on XFS with the `pquota` mount option). On unsupported drivers such as overlay2-on-ext4, Terminals logs a warning and provisions without the limit. The persistent `/home/user` directory is bind-mounted from the host and is **not** quota-limited on Docker. Use a Kubernetes backend if you need hard per-user storage caps.
|
||||
### Apply changes to existing terminals
|
||||
|
||||
Changes take effect when a terminal is next provisioned. Use the policy's rollout action in the UI, or:
|
||||
|
||||
```bash
|
||||
curl -fsS -X POST http://localhost:3000/api/v1/terminals/refresh \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"policy_id":"data-science","only_idle":true}'
|
||||
```
|
||||
|
||||
`only_idle` defaults to `true`. Set it to `false` to stop active terminals too. Add `user_id` or `context_id` to narrow the selection. Files are preserved unless you explicitly set `reset:true`.
|
||||
|
||||
### Schedule file resets
|
||||
|
||||
Scheduled resets delete persisted terminal files and refresh matching terminals, including active ones. Configure them in the policy editor or with:
|
||||
|
||||
```bash
|
||||
curl -fsS -X PUT http://localhost:3000/api/v1/policies/data-science/lifecycle \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"reset":{"schedule":"@weekly","timezone":"UTC"}}'
|
||||
```
|
||||
|
||||
Schedules support one-time ISO datetimes, `@weekly`, `@monthly`, and five-field cron expressions. Docker clears the matching home directory. Kubernetes uses a reset pod to clear the matching PVC or user subdirectory.
|
||||
|
||||
## Storage and persistence
|
||||
|
||||
Stopping or reaping a terminal preserves its persisted files. Idle cleanup is disabled by default; enable it with `TERMINALS_IDLE_TIMEOUT_MINUTES` or a policy. File resets and user-data deletion are separate, destructive actions.
|
||||
|
||||
| Backend | Persisted terminal files |
|
||||
|---------|-------------------------|
|
||||
| Docker | Bind-mounted under `TERMINALS_DOCKER_DATA_DIR`, regardless of the policy's `storage` field |
|
||||
| Kubernetes | PVCs; defaults to `1Gi` per terminal, with optional shared storage modes |
|
||||
| Kubernetes operator | Set `storage` in the policy to create a dedicated PVC; omitting it uses ephemeral storage |
|
||||
|
||||
### Docker paths
|
||||
|
||||
The quick start mounts the host's `./data` directory at `/app/data`:
|
||||
|
||||
| Host path | Container path | Contents |
|
||||
|-----------|----------------|----------|
|
||||
| `./data/terminals.db` | `/app/data/terminals.db` | SQLite database: policies and lifecycle state |
|
||||
| `./data/terminals/` | `/app/data/terminals/` | Users' terminal files, including chat and automation contexts |
|
||||
|
||||
`TERMINALS_DOCKER_HOST_DATA_DIR` tells the Docker daemon where those same terminal files live on its host. It is optional when the orchestrator and daemon use the same path. Both paths must refer to the same storage so provisioning, resets, and deletion operate on the same files. The quick start assumes a local Docker daemon.
|
||||
|
||||
Back up the database and terminal files before upgrades. Changing paths does not migrate existing data or change mounts on existing containers. Move data from its previous effective location before changing the configuration.
|
||||
|
||||
### Storage limits
|
||||
|
||||
On Kubernetes, `storage` sets the requested PVC size. On Docker it caps only the container's writable layer, and only when the storage driver supports `StorageOpt` (for example, overlay2 on XFS with `pquota`). Unsupported drivers log a warning and run without that limit. The bind-mounted `/home/user` directory is not covered by Docker's limit.
|
||||
|
||||
Terminal files need a filesystem. Open WebUI's uploaded-file storage and Azure Blob cleanup do not manage them. For Azure, use Azure Files, managed disks, or Kubernetes PVCs for terminal homes.
|
||||
|
||||
### Delete a user's files
|
||||
|
||||
Deleting an account in Open WebUI does not notify Terminals. After revoking that user's access, use **User data → Delete user data** in the admin UI.
|
||||
|
||||
For API-based cleanup, list users with `GET /api/v1/terminals/data`, stop their terminals through `/api/v1/terminals/refresh` with `user_id` and `only_idle:false`, then call:
|
||||
|
||||
```bash
|
||||
curl -fsS -X POST http://localhost:3000/api/v1/terminals/cleanup \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"user_id":"deleted-user-id"}'
|
||||
```
|
||||
|
||||
Cleanup removes the user's Docker directory or requests deletion of their labeled per-user PVCs, clears lifecycle records, and logs each storage deletion. It works after idle terminals have been reaped. Repeating the call is safe. It waits for terminating Kubernetes resources and returns `409` if terminal resources remain; remove them before retrying.
|
||||
|
||||
Shared PVCs need separate cleanup of the user's subdirectory and are not listed in the UI. The cleanup endpoint refuses deletion when shared storage exists. PVC removal follows the storage class's reclaim policy; retained volumes and backups need separate removal.
|
||||
|
||||
## Kubernetes deployment
|
||||
|
||||
| Backend | Use when |
|
||||
|---------|----------|
|
||||
| `docker` | Running on a single Docker host; the quick-start default |
|
||||
| `kubernetes-operator` | An operator should manage `Terminal` custom resources |
|
||||
| `kubernetes` | Terminals should manage Pods, PVCs, and Services directly, without a CRD |
|
||||
|
||||
From a checkout of this repository, install the operator:
|
||||
|
||||
```bash
|
||||
kubectl apply -f manifests/terminal-crd.yaml
|
||||
kubectl apply -f manifests/operator-deployment.yaml
|
||||
```
|
||||
|
||||
These commands install the operator, not the Terminals API service. Deploy `ghcr.io/open-webui/terminals:latest` separately with:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
- name: TERMINALS_BACKEND
|
||||
value: kubernetes-operator
|
||||
- name: TERMINALS_KUBERNETES_NAMESPACE
|
||||
value: terminals
|
||||
- name: TERMINALS_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: terminals
|
||||
key: api-key
|
||||
```
|
||||
|
||||
Create the referenced Secret, mount persistent storage at `/app/data` for SQLite, and give the service account the backend's required Kubernetes permissions. The operator RBAC is in [operator-deployment.yaml](manifests/operator-deployment.yaml). Expose the Terminals service on port `3000` to Open WebUI. Add `"storage":"5Gi"` to operator policies that need persistent files.
|
||||
|
||||
For direct Kubernetes provisioning, use `TERMINALS_BACKEND=kubernetes`; no operator or CRD is required. For restricted OpenShift clusters, follow [OpenShift deployment](docs/openshift.md).
|
||||
|
||||
## Authentication
|
||||
|
||||
The quick start uses a static `TERMINALS_API_KEY` for both the admin UI and Open WebUI's Bearer connection. Keep it on trusted servers: API-key requests trust the supplied `X-User-Id` to select the user.
|
||||
|
||||
For Open WebUI session authentication, set `TERMINALS_OPEN_WEBUI_URL` and use **Session** auth on the Open WebUI terminal connection. Terminals validates user tokens against that instance. Admin policy and lifecycle APIs still require a separate Terminals admin API key; user JWTs are not enough.
|
||||
|
||||
`terminals serve` generates and prints a key if none is configured. That generated key changes when the service process restarts. Running the ASGI app directly without either authentication setting allows unauthenticated access and is intended only for local development.
|
||||
|
||||
## Configuration
|
||||
|
||||
All settings are configured through environment variables prefixed with `TERMINALS_`, or via a `.env` file.
|
||||
|
||||
### Common
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_BACKEND` | `docker` | `docker`, `kubernetes`, or `kubernetes-operator` |
|
||||
| `TERMINALS_API_KEY` | *(auto-generated)* | Bearer token for API auth |
|
||||
| `TERMINALS_OPEN_WEBUI_URL` | | Advanced Open WebUI integration mode. If set, Terminals validates Open WebUI JWTs against that instance. Requires an Open WebUI terminal connection using session auth. |
|
||||
| `TERMINALS_HOST` | `0.0.0.0` | Orchestrator API bind host |
|
||||
| `TERMINALS_PORT` | `3000` | Orchestrator API bind port |
|
||||
| `TERMINALS_WORKERS` | `1` | Uvicorn worker process count. Docker workers adopt existing per-user containers by deterministic name instead of replacing them. |
|
||||
| `TERMINALS_ENABLE_UI` | `true` | Serve the built-in minimal admin UI at `/`. Set to `false` for API-only deployments. |
|
||||
| `TERMINALS_IMAGE` | `ghcr.io/open-webui/open-terminal:latest` | Default Open Terminal container image |
|
||||
| `TERMINALS_MAX_CPU` | | Hard cap on CPU per terminal container/pod |
|
||||
| `TERMINALS_MAX_MEMORY` | | Hard cap on memory per terminal container/pod |
|
||||
| `TERMINALS_MAX_STORAGE` | | Storage cap. Kubernetes enforces this with PVC sizes; Docker support depends on the storage driver and does not quota the bind-mounted `/home/user`. |
|
||||
| `TERMINALS_ALLOWED_IMAGES` | | Comma-separated list of allowed image patterns |
|
||||
| `TERMINALS_IDLE_TIMEOUT_MINUTES` | `0` | Minutes of inactivity before terminals are torn down. `0` disables idle cleanup. |
|
||||
| `TERMINALS_IDLE_CLEANUP_TIMEOUT_SECONDS` | `120` | Timeout for each teardown/reset call during idle cleanup |
|
||||
| `TERMINALS_DATABASE_URL` | `sqlite+aiosqlite:////app/data/terminals.db` in the image | SQLAlchemy database URL. Source installs use `data/terminals.db` next to the package directory. PostgreSQL is optional. |
|
||||
| `TERMINALS_LOG_LEVEL` | `INFO` | Minimum orchestrator log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`. On Docker, `WARNING` or higher disables child container Docker logs because Open Terminal does not expose a log-level env var. |
|
||||
| `TERMINALS_STATUS_CACHE_TTL` | `30` | Seconds a confirmed-running container status is trusted before re-inspecting it via the backend. `0` re-checks on every request. |
|
||||
| `TERMINALS_TOKEN_CACHE_TTL` | `60` | Seconds a successfully validated Open WebUI token is cached (JWT mode only). A revoked token stays usable for up to the TTL; `0` validates every request. |
|
||||
| `TERMINALS_WS_COMPRESSION` | `false` | Enable permessage-deflate on proxied WebSocket terminal traffic. Leave off unless clients connect over slow links. |
|
||||
| `TERMINALS_ACCESS_LOG` | `false` | Log every HTTP request. Off by default because per-request logging is expensive at high request rates. |
|
||||
| `TERMINALS_REPLAY_BODY_LIMIT` | | Maximum proxied request body bytes buffered for retry. Unset, `none`, `null`, or `unlimited` means no size cap. |
|
||||
| `TERMINALS_PROXY_CONNECT_TIMEOUT_SECONDS` | `10` | Timeout for opening upstream proxy connections to terminal containers |
|
||||
| `TERMINALS_PROXY_READ_TIMEOUT_SECONDS` | `360` | Timeout while waiting for upstream proxy responses. Keep above Open Terminal's maximum `/execute?wait` value. |
|
||||
| `TERMINALS_PROXY_WRITE_TIMEOUT_SECONDS` | `300` | Timeout while sending proxied request bodies upstream |
|
||||
| `TERMINALS_PROXY_POOL_TIMEOUT_SECONDS` | `300` | Timeout while waiting for an upstream proxy connection from the pool |
|
||||
| `TERMINALS_PROVISION_TIMEOUT_SECONDS` | `120` | Timeout waiting for terminal readiness on the `kubernetes-operator` backend |
|
||||
|
||||
### Docker
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_DOCKER_HOST` | `127.0.0.1` | Host/IP that the orchestrator uses to reach published terminal container ports |
|
||||
| `TERMINALS_DOCKER_NETWORK` | | Docker network for terminal containers. Use a comma-separated list to shard terminals across multiple Docker bridge networks. |
|
||||
| `TERMINALS_DOCKER_MOUNTS` | | JSON array of extra bind mounts with `source`, `target`, and optional `readOnly` |
|
||||
| `TERMINALS_DOCKER_DATA_DIR` | `data/terminals` (`/app/data/terminals` in the image) | Workspace directory accessible to the orchestrator, including file resets |
|
||||
| `TERMINALS_DOCKER_HOST_DATA_DIR` | | Optional absolute Docker-host path to the same workspace directory. Unset uses `TERMINALS_DOCKER_DATA_DIR`. |
|
||||
|
||||
### Kubernetes
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_KUBERNETES_NAMESPACE` | `terminals` | Namespace for terminal pods, services, PVCs, and CRDs |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_CLASS` | | Storage class for terminal PVCs. Empty uses the cluster default. |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_SIZE` | `1Gi` | Default PVC size for the direct `kubernetes` backend; operator policies must set `storage` for persistence |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_MODE` | `per-user` | Direct Kubernetes storage mode: `per-user`, `shared`, or `shared-rwo`; the operator creates dedicated PVCs |
|
||||
| `TERMINALS_KUBERNETES_SERVICE_TYPE` | `ClusterIP` | Service type for terminal services |
|
||||
| `TERMINALS_KUBERNETES_KUBECONFIG` | | Kubeconfig path. Empty uses in-cluster config. |
|
||||
| `TERMINALS_KUBERNETES_LABELS` | | Extra labels for terminal resources, as `k=v,k2=v2` |
|
||||
| `TERMINALS_KUBERNETES_RESTRICTED` | `false` | Enable restricted Kubernetes/OpenShift pod defaults globally |
|
||||
| `TERMINALS_KUBERNETES_POD_SECURITY_CONTEXT` | | JSON pod security context merged into terminal pods |
|
||||
| `TERMINALS_KUBERNETES_CONTAINER_SECURITY_CONTEXT` | | JSON container security context merged into terminal containers |
|
||||
| `TERMINALS_KUBERNETES_NODE_SELECTOR` | | Node selector for terminal and reset pods, as JSON or `k=v,k2=v2` |
|
||||
| `TERMINALS_KUBERNETES_TOLERATIONS` | | JSON array of tolerations for terminal and reset pods |
|
||||
|
||||
### Kubernetes operator
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_KUBERNETES_CRD_GROUP` | `openwebui.com` | Terminal CRD API group |
|
||||
| `TERMINALS_KUBERNETES_CRD_VERSION` | `v1alpha1` | Terminal CRD API version |
|
||||
|
||||
These tables are the public environment-variable surface. Compatibility-only
|
||||
settings may still be accepted by the code but are intentionally omitted.
|
||||
|
||||
By default, known-size proxied request bodies are buffered so retry behavior is preserved. Set `TERMINALS_REPLAY_BODY_LIMIT` to stream request bodies above that byte limit instead of buffering them in orchestrator memory. Chunked uploads are always streamed one-shot and are not retried.
|
||||
|
||||
## Advanced configuration
|
||||
|
||||
### Extra mounts
|
||||
|
||||
### Extra mounts: Docker vs Kubernetes
|
||||
|
||||
Docker deployments can use `TERMINALS_DOCKER_MOUNTS` to mount shared data into
|
||||
every spawned terminal container:
|
||||
@@ -165,6 +380,7 @@ boundary if terminal containers are privileged or can access the Docker socket.
|
||||
|
||||
### Kubernetes health probes
|
||||
|
||||
|
||||
Both Kubernetes backends accept probe overrides in the policy's `podTemplate`.
|
||||
Each supplied probe replaces the default, so include its check (such as
|
||||
`httpGet`) as well as timing settings. For slower hardware:
|
||||
@@ -197,176 +413,38 @@ Each supplied probe replaces the default, so include its check (such as
|
||||
Omitted probes keep their existing defaults. Refresh existing terminals to apply
|
||||
the updated policy on their next access.
|
||||
|
||||
### Policy lifecycle
|
||||
### Docker network scaling
|
||||
|
||||
Policies define what gets provisioned. Policy lifecycle config defines ongoing maintenance for that policy, such as scheduled resets of persisted terminal files. Due resets refresh matching terminals even when they are still running, so long-lived browser sessions do not block scheduled cleanup.
|
||||
For larger Docker deployments, create multiple bridge networks and set `TERMINALS_DOCKER_NETWORK` to a comma-separated list. Terminals assigns each user/policy/context to a stable network. Attach the orchestrator container to every listed network so it can reach terminals by name.
|
||||
|
||||
Use policy lifecycle resets for enterprise workspace retention. Open Terminal
|
||||
containers need a real filesystem for commands and file APIs, so Open WebUI's
|
||||
file storage provider and Azure Blob cleanup do not manage terminal workspace
|
||||
contents. Put terminal homes on the backend storage for this service, then reset
|
||||
them through Terminals policy lifecycle.
|
||||
## Troubleshooting
|
||||
|
||||
| Problem | What to check |
|
||||
|---------|---------------|
|
||||
| Admin UI shows `401` | Paste the Terminals API key, then click Refresh. Use the saved key, not an Open WebUI user token. |
|
||||
| Open WebUI cannot connect | Use `http://terminals:3000` on the shared Docker network. Inside a container, `localhost` refers to that container. |
|
||||
| First terminal is slow or fails | Check `docker logs terminals`; the configured terminal image must be available or pullable. |
|
||||
| Files disappear after recreating the service | Check the `/app/data` bind mount and both Docker data paths. Keep the same host directory across recreations. |
|
||||
| Kubernetes terminal files disappear after idle cleanup | For the operator backend, set `storage` in the policy so files live on a PVC. |
|
||||
| User-data deletion returns `409` | Terminal resources still exist or shared storage needs separate handling. Check the returned error; files are not deleted while terminals remain. |
|
||||
| UI is unavailable in a source install | Build the frontend and ensure `TERMINALS_ENABLE_UI` is not `false`. |
|
||||
|
||||
## Development
|
||||
|
||||
Use Python 3.11+ and Node.js 22.12+:
|
||||
|
||||
```bash
|
||||
curl -X PUT http://localhost:3000/api/v1/policies/data-science/lifecycle \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"reset": {
|
||||
"schedule": "@weekly",
|
||||
"timezone": "UTC"
|
||||
}
|
||||
}'
|
||||
git clone https://github.com/open-webui/terminals.git
|
||||
cd terminals
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -e .
|
||||
npm --prefix terminals/frontend ci
|
||||
npm --prefix terminals/frontend run build
|
||||
terminals serve
|
||||
```
|
||||
|
||||
Reset schedules support one-time ISO datetimes, `@weekly`, `@monthly`, and 5-field cron expressions.
|
||||
|
||||
Backend reset behavior:
|
||||
|
||||
- Docker removes the matching user's bind-mounted home directory contents under `TERMINALS_DOCKER_DATA_DIR`.
|
||||
- Kubernetes runs a reset pod that clears `/home/user` on the matching PVC or shared-PVC subPath.
|
||||
- Kubernetes operator runs a reset pod that clears the Terminal CR's PVC.
|
||||
|
||||
For Azure deployments, use Azure Files, managed disks, or Kubernetes PVCs for
|
||||
terminal homes. Azure Blob is suitable for Open WebUI uploaded file records, not
|
||||
as the live filesystem used by a running terminal.
|
||||
|
||||
### Applying policy changes
|
||||
|
||||
Policy updates apply to newly provisioned terminals. To stop matching terminals
|
||||
so the next access starts with the current image, env, and resource settings:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/v1/terminals/refresh \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"policy_id":"data-science","only_idle":true}'
|
||||
```
|
||||
|
||||
Use `user_id` to target one user, `policy_id` to target one policy, and
|
||||
`reset:true` to wipe the matched users' persisted files while
|
||||
refreshing. `only_idle` defaults to `true` so active users are not
|
||||
interrupted.
|
||||
|
||||
### Cleaning up a deleted user's data
|
||||
|
||||
Deleting an Open WebUI account does not notify Terminals. After revoking the
|
||||
user's access, find them in the admin UI's **User data** table and select
|
||||
**Delete user data**. Confirmation stops their tracked terminals, waits for
|
||||
terminating resources, and deletes their persisted terminal files. If terminals
|
||||
remain, cleanup fails without deleting files.
|
||||
|
||||
The table discovers users from Docker data directories or labeled per-user PVCs,
|
||||
including users with no active terminals. The same list is available through
|
||||
`GET /api/v1/terminals/data`. To clean up through the API, stop the user's terminals
|
||||
first, then call:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/v1/terminals/cleanup \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"user_id":"deleted-user-id"}'
|
||||
```
|
||||
|
||||
This permanently deletes the user's Docker workspace (including all chat and
|
||||
automation contexts) or requests deletion of their labeled per-user PVCs, even
|
||||
when no terminal is tracked. It also removes their lifecycle state and logs each
|
||||
storage deletion. The response counts deleted workspace directories or PVC
|
||||
deletion requests; repeating cleanup is safe. The endpoint returns `409` while
|
||||
terminal resources remain. The existing refresh endpoint with `user_id` and
|
||||
`only_idle:false` can stop tracked terminals; remove any remaining resources
|
||||
before retrying cleanup.
|
||||
|
||||
Shared Kubernetes PVCs require clearing only the user's subdirectory separately;
|
||||
this endpoint refuses cleanup when shared storage exists. PVC deletion follows
|
||||
the storage class's reclaim policy, so retained volumes and backups require
|
||||
separate removal. Account deletion workflows can call this endpoint explicitly;
|
||||
failed authentication never triggers data deletion.
|
||||
|
||||
## Configuration
|
||||
|
||||
All settings are configured through environment variables prefixed with `TERMINALS_`, or via a `.env` file.
|
||||
|
||||
### Common settings
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_BACKEND` | `docker` | `docker`, `kubernetes`, or `kubernetes-operator` |
|
||||
| `TERMINALS_API_KEY` | *(auto-generated)* | Bearer token for API auth |
|
||||
| `TERMINALS_OPEN_WEBUI_URL` | | Advanced Open WebUI integration mode. If set, Terminals validates Open WebUI JWTs against that instance. Requires an Open WebUI terminal connection using session auth. |
|
||||
| `TERMINALS_HOST` | `0.0.0.0` | Orchestrator API bind host |
|
||||
| `TERMINALS_PORT` | `3000` | Orchestrator API bind port |
|
||||
| `TERMINALS_WORKERS` | `1` | Uvicorn worker process count. Docker workers adopt existing per-user containers by deterministic name instead of replacing them. |
|
||||
| `TERMINALS_ENABLE_UI` | `true` | Serve the built-in minimal admin UI at `/`. Set to `false` for API-only deployments. |
|
||||
| `TERMINALS_IMAGE` | `ghcr.io/open-webui/open-terminal:latest` | Default Open Terminal container image |
|
||||
| `TERMINALS_MAX_CPU` | | Hard cap on CPU per terminal container/pod |
|
||||
| `TERMINALS_MAX_MEMORY` | | Hard cap on memory per terminal container/pod |
|
||||
| `TERMINALS_MAX_STORAGE` | | Storage cap. Kubernetes enforces this with PVC sizes; Docker support depends on the storage driver and does not quota the bind-mounted `/home/user`. |
|
||||
| `TERMINALS_ALLOWED_IMAGES` | | Comma-separated list of allowed image patterns |
|
||||
| `TERMINALS_IDLE_TIMEOUT_MINUTES` | `0` | Minutes of inactivity before terminals are torn down. `0` disables idle cleanup. |
|
||||
| `TERMINALS_IDLE_CLEANUP_TIMEOUT_SECONDS` | `120` | Timeout for each teardown/reset call during idle cleanup |
|
||||
| `TERMINALS_DATABASE_URL` | `sqlite+aiosqlite:///.../data/terminals.db` | SQLAlchemy database URL. SQLite is the default; PostgreSQL is optional. |
|
||||
| `TERMINALS_LOG_LEVEL` | `INFO` | Minimum orchestrator log level: `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL`. On Docker, `WARNING` or higher disables child container Docker logs because Open Terminal does not expose a log-level env var. |
|
||||
| `TERMINALS_STATUS_CACHE_TTL` | `30` | Seconds a confirmed-running container status is trusted before re-inspecting it via the backend. `0` re-checks on every request. |
|
||||
| `TERMINALS_TOKEN_CACHE_TTL` | `60` | Seconds a successfully validated Open WebUI token is cached (JWT mode only). A revoked token stays usable for up to the TTL; `0` validates every request. |
|
||||
| `TERMINALS_WS_COMPRESSION` | `false` | Enable permessage-deflate on proxied WebSocket terminal traffic. Leave off unless clients connect over slow links. |
|
||||
| `TERMINALS_ACCESS_LOG` | `false` | Log every HTTP request. Off by default because per-request logging is expensive at high request rates. |
|
||||
| `TERMINALS_REPLAY_BODY_LIMIT` | | Maximum proxied request body bytes buffered for retry. Unset, `none`, `null`, or `unlimited` means no size cap. |
|
||||
| `TERMINALS_PROXY_CONNECT_TIMEOUT_SECONDS` | `10` | Timeout for opening upstream proxy connections to terminal containers |
|
||||
| `TERMINALS_PROXY_READ_TIMEOUT_SECONDS` | `360` | Timeout while waiting for upstream proxy responses. Keep above Open Terminal's maximum `/execute?wait` value. |
|
||||
| `TERMINALS_PROXY_WRITE_TIMEOUT_SECONDS` | `300` | Timeout while sending proxied request bodies upstream |
|
||||
| `TERMINALS_PROXY_POOL_TIMEOUT_SECONDS` | `300` | Timeout while waiting for an upstream proxy connection from the pool |
|
||||
| `TERMINALS_PROVISION_TIMEOUT_SECONDS` | `120` | Timeout waiting for terminal readiness on the `kubernetes-operator` backend |
|
||||
|
||||
### Docker-only settings
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_DOCKER_HOST` | `127.0.0.1` | Host/IP that the orchestrator uses to reach published terminal container ports |
|
||||
| `TERMINALS_DOCKER_NETWORK` | | Docker network for terminal containers. Use a comma-separated list to shard terminals across multiple Docker bridge networks. |
|
||||
| `TERMINALS_DOCKER_MOUNTS` | | JSON array of extra bind mounts with `source`, `target`, and optional `readOnly` |
|
||||
| `TERMINALS_DOCKER_DATA_DIR` | `data/terminals` (`/app/data/terminals` in the image) | Workspace directory accessible to the orchestrator, including file resets |
|
||||
| `TERMINALS_DOCKER_HOST_DATA_DIR` | | Optional absolute Docker-host path to the same workspace directory. Unset uses `TERMINALS_DOCKER_DATA_DIR`. |
|
||||
|
||||
### Kubernetes-only settings
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_KUBERNETES_NAMESPACE` | `terminals` | Namespace for terminal pods, services, PVCs, and CRDs |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_CLASS` | | Storage class for terminal PVCs. Empty uses the cluster default. |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_SIZE` | `1Gi` | Default PVC size when a policy does not set `storage` |
|
||||
| `TERMINALS_KUBERNETES_STORAGE_MODE` | `per-user` | Storage mode: `per-user`, `shared`, or `shared-rwo` |
|
||||
| `TERMINALS_KUBERNETES_SERVICE_TYPE` | `ClusterIP` | Service type for terminal services |
|
||||
| `TERMINALS_KUBERNETES_KUBECONFIG` | | Kubeconfig path. Empty uses in-cluster config. |
|
||||
| `TERMINALS_KUBERNETES_LABELS` | | Extra labels for terminal resources, as `k=v,k2=v2` |
|
||||
| `TERMINALS_KUBERNETES_RESTRICTED` | `false` | Enable restricted Kubernetes/OpenShift pod defaults globally |
|
||||
| `TERMINALS_KUBERNETES_POD_SECURITY_CONTEXT` | | JSON pod security context merged into terminal pods |
|
||||
| `TERMINALS_KUBERNETES_CONTAINER_SECURITY_CONTEXT` | | JSON container security context merged into terminal containers |
|
||||
| `TERMINALS_KUBERNETES_NODE_SELECTOR` | | Node selector for terminal and reset pods, as JSON or `k=v,k2=v2` |
|
||||
| `TERMINALS_KUBERNETES_TOLERATIONS` | | JSON array of tolerations for terminal and reset pods |
|
||||
|
||||
### Kubernetes-operator-only settings
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `TERMINALS_KUBERNETES_CRD_GROUP` | `openwebui.com` | Terminal CRD API group |
|
||||
| `TERMINALS_KUBERNETES_CRD_VERSION` | `v1alpha1` | Terminal CRD API version |
|
||||
|
||||
These tables are the public environment-variable surface. Compatibility-only
|
||||
settings may still be accepted by the code but are intentionally omitted.
|
||||
|
||||
By default, known-size proxied request bodies are buffered so retry behavior is preserved. Set `TERMINALS_REPLAY_BODY_LIMIT` to stream request bodies above that byte limit instead of buffering them in orchestrator memory. Chunked uploads are always streamed one-shot and are not retried.
|
||||
|
||||
### Docker bridge scaling
|
||||
|
||||
Docker documents that bridge networks can become unstable when 1000 or more containers connect to a single network. For larger single-node Docker deployments, create multiple bridge networks and set `TERMINALS_DOCKER_NETWORK` to a comma-separated list; Terminals assigns each user/policy terminal to a stable network shard. The orchestrator container must be attached to every listed network so it can reach terminals by container name.
|
||||
|
||||
## Authentication
|
||||
|
||||
| Mode | How to enable |
|
||||
|------|---------------|
|
||||
| **API Key** | Set `TERMINALS_API_KEY` to a static token |
|
||||
| **Open (dev only)** | Leave unset, no auth, for local development only |
|
||||
Docker must be available when using the default backend. The command prints the generated API key; open `http://localhost:3000` to use the admin UI. During frontend development, run `npm --prefix terminals/frontend run dev`; its API proxy targets the backend on port `3000`.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in new issue
Block a user