Skip to content

Commit df9fa45

Browse files
authored
Merge pull request #526 from linagora/feat/ray-external-cluster-address
feat(api): connect to an external Ray cluster via RAY_ADDRESS
2 parents e9da333 + aa015bd commit df9fa45

6 files changed

Lines changed: 33 additions & 3 deletions

File tree

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ RAY_task_retry_delay_ms=3000
7474
RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 # critical with the newest version of UV
7575
# # To disable worker killing
7676
# RAY_memory_monitor_refresh_ms=0
77+
# Connect to an external Ray cluster instead of starting an embedded one.
78+
# When set, the app attaches to this cluster and does NOT start a local dashboard
79+
# (the head node owns it). See docs/documentation/deploy_ray_cluster.
80+
# RAY_ADDRESS=ray://X.X.X.X:10001
81+
# Interface the embedded Ray dashboard binds to. Defaults to 127.0.0.1 (loopback)
82+
# because the dashboard/job API is unauthenticated (CVE-2023-48022). Set to 0.0.0.0
83+
# only when the port is firewalled or behind an auth proxy. Ignored when RAY_ADDRESS is set.
84+
# RAY_DASHBOARD_HOST=127.0.0.1
7785

7886
# Indexer UI
7987
## 1. replace X.X.X.X with localhost if launching local or with your server IP

docs/assets/env_example.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ RAY_DEDUP_LOGS=0 # turns off ray log deduplication that appear across multiple p
4343
RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING=1 # # to enable logs at task level in ray dashboard
4444
RAY_task_retry_delay_ms=3000
4545
RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 # critical with the newest version of UV
46+
# Attach to an external Ray cluster instead of starting an embedded one (disables the local dashboard).
47+
# RAY_ADDRESS=ray://X.X.X.X:10001
48+
# Interface the embedded Ray dashboard binds to. Defaults to 127.0.0.1 (loopback) because the
49+
# dashboard/job API is unauthenticated (CVE-2023-48022). Set 0.0.0.0 only behind a firewall/auth proxy.
50+
# RAY_DASHBOARD_HOST=127.0.0.1
4651

4752
# Indexer UI
4853
## 1. replace X.X.X.X with localhost if launching local or with your server IP

docs/assets/env_linux_gpu.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ RAY_DEDUP_LOGS=0 # turns off ray log deduplication that appear across multiple p
3939
RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING=1 # # to enable logs at task level in ray dashboard
4040
RAY_task_retry_delay_ms=3000
4141
RAY_ENABLE_UV_RUN_RUNTIME_ENV=0 # critical with the newest version of UV
42+
# Attach to an external Ray cluster instead of starting an embedded one (disables the local dashboard).
43+
# RAY_ADDRESS=ray://X.X.X.X:10001
44+
# Interface the embedded Ray dashboard binds to. Defaults to 127.0.0.1 (loopback) because the
45+
# dashboard/job API is unauthenticated (CVE-2023-48022). Set 0.0.0.0 only behind a firewall/auth proxy.
46+
# RAY_DASHBOARD_HOST=127.0.0.1
4247

4348
# Indexer UI
4449
## 1. replace X.X.X.X with localhost if launching local or with your server IP

docs/content/docs/documentation/deploy_ray_cluster.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ docker compose up -d
136136

137137
Once running, **OpenRAG will auto-connect** to the Ray cluster using `RAY_ADDRESS` from `.env`.
138138

139+
:::note
140+
When `RAY_ADDRESS` is set, the app **attaches** to the external cluster and does **not** start its own embedded Ray dashboard — the head node owns it (started above via `--dashboard-host 0.0.0.0 --dashboard-port ${RAY_DASHBOARD_PORT:-8265}`). The app-side `RAY_DASHBOARD_HOST` setting is only used in embedded (single-node) mode, where it defaults to `127.0.0.1` because the dashboard API is unauthenticated ([CVE-2023-48022](https://nvd.nist.gov/vuln/detail/CVE-2023-48022)).
141+
:::
142+
139143
---
140144

141145
With this setup, your app is now fully distributed and ready to handle concurrent tasks across your Ray cluster.

docs/content/docs/documentation/env_vars.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ Ray is used for distributed task processing and parallel execution in the RAG pi
350350
| `RAY_POOL_SIZE` | `int` | 1 | Number of serializer actor instances (typically 1 actor per cluster node) |
351351
| `RAY_MAX_TASKS_PER_WORKER` | `int` | 8 | Maximum number of concurrent tasks (serialization tasks) per serializer actor instance |
352352
| `RAY_DASHBOARD_PORT` | `int` | 8265 | Ray Dashboard port used for monitoring. In production, [comment out this line](https://github.com/linagora/openrag/blob/ee732ea8e080dcde0107d62d12703a7525f810cd/docker-compose.yaml#L21C1-L22C1) to avoid exposing the port, as it may introduce security vulnerabilities. |
353+
| `RAY_DASHBOARD_HOST` | `str` | `127.0.0.1` | Interface the **embedded** Ray dashboard binds to. Defaults to loopback because the Ray dashboard/job-submission API is **unauthenticated** ([CVE-2023-48022](https://nvd.nist.gov/vuln/detail/CVE-2023-48022)). Set to `0.0.0.0` only when the dashboard port is firewalled or sits behind an authenticating proxy. Ignored when `RAY_ADDRESS` is set. |
354+
| `RAY_ADDRESS` | `str` | (unset) | When set, attach to an **external** Ray cluster at this address (e.g. `ray://HEAD_IP:10001`) instead of starting an embedded cluster in-process. In this mode the app does not start a local dashboard — the head node owns it. See [Ray Cluster deployment](/openrag/documentation/deploy_ray_cluster/). |
353355

354356
:::danger[Attention]
355357
The following environment variables control Ray's logging behavior, task retry settings. These are not set by default and must be supplied [as suggested in the .env](/openrag/getting_started/quickstart#2-create-a-env-file)

openrag/api.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515
from fastapi.openapi.utils import get_openapi
1616
from fastapi.responses import JSONResponse, RedirectResponse
1717

18-
# Bind the Ray dashboard to localhost; it's unauthenticated (CVE-2023-48022).
19-
# Override with RAY_DASHBOARD_HOST (e.g. behind an auth proxy).
20-
ray.init(dashboard_host=os.environ.get("RAY_DASHBOARD_HOST", "127.0.0.1"))
18+
_ray_address = os.environ.get("RAY_ADDRESS")
19+
if _ray_address:
20+
# Connect to an external Ray cluster (e.g. a dedicated ray-head container).
21+
ray.init(address=_ray_address)
22+
else:
23+
# Embedded mode: start a local Ray cluster inside this process.
24+
# Bind the Ray dashboard to localhost; it's unauthenticated (CVE-2023-48022).
25+
# Override with RAY_DASHBOARD_HOST (e.g. behind an auth proxy).
26+
ray.init(dashboard_host=os.environ.get("RAY_DASHBOARD_HOST", "127.0.0.1"))
2127

2228
# Apply noqa: E402 to ignore "module level import not at top of file" cause ray.init has to be called first
2329

0 commit comments

Comments
 (0)