Skip to content

P6 on Kubernetes, slice 2: external P4 microVM hosts attached to an in-cluster relay over TLS #424

Closed

Description

@pdettori

Slice 2 of the P6-on-Kubernetes epic: P4 microVM hosts attached to an in-cluster relay

Part of epic #426. Written so a planner can start it in a fresh session. Depends on slice 1.

Goal

P4 is the only part that still needs a VM or bare metal. A KVM host, outside the cluster, runs microvm-worker under systemd, as in deploy/microvm/. It dials the relay of a slice-1 cluster over TLS and serves authenticated mocactl turns.

This slice targets a P4-only stack: one P4 host and no container-sandbox pods. Slice 3 lifts both restrictions. The reasons are in "Limits" below.

Work

  1. Expose the relay's attach port outside the cluster with TLS. Use a LoadBalancer with TLS, or TLS passthrough to a relay that serves TLS. microvm-worker already supports RELAY_TLS=true with the system root CAs (remote-worker/cmd/microvm-worker/main.go:646-680). Only the attach port is exposed; the exec port never is.

    • Attach is a long-lived gRPC stream. Check the load balancer's idle timeout against the worker's keepalive, and record what was measured.
    • A NetworkPolicy admits the P4 hosts' CIDR to the attach port only.
  2. Add a remote-relay mode to deploy/microvm/setup-microvm.sh. Today it assumes P6 runs on the same host:

    • it reads SH_RELAY_PORT from P6's relay.env;
    • it writes a sh-relay.service drop-in carrying SH_RELAY_TOKEN_<id>;
    • it waits for the presence record with podman exec sh-redis.

    Remote mode takes RELAY_ADDR (and TLS) as input, generates the per-sandbox token as now, and prints the Secret entry the cluster side must add instead of writing a relay drop-in. It waits for attach some way other than local Redis: the worker log, a relay status endpoint, or an operator-run kubectl check. The co-located mode keeps working unchanged.

  3. Register per-sandbox tokens without restarting the relay. The relay reads SH_RELAY_TOKEN_<id> from its environment at boot. On Kubernetes, adding a P4 host would therefore mean restarting the single relay, which drops every attached sandbox and fails in-flight turns. Read the per-sandbox tokens from a mounted Secret file and reload it, without changing the fail-closed semantics in makeDefaultValidateToken.

  4. Docs: an addition to deploy/microvm/P4-ON-P6.md, or a sibling page, for the Kubernetes case.

