An open-source, faster Devin alternative
TypeScript
add cross cell migration/backwards compat
Brian Reardonaf8c2ea05674
diff --git a/internal/qemu/manager.go b/internal/qemu/manager.goindex b1adc596..18822b43 100644--- a/internal/qemu/manager.go+++ b/internal/qemu/manager.go@@ -313,6 +313,42 @@ func (m *Manager) sealSandboxEnvs(ctx context.Context, sandboxID string, netCfgreturn sealed}+// reinstallProxyCA overwrites the proxy CA cert in the guest's trust store+// with the destination worker's current CA. Called from any handoff path+// where the sandbox can land on a different worker than it was created on:+// live migration, hibernate→wake (cross-worker), checkpoint fork.+//+// The guest's env vars (SSL_CERT_FILE / REQUESTS_CA_BUNDLE / NODE_EXTRA_CA_CERTS)+// point at the fixed path the proxy injected at sandbox creation, so we+// only need to overwrite the file content; no update-ca-certificates run+// is required because the consuming libraries read the file directly.+//+// Idempotent: in steady state where every worker shares the same CA via KV,+// the destination's CA equals the source's and this is a no-op write. The+// value is in the transition window (sandboxes created before shared-CA+// rollout) and any future "the destination's CA differs" scenario (cross-+// cell migration, planned CA rotation, etc.).+//+// Best-effort — errors are logged but don't fail the handoff. A migration+// that successfully moves the workload but fails to refresh the cert is+// strictly better than refusing the migration.+func (m *Manager) reinstallProxyCA(ctx context.Context, sandboxID string, agent *AgentClient) {+ if m.secretsProxy == nil || agent == nil {+ return+ }+ certPEM := m.secretsProxy.CACertPEM()+ if len(certPEM) == 0 {+ return+ }+ writeCtx, cancel := context.WithTimeout(ctx, 5*time.Second)+ defer cancel()+ if err := agent.WriteFile(writeCtx, "/usr/local/share/ca-certificates/opensandbox-proxy.crt", certPEM); err != nil {+ log.Printf("qemu: %s: reinstall proxy CA failed: %v (sandbox is alive but TLS substitution may break until next handoff)", sandboxID, err)+ return+ }+ log.Printf("qemu: %s: reinstalled proxy CA on guest", sandboxID)+}+// PrepareGoldenSnapshot boots a temporary VM, waits for the agent, then// hibernates it to create a reusable snapshot. Subsequent Create() calls// restore from this snapshot instead of cold-booting, cutting start time@@ -2982,6 +3018,12 @@ func (m *Manager) ForkFromCheckpoint(ctx context.Context, checkpointID string, cm.vms[id] = vmm.mu.Unlock()+ // Refresh the proxy CA in the forked guest's trust store. The fork+ // inherits the source checkpoint's disk + RAM, so its trust store has+ // whatever CA the original sandbox was created against — which is+ // probably a different worker. Idempotent in the shared-CA case.+ m.reinstallProxyCA(ctx, id, agent)+// Notify metadata serverif m.onSandboxReady != nil {m.onSandboxReady(id, netCfg.GuestIP, meta.Template, now)diff --git a/internal/qemu/migration.go b/internal/qemu/migration.goindex ac63783d..afc31a17 100644--- a/internal/qemu/migration.go+++ b/internal/qemu/migration.go@@ -563,6 +563,18 @@ func (m *Manager) CompleteIncomingMigration(ctx context.Context, sandboxID strinlog.Printf("qemu: migration %s: clock sync failed: %v", sandboxID, err)}+ // Re-install the secrets-proxy CA cert into the guest so the destination+ // worker's cert chain is trusted by anything the guest does next. Even+ // with the shared-CA-via-KV path, this is belt-and-suspenders that also+ // retrofits sandboxes which were created BEFORE the shared CA rollout+ // (their trust store has the source's per-worker CA baked in). The+ // guest's env vars (SSL_CERT_FILE / REQUESTS_CA_BUNDLE / NODE_EXTRA_CA_CERTS)+ // already point to this fixed path; overwriting the file is enough — no+ // update-ca-certificates run required because consumers read the file+ // directly. Cheap (~1ms agent RPC) and idempotent: in steady state the+ // new content equals the old, so this is a no-op write.+ m.reinstallProxyCA(ctx, sandboxID, agentClient)+// Sync VM memory tracking with actual QEMU state.// After migration, the QEMU process has the source's virtio-mem hotplugged memory,// but the Go struct still has the prep values (virtioMemRequestedMB=0, MemoryMB=baseMem).diff --git a/internal/qemu/snapshot.go b/internal/qemu/snapshot.goindex 803b232e..e3341d53 100644--- a/internal/qemu/snapshot.go+++ b/internal/qemu/snapshot.go@@ -491,6 +491,11 @@ func (m *Manager) doWake(ctx context.Context, sandboxID, checkpointKey string, cm.secretsProxy.ReregisterSession(sandboxID, netCfg.GuestIP, meta.SealedTokens, meta.EgressAllowlist, meta.TokenHosts)log.Printf("qemu: wake %s: re-registered secrets proxy session (%d tokens)", sandboxID, len(meta.SealedTokens))}+ // Refresh the proxy CA in the guest's trust store. Wake may land on a+ // different worker than the one that hibernated the sandbox, in which+ // case the cert in the guest's trust store no longer matches what this+ // worker's proxy presents. Idempotent on same-worker wake.+ m.reinstallProxyCA(context.Background(), sandboxID, agentClient)log.Printf("qemu: wake %s: golden restore complete (port=%d, tap=%s)",sandboxID, hostPort, netCfg.TAPName)