mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2)
Paired runtime environments gain a durable two-phase SSH access link
(prepare link, verified link, prepare unlink, complete unlink, cancel),
plus the reconciliation record type and the runtime identity verification
helper that T6 needs. Nothing calls the link store yet; T6's managed tunnel
and runtime SSH access are its first writers.
Why a sidecar: v1.4.217 and v1.4.218 parse orca-environments.json with plain
z.object schemas, which strip unknown keys, and rewrite the whole file on
routine use (markEnvironmentUsed). Storing the link there, as #16741 did, would
let a downgraded build keep the tunnel endpoint but drop sshAccess, stranding
the server unlinkable and losing its pinned host-key fingerprint. #16741's own
answer (bumping the store version) makes those builds reject the whole file.
So orca-environments.json keeps exactly its shipped shape (version 1, persisted
fields only), and all T5 state lives in orca-environment-sidecar.json beside
it: the link and its tunnel endpoint, the pending operation, the reconciliation
record, the verified runtime id and a monotonic pairing-revision floor. Reads
overlay the sidecar; each entry is bound to the environment's createdAt,
pairing revision and preferred endpoint, so a re-pair, removal or edit by an
older build makes it stale (ignored, pruned on the next sidecar write). An
unreadable sidecar fails closed, like the main file.
Porting note (source: #16741 a68b6f3531):
- Taken: the link-store behavior and messages, the access-link schemas and
refinements, the reconciliation record, identity verification, and the
store/schema tests.
- Adapted: link state moved from orca-environments.json to the sidecar;
existing mutators write persisted fields only; removal, re-pairing and
runtime identity changes refuse while SSH access is linked or pending.
- Left for later slices: orcadDeployment and restoreManagedOrcadEnvironmentLink
(T6), reconciliation store, integrity, catalog and UI (T5-3 to T5-5), the 24
renderer terminal-input files (T7), runtime-identity and the managed-tunnel
resolver (T6).
* test(runtime): read SSH access from the known view of a persisted environment
---------
Co-authored-by: m4air <m4air@m4airs-Air.localdomain>
138 lines
4.4 KiB
TypeScript
138 lines
4.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { PAIRING_OFFER_VERSION, type PairingOffer } from './pairing'
|
|
import {
|
|
createEnvironmentFromPairingOffer,
|
|
getPreferredPairingOffer,
|
|
getRuntimeSshAccess,
|
|
KnownRuntimeEnvironmentSchema,
|
|
redactRuntimeEnvironment,
|
|
RuntimeEnvironmentStoreSchema,
|
|
type RuntimeSshTunnelLink
|
|
} from './runtime-environments'
|
|
|
|
const link: RuntimeSshTunnelLink = {
|
|
sshTargetId: 'ssh-host',
|
|
sshTargetGeneration: 7,
|
|
localPort: 46768,
|
|
remotePort: 6768
|
|
}
|
|
const accessLink = {
|
|
...link,
|
|
endpointId: 'ssh-access',
|
|
previousPreferredEndpointId: 'ws-environment-1'
|
|
}
|
|
const offer: PairingOffer = {
|
|
v: PAIRING_OFFER_VERSION,
|
|
endpoint: 'ws://127.0.0.1:46768',
|
|
deviceToken: 'secret-device-token',
|
|
publicKeyB64: 'secret-key',
|
|
pairedDeviceId: 'paired-device'
|
|
}
|
|
function accessEnvironment() {
|
|
const original = environment()
|
|
return {
|
|
...original,
|
|
connectionDependency: 'ssh-tunnel' as const,
|
|
sshAccess: accessLink,
|
|
endpoints: [...original.endpoints, { ...original.endpoints[0]!, id: accessLink.endpointId }],
|
|
preferredEndpointId: accessLink.endpointId
|
|
}
|
|
}
|
|
function environment() {
|
|
return createEnvironmentFromPairingOffer({
|
|
id: 'environment-1',
|
|
name: 'Host',
|
|
now: 1,
|
|
offer,
|
|
runtimeId: 'host-runtime'
|
|
})
|
|
}
|
|
|
|
describe('runtime SSH access without deployment ownership', () => {
|
|
it('keeps old stored environments valid without adding an SSH dependency', () => {
|
|
const original = environment()
|
|
const restored = RuntimeEnvironmentStoreSchema.parse({ version: 1, environments: [original] })
|
|
.environments[0]!
|
|
expect(restored).toEqual(original)
|
|
expect(getRuntimeSshAccess(KnownRuntimeEnvironmentSchema.parse(restored))).toBeUndefined()
|
|
expect(restored).not.toHaveProperty('sshAccess')
|
|
// The persisted envelope never carries sidecar state, even when handed a linked environment.
|
|
const persisted = RuntimeEnvironmentStoreSchema.parse({
|
|
version: 1,
|
|
environments: [accessEnvironment()]
|
|
}).environments[0]!
|
|
expect(persisted).not.toHaveProperty('sshAccess')
|
|
})
|
|
|
|
it.each([
|
|
{ sshTargetId: '' },
|
|
{ sshTargetGeneration: 0 },
|
|
{ sshTargetGeneration: 1.5 },
|
|
{ localPort: 0 },
|
|
{ localPort: 65536 },
|
|
{ remotePort: 0 },
|
|
{ remotePort: 65536 }
|
|
])('rejects malformed generic access links: %j', (change) => {
|
|
expect(
|
|
KnownRuntimeEnvironmentSchema.safeParse({
|
|
...accessEnvironment(),
|
|
sshAccess: { ...accessLink, ...change }
|
|
}).success
|
|
).toBe(false)
|
|
})
|
|
|
|
it('preserves SSH metadata while redacting the same pairing secrets', () => {
|
|
const accessed = KnownRuntimeEnvironmentSchema.parse(accessEnvironment())
|
|
const redacted = redactRuntimeEnvironment(accessed)
|
|
expect(getRuntimeSshAccess(redacted)).toEqual(accessLink)
|
|
expect(redacted.endpoints[0]).not.toHaveProperty('deviceToken')
|
|
expect(redacted.endpoints[0]).not.toHaveProperty('publicKeyB64')
|
|
expect(JSON.stringify(redacted)).not.toContain('secret-')
|
|
expect(getPreferredPairingOffer(accessed)).toEqual(offer)
|
|
})
|
|
|
|
it.each([
|
|
{ endpointId: 'missing' },
|
|
{ previousPreferredEndpointId: 'missing' },
|
|
{ previousPreferredEndpointId: 'ssh-access' },
|
|
{ localPort: 46769 }
|
|
])('rejects access links that cannot restore the prior endpoint: %j', (change) => {
|
|
expect(
|
|
KnownRuntimeEnvironmentSchema.safeParse({
|
|
...accessEnvironment(),
|
|
sshAccess: { ...accessLink, ...change }
|
|
}).success
|
|
).toBe(false)
|
|
})
|
|
|
|
it('rejects an unpreferred SSH access endpoint', () => {
|
|
expect(
|
|
KnownRuntimeEnvironmentSchema.safeParse({
|
|
...accessEnvironment(),
|
|
preferredEndpointId: accessLink.previousPreferredEndpointId
|
|
}).success
|
|
).toBe(false)
|
|
})
|
|
|
|
it('rejects a non-loopback SSH access endpoint', () => {
|
|
const accessed = accessEnvironment()
|
|
accessed.endpoints[1]!.endpoint = 'ws://remote.example:46768'
|
|
expect(KnownRuntimeEnvironmentSchema.safeParse(accessed).success).toBe(false)
|
|
})
|
|
|
|
it('rejects a generic access link without its SSH dependency', () => {
|
|
expect(
|
|
KnownRuntimeEnvironmentSchema.safeParse({
|
|
...accessEnvironment(),
|
|
connectionDependency: undefined
|
|
}).success
|
|
).toBe(false)
|
|
})
|
|
|
|
it('rejects a non-WebSocket loopback endpoint', () => {
|
|
const accessed = accessEnvironment()
|
|
accessed.endpoints[1]!.endpoint = 'https://127.0.0.1:46768'
|
|
expect(KnownRuntimeEnvironmentSchema.safeParse(accessed).success).toBe(false)
|
|
})
|
|
})
|