Limits (by design in this slice, lifted by slice 3)

  • One tier per stack. selectPoolSandbox (harness/src/select-sandbox.ts) picks the least-loaded of all presence records on every turn, and records carry no tier label. With container pods and a P4 host on one relay, a session's turn 2 can land in a container and lose turn 1's microVM workspace (P4-ON-P6.md, "A P4-only host"). A cluster wanting both runs two stacks, one namespace each, with separate Redis and relay.
  • One P4 host per stack. The workspace is keyed by session id on the worker host's disk (select-sandbox.ts:446-456), and selection has no session-to-sandbox affinity. With a second host, a later turn can open an empty workspace.
  • The golden snapshot is restored only on the instance type it was built on, so P4 hosts must be homogeneous.
  • The P4 guest still has no network (P4.1: implement microVM egress transport (vsock → shared proxy) #277).

Not chosen: P4 as a privileged DaemonSet on a KVM node pool

It is possible, but it fights the jailer, the microvm-vms.slice cgroup layout and hostPath state. Revisit only if external hosts prove unworkable.

Acceptance

  • An authenticated mocactl turn on the slice-1 stack runs its tool calls in Firecracker microVMs on an external host, over TLS.
  • A second turn of the same session sees the first turn's files.
  • Adding the host's token does not restart the relay.
  • A sandbox credential cannot reach the exec port from outside the cluster.

Activity

  1. added
    enhancement
    on Oct 2, 2026
  2. pdettori commented on Oct 5, 2026

    @pdettori
    MemberAuthor

    Slice 2 (#424) live acceptance: OpenShift 4.20.8 plus the shared KVM rig

    Result: PASS. A P4 microVM host outside the cluster attached to the in-cluster relay over TLS. It served authenticated turns for two users, and adding a host did not restart the relay. Both sides were then restored.

    Item Value
    Branch feat/424-p6-k8s-slice2 @ 5a69c0b
    Harness image Built in-cluster from c3bdb21: image-registry.openshift-image-registry.svc:5000/moca-build/moca-harness@sha256:99aa5c99d8ec9023f18b2acecbcf95801dd95705f36864a1ea69bcc60acc9f08. 5a69c0b only changes smoke.sh and its test, which run on the operator's machine.
    Cluster OpenShift 4.20.8, apps domain apps.moca1.kubestellar.org, nodes on kernel 5.14.0-570.73.1.el9_6
    P4 host The shared KVM rig (EC2, Firecracker). microvm-worker was built from c3bdb21 and installed with setup-microvm.sh --remote. Guest kernel 6.18.44+.

    Steps (spec §8)

    1. Owner alerted. The rig manifest was opened before any change. It records what was found, each change, and each restore.
    2. Stack switched to P4-only with SH_SANDBOX_COUNT=0 SH_P4_SANDBOX_IDS=moca_microvm_0 deploy/k8s/setup.sh --target ocp --image <above>.
      • The setup generated the relay token and a self-signed relay certificate for moca-relay-moca.apps.moca1.kubestellar.org.
      • The relay pod came up 2/2 (relay plus TLS sidecar), behind passthrough Route moca-relay.
      • The container sandboxes were scaled to 0.
    3. Rig reachability, checked first: curl -v https://moca-relay-moca… from the rig completed the TLS handshake, with ALPN: server accepted h2 (the --alpn h2 fix, confirmed live) and the self-signed certificate.
    4. Bundle installed. The bundle was copied with scp -r and installed with sudo … setup-microvm.sh --remote ~/moca-p4-moca_microvm_0, which printed moca_microvm_0 is attached to the relay at moca-relay-moca.apps.moca1.kubestellar.org:443. On the cluster side, sh:sandbox:records = moca_microvm_0. The worker logged tls=true and a single attached. The bundle copy was deleted after install.
    5. smoke.sh --target ocp --tier p4, real model (Anthropic API):
    Claim Result
    1 supervisor ready ok, 2/2 workers healthy
    P2 P4 IDs attached, no container sandbox ok, moca_microvm_0
    5 control plane ready, harness URL ok
    6 unauthenticated /turn refused ok, 401 token_required
    P3 turn runs on a kernel that is no node's ok, 6.18.44+ vs nodes 5.14.0-570.73.1.el9_6.x86_64
    P4 second turn reads the file back ok
    P6 through the Route: wrong attach token refused at the relay; SandboxExec not served even with the exec token ok, attach=0 exec=12
    P7 adding a host reloads no relay (SMOKE_P4_ADD_ID=moca_microvm_scratch) ok: the token reached the relay's directory in 42 s, and the relay pod (sandbox-relay-cb564b8f7-hh9pp, start 02:40:58Z, 0 restarts) was unchanged. The scratch ID's token and bundle were removed again.

    The first run passed 8/8. Its P3 line exposed a defect, described under Findings. After the fix, the smoke was re-run with P7 skipped: 7/7.

    1. mocactl ran for both slice-1 GitHub users, after a fresh device-flow login for each. doctor passed 7/7 for both.
      • Each user wrote a file in one turn and read it back in a second turn of the same session. The tool output named the guest kernel 6.18.44+.
      • Each user's mocactl sessions lists only their own sessions.
    2. Idle check (spec §9 risk): the worker stayed attached from 02:42:13 to 03:06:34 UTC. That includes 11 minutes with no turns (02:55:34 to 03:06:34). The relay log and the worker journal each show one attach and no stream ended, so the Route's timeout: 5m plus the worker's 30 s keepalive hold over the router.
    3. Restore: both sides were verified back to their recorded starting state.
      • Rig: setup-microvm.sh (local mode) was re-run with the original binary, rebuilt on the rig from its checkout (fd6fed2). Its sha256 83d47cee… is byte-identical to the one recorded before the run.
        • 50-moca-p6.conf is back; the remote drop-in and the CA file are gone.
        • The env keys match the original, and the token matches the local relay's copy. The local relay was not restarted.
        • The worker re-attached locally (tls=false), and the staging files were removed. /opt/serverless-harness was never touched.
      • Stack: SH_P4_SANDBOX_IDS= SH_SANDBOX_COUNT=2 setup.sh --target ocp --image <slice-1 digest>. Revocation ran clean on the real API server.
        • The leftover p4-relay objects and the two relay Secrets were deleted, as README §11.4 describes.
        • moca-setup is identical to its pre-run value.
        • The container-tier smoke.sh --target ocp passed 11/11.

    Findings from the live run

    • Fixed during the run (5a69c0b): P3 was vacuous against a real model. The tool_result preview is a JSON envelope, so P3 compared the whole envelope against the node kernels, a comparison that could never fail. P3 now extracts the text, requires a kernel-release shape, and then rejects any node kernel. A regression test uses the real envelope format. The corrected P3 then passed live with 6.18.44+.
    • Recorded: I did not back up the rig's original microvm-worker binary before --remote replaced it. The restore rebuilt it from the rig checkout's commit; see the restore section.
    • Not fixed (follow-up): setup.sh accepts several P4 IDs. One attached host per stack is a documented limit until Sandbox tier selection and session-to-sandbox affinity in selectPoolSandbox (P6-on-K8s slice 3) #425.
  3. 5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions