-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(cli): show SSH port-forward hint for remote dashboard access (#5925) #5929
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
5 commits
Select commit
Hold shift + click to select a range
9191002
fix(cli): show SSH port-forward hint for remote dashboard access (#5925)
atulya-singh 9be161a
fix(cli): address review feedback on SSH port-forward hint
atulya-singh f593b57
fix(cli): use <host> placeholder in SSH port-forward hint (#5925)
atulya-singh ce1f066
Merge branch 'main' into fix/5925-ssh-port-forward-hint
cv 4f00992
Merge branch 'main' into fix/5925-ssh-port-forward-hint
cv 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
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,127 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { buildSshForwardHintLines, isSshSession } from "./ssh-forward-hint"; | ||
|
|
||
| describe("ssh-forward-hint", () => { | ||
| describe("isSshSession", () => { | ||
| it("detects SSH_CONNECTION, SSH_CLIENT, and SSH_TTY", () => { | ||
| expect(isSshSession({ SSH_CONNECTION: "10.0.0.1 5000 10.0.0.2 22" })).toBe(true); | ||
| expect(isSshSession({ SSH_CLIENT: "10.0.0.1 5000 22" })).toBe(true); | ||
| expect(isSshSession({ SSH_TTY: "/dev/pts/0" })).toBe(true); | ||
| }); | ||
|
|
||
| it("returns false outside an SSH session", () => { | ||
| expect(isSshSession({})).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("buildSshForwardHintLines", () => { | ||
| it("builds a copy-pastable ssh -L example with the real user and a <host> placeholder (#5925)", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| accessUrl: "http://127.0.0.1:18790", | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" }, | ||
| }); | ||
|
|
||
| expect(lines).toEqual([ | ||
| " Remote access (SSH session detected):", | ||
| " On your workstation, run:", | ||
| " ssh -L 18790:127.0.0.1:18790 spark@<host>", | ||
| " Then open the dashboard URL above in your local browser.", | ||
| ]); | ||
| }); | ||
|
|
||
| it("never leaks the SSH_CONNECTION socket IP across an alias, NAT, or ProxyJump (#5925)", () => { | ||
| // An `~/.ssh/config` alias or ProxyJump makes the SSH_CONNECTION server-IP | ||
| // (field 3) unrelated to what the operator typed, so it must never appear. | ||
| for (const sshConnection of [ | ||
| "10.0.0.9 51000 10.6.76.40 22", // NAT'd / aliased direct host | ||
| "203.0.113.8 40222 10.10.0.5 2222", // private bastion-side (ProxyJump) target on a custom port | ||
| ]) { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| accessUrl: "http://127.0.0.1:18790", | ||
| env: { SSH_CONNECTION: sshConnection, USER: "spark" }, | ||
| }); | ||
|
|
||
| expect(lines?.[2]).toBe(" ssh -L 18790:127.0.0.1:18790 spark@<host>"); | ||
| // No socket IP and no inferred -p port from the (untrusted) SSH_CONNECTION. | ||
| expect(lines?.join("\n")).not.toContain("10.6.76.40"); | ||
| expect(lines?.join("\n")).not.toContain("10.10.0.5"); | ||
| expect(lines?.join("\n")).not.toContain("-p "); | ||
| } | ||
| }); | ||
|
|
||
| it("renders an explicitly supplied destination verbatim (#5925)", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| destination: "spark-host", | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" }, | ||
| }); | ||
|
|
||
| expect(lines?.[2]).toBe(" ssh -L 18790:127.0.0.1:18790 spark@spark-host"); | ||
| }); | ||
|
|
||
| it("falls back to the <host> placeholder for an unsafe explicit destination", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| destination: "evil; rm -rf /", | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" }, | ||
| }); | ||
|
|
||
| expect(lines?.[2]).toBe(" ssh -L 18790:127.0.0.1:18790 spark@<host>"); | ||
| }); | ||
|
|
||
| it("falls back to placeholders when user is unavailable", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| accessUrl: "http://127.0.0.1:18790", | ||
| env: { SSH_TTY: "/dev/pts/0" }, | ||
| }); | ||
|
|
||
| expect(lines?.[2]).toBe(" ssh -L 18790:127.0.0.1:18790 <user>@<host>"); | ||
| }); | ||
|
|
||
| it("rejects unsafe usernames in favor of the placeholder", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "evil; rm -rf" }, | ||
| }); | ||
|
|
||
| expect(lines?.[2]).toBe(" ssh -L 18790:127.0.0.1:18790 <user>@<host>"); | ||
| }); | ||
|
|
||
| it("respects a custom indent and open hint", () => { | ||
| const lines = buildSshForwardHintLines({ | ||
| port: 18790, | ||
| indent: "", | ||
| openHint: "Then open: http://127.0.0.1:18790/", | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" }, | ||
| }); | ||
|
|
||
| expect(lines).toEqual([ | ||
| "Remote access (SSH session detected):", | ||
| " On your workstation, run:", | ||
| " ssh -L 18790:127.0.0.1:18790 spark@<host>", | ||
| " Then open: http://127.0.0.1:18790/", | ||
| ]); | ||
| }); | ||
|
|
||
| it("returns null outside an SSH session", () => { | ||
| expect(buildSshForwardHintLines({ port: 18790, env: {} })).toBeNull(); | ||
| }); | ||
|
|
||
| it("returns null when the dashboard already binds a routable address", () => { | ||
| expect( | ||
| buildSshForwardHintLines({ | ||
| port: 18790, | ||
| accessUrl: "http://172.22.1.1:18790", | ||
| env: { SSH_CONNECTION: "10.0.0.9 51000 10.6.76.40 22", USER: "spark" }, | ||
| }), | ||
| ).toBeNull(); | ||
| }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.