-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(security): bind Ollama to localhost instead of 0.0.0.0 #1140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2748,7 +2748,20 @@ async function setupNim(gpu) { | |
| console.log(" Installing Ollama via Homebrew..."); | ||
| run("brew install ollama", { ignoreError: true }); | ||
| console.log(" Starting Ollama..."); | ||
| run("OLLAMA_HOST=0.0.0.0:11434 ollama serve > /dev/null 2>&1 &", { ignoreError: true }); | ||
| // On macOS, Docker Desktop routes host-gateway through the VM so | ||
| // 127.0.0.1 is reachable from containers — bind to localhost to | ||
| // avoid exposing Ollama to the LAN (CWE-668, NVBUG 6014821). | ||
| // On Linux, containers access the host via the Docker bridge IP | ||
| // so 0.0.0.0 is required for reachability. | ||
| // On WSL2, the default binding works without override. | ||
| let ollamaEnv = ""; | ||
| if (!isWsl()) { | ||
| ollamaEnv = | ||
| process.platform === "darwin" | ||
| ? "OLLAMA_HOST=127.0.0.1:11434 " | ||
| : "OLLAMA_HOST=0.0.0.0:11434 "; | ||
| } | ||
| run(`${ollamaEnv}ollama serve > /dev/null 2>&1 &`, { ignoreError: true }); | ||
|
Comment on lines
+2751
to
+2764
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reuse the bind-selection logic in both Ollama launch paths. Line 2334 makes 💡 Suggested fix+function getOllamaServeEnvPrefix() {
+ if (isWsl()) return "";
+ return process.platform === "darwin"
+ ? "OLLAMA_HOST=127.0.0.1:11434 "
+ : "OLLAMA_HOST=0.0.0.0:11434 ";
+}
...
- const ollamaEnv = isWsl() ? "" : "OLLAMA_HOST=0.0.0.0:11434 ";
+ const ollamaEnv = getOllamaServeEnvPrefix();
run(`${ollamaEnv}ollama serve > /dev/null 2>&1 &`, { ignoreError: true });
...
- let ollamaEnv = "";
- if (!isWsl()) {
- ollamaEnv =
- process.platform === "darwin"
- ? "OLLAMA_HOST=127.0.0.1:11434 "
- : "OLLAMA_HOST=0.0.0.0:11434 ";
- }
+ const ollamaEnv = getOllamaServeEnvPrefix();
run(`${ollamaEnv}ollama serve > /dev/null 2>&1 &`, { ignoreError: true });🤖 Prompt for AI Agents |
||
| sleep(2); | ||
| console.log(" ✓ Using Ollama on localhost:11434"); | ||
| provider = "ollama-local"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,7 +119,9 @@ export function validateLocalProvider( | |
| return { | ||
| ok: false, | ||
| message: | ||
| "Local Ollama is responding on localhost, but containers cannot reach http://host.openshell.internal:11434. Ensure Ollama listens on 0.0.0.0:11434 instead of 127.0.0.1 so sandboxes can reach it.", | ||
| process.platform === "darwin" | ||
| ? "Local Ollama is responding on localhost, but containers cannot reach http://host.openshell.internal:11434. Restart Docker Desktop and ensure host networking is enabled." | ||
| : "Local Ollama is responding on localhost, but containers cannot reach http://host.openshell.internal:11434. Ensure Ollama listens on 0.0.0.0:11434 (not 127.0.0.1) so sandboxes can reach it via the Docker bridge.", | ||
|
Comment on lines
+122
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle WSL separately in the Ollama reachability hint. This 🤖 Prompt for AI Agents |
||
| }; | ||
| default: | ||
| return { | ||
|
|
@@ -207,10 +209,7 @@ export function getOllamaProbeCommand( | |
| return `curl -sS --max-time ${timeoutSeconds} http://localhost:11434/api/generate -H 'Content-Type: application/json' -d ${shellQuote(payload)} 2>/dev/null`; | ||
| } | ||
|
|
||
| export function validateOllamaModel( | ||
| model: string, | ||
| runCapture: RunCaptureFn, | ||
| ): ValidationResult { | ||
| export function validateOllamaModel(model: string, runCapture: RunCaptureFn): ValidationResult { | ||
| const output = runCapture(getOllamaProbeCommand(model), { ignoreError: true }); | ||
| if (!output) { | ||
| return { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-WSL Linux still publishes Ollama off-host.
Line 2650 keeps the default Linux launch path on
OLLAMA_HOST=0.0.0.0:11434. A normalnemoclaw onboardon Linux therefore still exposes the Ollama API beyond the host, so this hardening only lands for macOS right now. If Linux is meant to be covered too, this branch needs to stop forcing0.0.0.0.🤖 Prompt for AI Agents