-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: configure OpenShell gateway bind address and port #3425
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8bd6484
fix: configure gateway bind address and port
ericksoa b0f8aed
fix: address gateway bind review feedback
ericksoa fa305c8
fix: harden gateway env handling
ericksoa 9905e8d
fix: address gateway review follow-ups
ericksoa 3294d03
fix: enforce gateway env directory permissions
ericksoa ebf8880
Merge remote-tracking branch 'origin/main' into fix/gateway-bind-port…
ericksoa 4ac4333
test: allow slow transport-back selection path
ericksoa 0bf0cb0
chore: merge main into gateway bind port config
ericksoa c000d8b
fix: resolve CodeQL alerts for gateway port config
ericksoa aeea3c2
test: fix gateway upgrade macos entitlement fixture
ericksoa 27b0e00
Merge branch 'main' into fix/gateway-bind-port-config
ericksoa dd5e25c
chore: merge main into gateway bind port config
ericksoa f51d73f
chore: merge main into gateway bind port config
ericksoa 981c43f
chore: merge main into gateway bind port config
ericksoa 8f923e6
chore: merge main into gateway bind port config
ericksoa 994e923
test(onboard): mock ollama proxy readiness in selection tests
ericksoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| getGatewayConnectHost, | ||
| getGatewayHttpEndpoint, | ||
| getGatewayHttpsEndpoint, | ||
| parseGatewayBindAddress, | ||
| } from "../../../dist/lib/core/gateway-address"; | ||
|
|
||
| const ENV_KEY = "TEST_GATEWAY_BIND_ADDRESS"; | ||
|
|
||
| afterEach(() => { | ||
| delete process.env[ENV_KEY]; | ||
| }); | ||
|
|
||
| describe("parseGatewayBindAddress", () => { | ||
| it("defaults to loopback", () => { | ||
| expect(parseGatewayBindAddress(ENV_KEY)).toBe("127.0.0.1"); | ||
| }); | ||
|
|
||
| it("accepts loopback", () => { | ||
| process.env[ENV_KEY] = "127.0.0.1"; | ||
| expect(parseGatewayBindAddress(ENV_KEY)).toBe("127.0.0.1"); | ||
| }); | ||
|
|
||
| it("accepts all IPv4 interfaces", () => { | ||
| process.env[ENV_KEY] = "0.0.0.0"; | ||
| expect(parseGatewayBindAddress(ENV_KEY)).toBe("0.0.0.0"); | ||
| }); | ||
|
|
||
| it("rejects comma-separated addresses", () => { | ||
| process.env[ENV_KEY] = "0.0.0.0,127.0.0.1"; | ||
| expect(() => parseGatewayBindAddress(ENV_KEY)).toThrow("must be either"); | ||
| }); | ||
|
|
||
| it.each(["localhost", "10.0.0.5", "::", "::1"])("rejects %s", (value) => { | ||
| process.env[ENV_KEY] = value; | ||
| expect(() => parseGatewayBindAddress(ENV_KEY)).toThrow("must be either"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("gateway endpoint helpers", () => { | ||
| it("keeps loopback endpoints unchanged", () => { | ||
| expect(getGatewayConnectHost("127.0.0.1")).toBe("127.0.0.1"); | ||
| expect(getGatewayHttpEndpoint(8080, "127.0.0.1")).toBe("http://127.0.0.1:8080"); | ||
| expect(getGatewayHttpsEndpoint(8080, "127.0.0.1")).toBe("https://127.0.0.1:8080"); | ||
| }); | ||
|
|
||
| it("does not advertise wildcard bind addresses as client endpoints", () => { | ||
| expect(getGatewayConnectHost("0.0.0.0")).toBe("127.0.0.1"); | ||
| expect(getGatewayHttpEndpoint(8990, "0.0.0.0")).toBe("http://127.0.0.1:8990"); | ||
| expect(getGatewayHttpsEndpoint(8990, "0.0.0.0")).toBe("https://127.0.0.1:8990"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { GATEWAY_PORT } from "./ports"; | ||
|
|
||
| export const DEFAULT_GATEWAY_BIND_ADDRESS = "127.0.0.1"; | ||
| export const WILDCARD_GATEWAY_BIND_ADDRESS = "0.0.0.0"; | ||
|
|
||
| export type GatewayBindAddress = | ||
| | typeof DEFAULT_GATEWAY_BIND_ADDRESS | ||
| | typeof WILDCARD_GATEWAY_BIND_ADDRESS; | ||
|
|
||
| export function parseGatewayBindAddress( | ||
| envVar = "NEMOCLAW_GATEWAY_BIND_ADDRESS", | ||
| fallback: GatewayBindAddress = DEFAULT_GATEWAY_BIND_ADDRESS, | ||
| ): GatewayBindAddress { | ||
| const raw = process.env[envVar]; | ||
| if (raw === undefined || raw === "") return fallback; | ||
| const trimmed = String(raw).trim(); | ||
| if (trimmed === DEFAULT_GATEWAY_BIND_ADDRESS) return DEFAULT_GATEWAY_BIND_ADDRESS; | ||
| if (trimmed === WILDCARD_GATEWAY_BIND_ADDRESS) return WILDCARD_GATEWAY_BIND_ADDRESS; | ||
| throw new Error( | ||
| `Invalid gateway bind address: ${envVar}="${raw}" — must be either ${DEFAULT_GATEWAY_BIND_ADDRESS} or ${WILDCARD_GATEWAY_BIND_ADDRESS}`, | ||
| ); | ||
| } | ||
|
|
||
| export const GATEWAY_BIND_ADDRESS = parseGatewayBindAddress(); | ||
|
|
||
| export function getGatewayConnectHost( | ||
| bindAddress: GatewayBindAddress = GATEWAY_BIND_ADDRESS, | ||
| ): string { | ||
| return bindAddress === WILDCARD_GATEWAY_BIND_ADDRESS | ||
| ? DEFAULT_GATEWAY_BIND_ADDRESS | ||
| : bindAddress; | ||
| } | ||
|
|
||
| export function getGatewayHttpEndpoint( | ||
| port: number = GATEWAY_PORT, | ||
| bindAddress: GatewayBindAddress = GATEWAY_BIND_ADDRESS, | ||
| ): string { | ||
| return `http://${getGatewayConnectHost(bindAddress)}:${port}`; | ||
| } | ||
|
|
||
| export function getGatewayHttpsEndpoint( | ||
| port: number = GATEWAY_PORT, | ||
| bindAddress: GatewayBindAddress = GATEWAY_BIND_ADDRESS, | ||
| ): string { | ||
| return `https://${getGatewayConnectHost(bindAddress)}:${port}`; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Treat whitespace-only bind values as empty input.
At Line 18, blank handling is checked before trimming, so
NEMOCLAW_GATEWAY_BIND_ADDRESS=" "throws instead of using the fallback. Normalizing empties after trim avoids surprising config failures.Suggested patch
export function parseGatewayBindAddress( envVar = "NEMOCLAW_GATEWAY_BIND_ADDRESS", fallback: GatewayBindAddress = DEFAULT_GATEWAY_BIND_ADDRESS, ): GatewayBindAddress { const raw = process.env[envVar]; - if (raw === undefined || raw === "") return fallback; const trimmed = String(raw).trim(); + if (raw === undefined || trimmed === "") return fallback; if (trimmed === DEFAULT_GATEWAY_BIND_ADDRESS) return DEFAULT_GATEWAY_BIND_ADDRESS; if (trimmed === WILDCARD_GATEWAY_BIND_ADDRESS) return WILDCARD_GATEWAY_BIND_ADDRESS; throw new Error( `Invalid gateway bind address: ${envVar}="${raw}" — must be either ${DEFAULT_GATEWAY_BIND_ADDRESS} or ${WILDCARD_GATEWAY_BIND_ADDRESS}`, ); }📝 Committable suggestion
🤖 Prompt for AI Agents