feat: SSH Authentication Keys v2 (#113)

* feat: add SSH authentication keys v2 for Git operations

Add comprehensive SSH key authentication support for Git operations including:
- SSH host key verification with user approval flow
- Encrypted SSH key storage with passphrase support
- SSH connection testing endpoint
- Real-time host key change warnings

Backend changes:
- New SSHHostKeyHandler for managing host key verification via IPC
- Add passphrase handler for locked SSH keys
- Add SSH key manager utilities (key writing, validation, cleanup)
- Add crypto utilities for secure key/secret encryption
- Add SSH validation utilities for key format checking
- Add SSH routes for host key response handling
- Enhance GitAuthService with SSH setup and environment methods
- Update GitService to handle SSH authentication for push/fetch/pull
- Update OpenCode server to support SSH keys with SSH config generation
- Add database migration for trusted_ssh_hosts table
- Add settings endpoint for SSH connection testing

Frontend changes:
- Add SSHHostKeyDialog for host key verification UI
- Add PassphraseModal for SSH key passphrase input
- Update GitCredentialDialog with SSH key type and testing
- Update GitSettings to manage SSH keys
- Add SSH API client and hooks (useSSH, usePassphraseHandler)

Shared changes:
- Add SSH schemas and types

Test coverage:
- Integration tests for SSH flow
- IPC handler tests for host key and passphrase
- SSH route tests
- SSH utility validation tests
- Updated existing tests for SSH-aware changes
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-08 00:06:44 -05:00
1 parent 3d5ee463d7
commit 414f39b809
54 files changed
+4051 -214

No files matched your search

+30 -1
View File
@@ -4,7 +4,7 @@ import { useNavigate, useLocation } from 'react-router-dom'
import { useQueryClient, useQuery } from '@tanstack/react-query'
import { OpenCodeClient } from '@/api/opencode'
import { listRepos } from '@/api/repos'
import type { PermissionRequest, PermissionResponse, QuestionRequest, SSEEvent } from '@/api/types'
import type { PermissionRequest, PermissionResponse, QuestionRequest, SSEEvent, SSHHostKeyRequest } from '@/api/types'
import { showToast } from '@/lib/toast'
import { subscribeToSSE, addSSEDirectory, ensureSSEConnected } from '@/lib/sseManager'
import { OPENCODE_API_ENDPOINT } from '@/config'
@@ -13,7 +13,13 @@ import { addToSessionKeyedState, removeFromSessionKeyedState } from '@/lib/sessi
type PermissionsBySession = Record<string, PermissionRequest[]>
type QuestionsBySession = Record<string, QuestionRequest[]>
interface SSHHostKeyState {
request: SSHHostKeyRequest | null
respond: (requestId: string, approved: boolean) => Promise<void>
}
interface EventContextValue {
sshHostKey: SSHHostKeyState
permissions: {
current: PermissionRequest | null
pendingCount: number
@@ -45,6 +51,18 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
const navigate = useNavigate()
const location = useLocation()
const [sshHostKeyRequest, setSSHHostKeyRequest] = useState<SSHHostKeyRequest | null>(null)
const respondToSSHHostKey = useCallback(async (requestId: string, approved: boolean) => {
try {
const { respondSSHHostKey } = await import('@/api/ssh')
await respondSSHHostKey(requestId, approved)
setSSHHostKeyRequest(null)
} catch {
showToast.error('Failed to respond to SSH host key verification')
}
}, [])
const [permissionsBySession, setPermissionsBySession] = useState<PermissionsBySession>({})
const [questionsBySession, setQuestionsBySession] = useState<QuestionsBySession>({})
const [showPermissionDialog, setShowPermissionDialog] = useState(true)
@@ -272,6 +290,11 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
addQuestion(event.properties as QuestionRequest)
}
break
case 'ssh.host-key-request':
if ('requestId' in event.properties && 'host' in event.properties) {
setSSHHostKeyRequest(event.properties as SSHHostKeyRequest)
}
break
case 'question.replied':
case 'question.rejected':
if ('requestID' in event.properties && 'sessionID' in event.properties) {
@@ -325,6 +348,10 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
}, [repos, fetchInitialPendingData])
const value: EventContextValue = useMemo(() => ({
sshHostKey: {
request: sshHostKeyRequest,
respond: respondToSSHHostKey,
},
permissions: {
current: currentPermission,
pendingCount: allPermissions.length,
@@ -348,6 +375,8 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
getRepoIdForSession,
getClient,
}), [
sshHostKeyRequest,
respondToSSHHostKey,
currentPermission,
allPermissions.length,
respondToPermission,