mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
* feat(cloud): SSH into Orca Cloud workspaces (orca ssh, ssh-proxy, VS Code/Cursor Remote-SSH) - VM: unprivileged key-only sshd on 127.0.0.1:2222 (orca-sshd), host key and Orca-managed authorized_keys on the persistent disk; orca-ssh-keys entry point; provision extracts only the server binaries (dnf or apt, +1.5-2 MB) and unlocks the sandbox user for key logins. - Control plane: POST/DELETE /v1/sandboxes/:id/ssh-keys runs the fixed entry point and answers the pinned host key; editor Remote-SSH server hosts on the egress allowlist. - Desktop: per-workspace ed25519 keys in userData (0600), Orca-owned ssh_config + pinned known_hosts, ~/.ssh/config Include only after consent; wake -> key -> runtime port forward (openRuntimePortForward reason 'ssh'); revoke (deferred while asleep); SSH traffic keeps the workspace awake. - CLI: orca ssh-proxy <workspace> (ProxyCommand) and orca ssh <workspace>. - UI: Open in -> VS Code / Cursor over Remote SSH, SSH submenu (Copy SSH Command, Revoke), include consent dialog, progress/error toasts. * fix(cloud-ssh): review fixes — no agent forwarding, reinstall per VM boot, wake to revoke - ForwardAgent/ForwardX11 no in Orca's host blocks; AllowAgentForwarding no in the VM's sshd. - Reinstall the key (idempotent; restarts sshd, re-pins the host key) once per VM boot, so a wiped disk, rollover or dead sshd heals on the next connection. - Revoke wakes the VM to remove its copy; only an unreachable VM falls back to the queue. - orca-ssh-keys rejects multi-line keys; sshd log truncated per start; audit log entries for ssh key add/remove; state parsed per entry; % escaped in ssh_config paths; ProxyCommand pinned to this app's profile; ssh-proxy flushes stdout before exit; --print shell-quotes; editors open via --folder-uri with a checked path; "Remove from ~/.ssh/config" + one-time backup.
55 lines
2.0 KiB
TypeScript
55 lines
2.0 KiB
TypeScript
// SSH access to a running workspace: installs or removes one desktop's public key in the VM's
|
|
// Orca-managed authorized_keys through the fixed /opt/orca/bin/orca-ssh-keys entry point. The VM's
|
|
// sshd listens on loopback only; the desktop reaches it through its own runtime connection.
|
|
import { z } from 'zod'
|
|
import { LifecycleError, type LifecycleDeps } from './lifecycle'
|
|
import { VmCommandError } from './sandbox-vm-commands'
|
|
import type { SandboxRow } from './store'
|
|
|
|
export const SSH_KEYS_COMMAND = '/opt/orca/bin/orca-ssh-keys'
|
|
const SSH_KEYS_TIMEOUT_MS = 30_000
|
|
|
|
/** ed25519 only, one line, a plain comment: nothing sshd would read as key options. */
|
|
export const SSH_PUBLIC_KEY = /^ssh-ed25519 [A-Za-z0-9+/]{68} [A-Za-z0-9@._:+-]{1,200}$/
|
|
|
|
export const SshKeyRequestSchema = z.object({ publicKey: z.string().regex(SSH_PUBLIC_KEY) }).strict()
|
|
|
|
const SshAccessSchema = z
|
|
.object({
|
|
port: z.number().int().min(1).max(65535),
|
|
user: z.string().regex(/^[a-z_][a-z0-9_-]{0,31}$/),
|
|
hostKey: z.string().regex(/^ssh-ed25519 [A-Za-z0-9+/]{68}$/)
|
|
})
|
|
.strict()
|
|
|
|
export type SshAccess = z.infer<typeof SshAccessSchema>
|
|
|
|
export async function updateSshKey(
|
|
deps: LifecycleDeps,
|
|
row: SandboxRow,
|
|
action: 'add' | 'remove',
|
|
publicKey: string
|
|
): Promise<SshAccess> {
|
|
if (row.status !== 'running' || !row.session_id) {
|
|
throw new LifecycleError('conflict', `sandbox_${row.status}`)
|
|
}
|
|
const result = await deps.provider.runCommand(row.session_id, {
|
|
command: SSH_KEYS_COMMAND,
|
|
args: [action],
|
|
env: { ORCA_SSH_PUBLIC_KEY: publicKey },
|
|
timeoutMs: SSH_KEYS_TIMEOUT_MS
|
|
})
|
|
// 3 = this VM's image predates sshd (older golden image); 127 = predates the entry point.
|
|
if (result.exitCode === 3 || result.exitCode === 127) {
|
|
throw new LifecycleError('conflict', 'ssh_unsupported_image')
|
|
}
|
|
if (result.exitCode !== 0) {
|
|
throw new VmCommandError('ssh_keys_failed')
|
|
}
|
|
try {
|
|
return SshAccessSchema.parse(JSON.parse(result.stdout.trim().split('\n').at(-1) ?? ''))
|
|
} catch {
|
|
throw new VmCommandError('ssh_keys_failed')
|
|
}
|
|
}
|