Skip to content

Commit b6610d3

Browse files
committed
fix(ssh): gate verbose SSH debug logging behind ssh.debug config flag
1 parent d9fffe3 commit b6610d3

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

config.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@
394394
"agentForwardingErrorMessage": {
395395
"type": "string",
396396
"description": "Custom error message shown when SSH agent forwarding is not enabled or no keys are loaded in the client's SSH agent. If not specified, a default message with git config commands will be shown. This allows organizations to customize instructions based on their security policies."
397+
},
398+
"debug": {
399+
"type": "boolean",
400+
"description": "Enable verbose SSH protocol debug logging (both for the local SSH server and for outbound connections to remote Git servers). Emits one log line per SSH packet, so leave disabled in production.",
401+
"default": false
397402
}
398403
},
399404
"required": ["enabled"]

src/config/generated/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ export interface SSH {
558558
* security policies.
559559
*/
560560
agentForwardingErrorMessage?: string;
561+
/**
562+
* Enable verbose SSH protocol debug logging (both for the local SSH server and for outbound
563+
* connections to remote Git servers). Emits one log line per SSH packet, so leave disabled
564+
* in production.
565+
*/
566+
debug?: boolean;
561567
/**
562568
* Enable SSH proxy server. When enabled, clients can connect via SSH and the proxy will
563569
* forward their SSH agent to authenticate with remote Git servers.
@@ -1008,6 +1014,7 @@ const typeMap: any = {
10081014
js: 'agentForwardingErrorMessage',
10091015
typ: u(undefined, ''),
10101016
},
1017+
{ json: 'debug', js: 'debug', typ: u(undefined, true) },
10111018
{ json: 'enabled', js: 'enabled', typ: true },
10121019
{ json: 'port', js: 'port', typ: u(undefined, 3.14) },
10131020
],

src/proxy/ssh/GitProtocol.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import * as ssh2 from 'ssh2';
2828
import { ClientWithUser } from './types';
2929
import { validateSSHPrerequisites, createSSHConnectionOptions } from './sshHelpers';
3030
import { parsePacketLines } from '../processors/pktLineParser';
31+
import { getSSHConfig } from '../../config';
32+
33+
function isDebugEnabled(): boolean {
34+
return getSSHConfig()?.debug === true;
35+
}
3136

3237
/**
3338
* Parser for Git pkt-line protocol
@@ -285,7 +290,7 @@ export async function forwardPackDataToRemote(
285290
command,
286291
client,
287292
remoteHost,
288-
{ clientStream: stream, debug: true, keepalive: true },
293+
{ clientStream: stream, debug: isDebugEnabled(), keepalive: true },
289294
(remoteStream) => {
290295
console.log(`[SSH] Forwarding pack data for user ${userName}`);
291296

@@ -345,7 +350,7 @@ export async function connectToRemoteGitServer(
345350
remoteHost,
346351
{
347352
clientStream: stream,
348-
debug: true,
353+
debug: isDebugEnabled(),
349354
keepalive: true,
350355
requireAgentForwarding: true,
351356
},

src/proxy/ssh/server.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ export class SSHServer {
5959
keepaliveInterval: 20000, // 20 seconds is recommended for SSH connections
6060
keepaliveCountMax: 5, // Recommended for SSH connections is 3-5 attempts
6161
readyTimeout: 30000, // Longer ready timeout
62-
debug: (msg: string) => {
63-
console.debug('[SSH Debug]', msg);
64-
},
6562
};
6663

64+
if (sshConfig.debug) {
65+
serverOptions.debug = (msg: string) => {
66+
console.debug('[SSH Debug]', msg);
67+
};
68+
}
69+
6770
this.server = new ssh2.Server(
6871
serverOptions as any, // ssh2 types don't fully match our extended interface
6972
(client: ssh2.Connection, info: any) => {

0 commit comments

Comments
 (0)