-
Notifications
You must be signed in to change notification settings - Fork 246
Add GSSAPI/Kerberos SSH authentication support #1382
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||
| import { ipcMain } from 'electron'; | ||||||||||||||||||||
| import { execFile } from 'child_process'; | ||||||||||||||||||||
| import { SSH_IPC_CHANNELS } from '../../shared/ssh/types'; | ||||||||||||||||||||
| import { sshService } from '../services/ssh/SshService'; | ||||||||||||||||||||
| import { SshCredentialService } from '../services/ssh/SshCredentialService'; | ||||||||||||||||||||
|
|
@@ -50,7 +51,7 @@ function mapRowToConfig(row: { | |||||||||||||||||||
| host: row.host, | ||||||||||||||||||||
| port: row.port, | ||||||||||||||||||||
| username: row.username, | ||||||||||||||||||||
| authType: row.authType as 'password' | 'key' | 'agent', | ||||||||||||||||||||
| authType: row.authType as 'password' | 'key' | 'agent' | 'gssapi', | ||||||||||||||||||||
| privateKeyPath: row.privateKeyPath ?? undefined, | ||||||||||||||||||||
| useAgent: row.useAgent === 1, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
@@ -161,6 +162,61 @@ export function registerSshIpc() { | |||||||||||||||||||
| config: SshConfig & { password?: string; passphrase?: string } | ||||||||||||||||||||
| ): Promise<ConnectionTestResult> => { | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| // GSSAPI connections use system ssh for testing (ssh2 doesn't support GSSAPI) | ||||||||||||||||||||
| if (config.authType === 'gssapi') { | ||||||||||||||||||||
| return new Promise((resolve) => { | ||||||||||||||||||||
| const startTime = Date.now(); | ||||||||||||||||||||
| const debugLogs: string[] = []; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sshArgs = [ | ||||||||||||||||||||
| '-o', | ||||||||||||||||||||
| 'GSSAPIAuthentication=yes', | ||||||||||||||||||||
| '-o', | ||||||||||||||||||||
| 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex', | ||||||||||||||||||||
| '-o', | ||||||||||||||||||||
| 'StrictHostKeyChecking=accept-new', | ||||||||||||||||||||
| '-o', | ||||||||||||||||||||
| 'BatchMode=yes', | ||||||||||||||||||||
| '-o', | ||||||||||||||||||||
| 'ConnectTimeout=10', | ||||||||||||||||||||
| '-v', // Verbose for debug logs | ||||||||||||||||||||
| '-p', | ||||||||||||||||||||
| String(config.port), | ||||||||||||||||||||
| '-l', | ||||||||||||||||||||
| config.username, | ||||||||||||||||||||
| config.host, | ||||||||||||||||||||
| 'echo __EMDASH_SSH_OK__', | ||||||||||||||||||||
| ]; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| execFile( | ||||||||||||||||||||
| 'ssh', | ||||||||||||||||||||
| sshArgs, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| timeout: 15000, | ||||||||||||||||||||
| env: { | ||||||||||||||||||||
| ...process.env, | ||||||||||||||||||||
| KRB5CCNAME: process.env.KRB5CCNAME || '', | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| (err, stdout, stderr) => { | ||||||||||||||||||||
| const latency = Date.now() - startTime; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Capture verbose ssh output as debug logs | ||||||||||||||||||||
| if (stderr) { | ||||||||||||||||||||
| debugLogs.push(...stderr.split('\n').filter(Boolean)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (stdout && stdout.includes('__EMDASH_SSH_OK__')) { | ||||||||||||||||||||
| resolve({ success: true, latency, debugLogs }); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| const errorMsg = err?.message || stderr?.trim() || 'GSSAPI authentication failed'; | ||||||||||||||||||||
| resolve({ success: false, error: errorMsg, debugLogs }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const { Client } = await import('ssh2'); | ||||||||||||||||||||
| const debugLogs: string[] = []; | ||||||||||||||||||||
| const testClient = new Client(); | ||||||||||||||||||||
|
|
@@ -571,6 +627,43 @@ export function registerSshIpc() { | |||||||||||||||||||
| return { success: false, error: 'Access denied: path is restricted' }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // GSSAPI connections use command-based file operations | ||||||||||||||||||||
| if (sshService.isGssapiConnection(connectionId)) { | ||||||||||||||||||||
| const result = await sshService.executeCommand( | ||||||||||||||||||||
| connectionId, | ||||||||||||||||||||
| `ls -la --time-style=+%s ${quoteShellArg(path)} 2>/dev/null` | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (result.exitCode !== 0) { | ||||||||||||||||||||
| return { success: false, error: `Failed to list files: ${result.stderr}` }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const entries: FileEntry[] = []; | ||||||||||||||||||||
| for (const line of result.stdout.split('\n')) { | ||||||||||||||||||||
| // Parse ls -la output: permissions links owner group size timestamp name | ||||||||||||||||||||
| const match = line.match( | ||||||||||||||||||||
| /^([dlscp-])([rwxsStT-]{9})\s+\d+\s+\S+\s+\S+\s+(\d+)\s+(\d+)\s+(.+)$/ | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (!match) continue; | ||||||||||||||||||||
| const [, typeChar, perms, sizeStr, mtimeStr, name] = match; | ||||||||||||||||||||
| if (name === '.' || name === '..') continue; | ||||||||||||||||||||
|
Comment on lines
+643
to
+648
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. Symlink names include When A fix would be to strip the arrow and target from symlink names:
Suggested change
And use |
||||||||||||||||||||
|
|
||||||||||||||||||||
| let type: 'file' | 'directory' | 'symlink' = 'file'; | ||||||||||||||||||||
| if (typeChar === 'd') type = 'directory'; | ||||||||||||||||||||
| else if (typeChar === 'l') type = 'symlink'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| entries.push({ | ||||||||||||||||||||
| path: `${path}/${name}`.replace(/\/+/g, '/'), | ||||||||||||||||||||
| name, | ||||||||||||||||||||
| type, | ||||||||||||||||||||
| size: parseInt(sizeStr, 10), | ||||||||||||||||||||
| modifiedAt: new Date(parseInt(mtimeStr, 10) * 1000), | ||||||||||||||||||||
| permissions: perms, | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return { success: true, files: entries }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sftp = await sshService.getSftp(connectionId); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return new Promise((resolve) => { | ||||||||||||||||||||
|
|
@@ -622,6 +715,18 @@ export function registerSshIpc() { | |||||||||||||||||||
| return { success: false, error: 'Access denied: path is restricted' }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // GSSAPI connections use command-based file operations | ||||||||||||||||||||
| if (sshService.isGssapiConnection(connectionId)) { | ||||||||||||||||||||
| const result = await sshService.executeCommand( | ||||||||||||||||||||
| connectionId, | ||||||||||||||||||||
| `cat ${quoteShellArg(path)}` | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (result.exitCode !== 0) { | ||||||||||||||||||||
| return { success: false, error: `Failed to read file: ${result.stderr}` }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return { success: true, content: result.stdout }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sftp = await sshService.getSftp(connectionId); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return new Promise((resolve) => { | ||||||||||||||||||||
|
|
@@ -655,6 +760,19 @@ export function registerSshIpc() { | |||||||||||||||||||
| return { success: false, error: 'Access denied: path is restricted' }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // GSSAPI connections use command-based file operations | ||||||||||||||||||||
| if (sshService.isGssapiConnection(connectionId)) { | ||||||||||||||||||||
| const encoded = Buffer.from(content, 'utf-8').toString('base64'); | ||||||||||||||||||||
| const result = await sshService.executeCommand( | ||||||||||||||||||||
| connectionId, | ||||||||||||||||||||
| `echo ${quoteShellArg(encoded)} | base64 -d > ${quoteShellArg(path)}` | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (result.exitCode !== 0) { | ||||||||||||||||||||
| return { success: false, error: `Failed to write file: ${result.stderr}` }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return { success: true }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sftp = await sshService.getSftp(connectionId); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return new Promise((resolve) => { | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
--time-styleis a GNU ls extension that breaks on macOS/BSD remote servers--time-style=+%sis specific to GNU coreutilslsand is not available on macOS or BSD systems. If the remote host runs macOS, this command will exit non-zero withls: illegal option -- -(the long option form is not supported), causing all GSSAPI directory listings to fail with a generic "Failed to list files" error.Consider a more portable approach using
statfor timestamps, or fall back gracefully. For example, usingls -lawithout--time-styleand then separately fetching timestamps, or checkingunameat connection time. At minimum, the error message could hint at the root cause when this fails.