Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/(remote-access)/peer/ssh/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function SSHTerminal({ username, port, peer }: Props) {
if (!peer.id) return;
if (connected.current) return;
connected.current = true;

try {
const aclPort = isNativeSSHSupported(peer.version) ? "22022" : port;
const rules = [`tcp/${aclPort}`];
Expand All @@ -121,7 +122,7 @@ function SSHTerminal({ username, port, peer }: Props) {
sshConnectedOnce.current = true;
}
} catch (error) {
console.error("Connection failed:", error);
console.error("Connection error:", error);
}
};

Expand Down
31 changes: 26 additions & 5 deletions src/modules/remote-access/ssh/useSSH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export enum SSHStatus {
export const SSH_DOCS_LINK =
"https://docs.netbird.io/how-to/browser-client#ssh-connection";

const SSH_DETECTION_TIMEOUT_MS = 20000;

export const useSSH = (client: any) => {
const [status, setStatus] = useState(SSHStatus.DISCONNECTED);
const [config, setConfig] = useState<SSHConfig | null>(null);
Expand All @@ -38,12 +40,31 @@ export const useSSH = (client: any) => {

setStatus(SSHStatus.CONNECTING);
setConfig(config);
setError("");

try {
const requiresJwt = await client.detectSSHServerType(
config.hostname,
config.port,
);
let requiresJwt = false;
try {
requiresJwt = await client.detectSSHServerType(
config.hostname,
config.port,
SSH_DETECTION_TIMEOUT_MS,
);
console.log("Detection:", { requiresJwt, hasToken: !!accessToken });
} catch (detectionErr) {
console.error(
"Detection failed, falling back to pubkey:",
detectionErr,
);
}

if (requiresJwt && !accessToken) {
console.error("No access token available");
setError("No access token available");
setStatus(SSHStatus.DISCONNECTED);
setConfig(null);
return SSHStatus.DISCONNECTED;
}

const ssh = await client.createSSHConnection(
config.hostname,
Expand All @@ -63,7 +84,7 @@ export const useSSH = (client: any) => {
setStatus(SSHStatus.CONNECTED);
return SSHStatus.CONNECTED;
} catch (err) {
console.error("SSH connection failed:", err);
console.error("Connection failed:", err);
session.current = null;
setStatus(SSHStatus.DISCONNECTED);
setError("SSH connection failed. Check the console for details.");
Expand Down
11 changes: 8 additions & 3 deletions src/modules/remote-access/useNetBirdClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ export const useNetBirdClient = () => {
}, []);

const detectSSHServerType = useCallback(
async (host: string, port: number): Promise<boolean> => {
async (host: string, port: number, timeoutMs: number): Promise<boolean> => {
if (!netBirdClient.current?.detectSSHServerType) {
throw new Error("NetBird client not ready");
}
return netBirdClient.current.detectSSHServerType(host, port);
return netBirdClient.current.detectSSHServerType(host, port, timeoutMs);
},
[],
);
Expand All @@ -228,7 +228,12 @@ export const useNetBirdClient = () => {
if (!netBirdClient.current?.createSSHConnection) {
throw new Error("Go client not ready");
}
return netBirdClient.current.createSSHConnection(host, port, username);
return netBirdClient.current.createSSHConnection(
host,
port,
username,
jwtToken,
);
},
[],
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const loadConfig = (): Config => {
googleAnalyticsID: configJson?.googleAnalyticsID || undefined,
googleTagManagerID: configJson?.googleTagManagerID || undefined,
wasmPath:
configJson?.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.60.0",
configJson?.wasmPath || "https://pkgs.netbird.io/wasm/client/v0.60.2",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} as Config;
};

Expand Down