← Back to Pull requests

test: add podvm test suite #3361

Open
mkulke opened this pull request with 1266 lines diff across 16 files
View on GitHub
mkulke mkulke commented on Oct 01, 2026 21:15 UTC
Author

This adds a programmatic test suite, like the e2e test suite, but scoped to testing the PodVM surface. It doesn't require a K8S or CAA deployment and its goal is to improve the debug cycle for development on PodVM features and to avoid runnign costly full e2e-suite runs. A successful run should take less than 30s.

The current test will use ssh-over-vsock and thus require a debug image for testing. An SSH key is injected via systemd+SMBIOS and the TLS key material is provided via the cloud-disk, so no customization is needed.

Tests assert that the various systemd units are active and not flapping (there is a recheck w/ a correlation id after 2s).

The ttrpc api is used to create a Sandbox and a small container payload. A container is using api-server-rest to retrieve evidence via the sample attester, hereby exercising various services in the podvm.

Currently the tests are limited to x86_64, but I think they can be adapted to other archs rather easily.

$ TEST_PODVM_IMAGE=podvm/build/podvm-ubuntu-amd64.qcow2 make test-podvm
TEST_PODVM_IMAGE=./podvm/build/podvm-ubuntu-amd64.qcow2 go test -v -timeout 5m -count=1 -run '' ./test/podvm
=== RUN   TestPodVM
=== RUN   TestPodVM/SSHReady
=== RUN   TestPodVM/ExecuteCommandOverVSock
=== RUN   TestPodVM/ProvisionUserData
=== RUN   TestPodVM/SystemdServices
=== RUN   TestPodVM/SystemdServices/ProcessUserData
=== PAUSE TestPodVM/SystemdServices/ProcessUserData
=== RUN   TestPodVM/SystemdServices/AttestationAgent
=== PAUSE TestPodVM/SystemdServices/AttestationAgent
=== RUN   TestPodVM/SystemdServices/ConfidentialDataHub
=== PAUSE TestPodVM/SystemdServices/ConfidentialDataHub
=== RUN   TestPodVM/SystemdServices/APIServerREST
=== PAUSE TestPodVM/SystemdServices/APIServerREST
=== RUN   TestPodVM/SystemdServices/KataAgent
=== PAUSE TestPodVM/SystemdServices/KataAgent
=== CONT  TestPodVM/SystemdServices/ProcessUserData
=== CONT  TestPodVM/SystemdServices/APIServerREST
=== CONT  TestPodVM/SystemdServices/ConfidentialDataHub
=== CONT  TestPodVM/SystemdServices/AttestationAgent
=== CONT  TestPodVM/SystemdServices/KataAgent
=== RUN   TestPodVM/ForwarderMutualTLS
=== RUN   TestPodVM/KataAgentHealth
=== RUN   TestPodVM/SandboxLifecycle
=== RUN   TestPodVM/SandboxLifecycle/LaunchContainers
=== RUN   TestPodVM/SandboxLifecycle/LaunchContainers/Message
=== RUN   TestPodVM/SandboxLifecycle/LaunchContainers/GetEvidence
--- PASS: TestPodVM (18.99s)
    --- PASS: TestPodVM/SSHReady (12.82s)
    --- PASS: TestPodVM/ExecuteCommandOverVSock (0.02s)
    --- PASS: TestPodVM/ProvisionUserData (0.03s)
    --- PASS: TestPodVM/SystemdServices (0.00s)
        --- PASS: TestPodVM/SystemdServices/ProcessUserData (2.11s)
        --- PASS: TestPodVM/SystemdServices/AttestationAgent (2.11s)
        --- PASS: TestPodVM/SystemdServices/APIServerREST (2.11s)
        --- PASS: TestPodVM/SystemdServices/ConfidentialDataHub (2.11s)
        --- PASS: TestPodVM/SystemdServices/KataAgent (2.55s)
    --- PASS: TestPodVM/ForwarderMutualTLS (0.01s)
    --- PASS: TestPodVM/KataAgentHealth (0.01s)
    --- PASS: TestPodVM/SandboxLifecycle (3.40s)
        --- PASS: TestPodVM/SandboxLifecycle/LaunchContainers (3.39s)
            --- PASS: TestPodVM/SandboxLifecycle/LaunchContainers/Message (1.88s)
            --- PASS: TestPodVM/SandboxLifecycle/LaunchContainers/GetEvidence (1.51s)
PASS
ok      github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm   19.005s

Diff: 1266 lines (+1260 / -6) across 16 files Reviewer: mkulke Review duration: 13163m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.86) × (1 − Review Confidence (0.84)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.86 · 1266 lines diff across 16 files
0.86
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 5 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Self Review self_review
0.140
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
26 items
github-advanced-security[bot] github-advanced-security[bot] commented on code on Oct 01, 2026 21:32 UTC
Code Review
src/cloud-api-adaptor/test/podvm/qemu.go:1
@@ -0,0 +1,295 @@
+// (C) Copyright Confidential Containers Contributors
+// SPDX-License-Identifier: Apache-2.0
+
+//go:build linux && amd64
+
+package podvm
+
+import (
+	"context"
+	"encoding/base64"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"io"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"strconv"
+	"syscall"
+	"time"
+
+	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
+	"github.com/mdlayher/vsock"
+	"golang.org/x/crypto/ssh"
+)
+
+const (
+	defaultGuestCID = 3
+	sshPort         = 22
+)
+
+type qemuConfig struct {
+	image         string
+	qemuBinary    string
+	ovmfCode      string
+	ovmfVars      string
+	guestCID      uint32
+	authorizedKey []byte
+	userData      cloudinit.CloudConfigGenerator
+}
+
+type qemuVM struct {
+	cmd       *exec.Cmd
+	done      chan struct{}
+	waitErr   error
+	guestCID  uint32
+	qemuLog   string
+	serialLog string
+	workDir   string
+}
+
+type imageInfo struct {
+	Format string `json:"format"`
+}
+
+func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
+	format, err := getImageFormat(config.image)
+	if err != nil {
+		return nil, err
+	}
+
+	workDir, err := os.MkdirTemp("", "podvm-test-")
+	if err != nil {
+		return nil, fmt.Errorf("create temporary directory: %w", err)
+	}
+	defer func() {
+		if err != nil {
+			_ = os.RemoveAll(workDir)
+		}
+	}()
+
+	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
+	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
+		return nil, fmt.Errorf("copy OVMF variables: %w", err)
+	}
+
+	serialLog := filepath.Join(workDir, "serial.log")
+	qemuLog := filepath.Join(workDir, "qemu.log")
+	configDrive := filepath.Join(workDir, "config-drive.iso")
+	if err := createConfigDrive(configDrive, config.userData); err != nil {
+		return nil, err
+	}
+	logFile, err := os.Create(qemuLog)
+	if err != nil {
+		return nil, fmt.Errorf("create QEMU log: %w", err)
+	}
+	defer logFile.Close()
+
+	args := []string{
+		"-machine", "q35,accel=kvm",
+		"-cpu", "host",
+		"-m", "2048",
+		"-smp", "2",
+		"-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", config.ovmfCode),
+		"-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", ovmfVars),
+		"-drive", fmt.Sprintf("if=virtio,format=%s,file=%s,snapshot=on", format, config.image),
+		"-drive", fmt.Sprintf("file=%s,media=cdrom,readonly=on", configDrive),
+		"-device", fmt.Sprintf("vhost-vsock-pci,guest-cid=%d", config.guestCID),
+		"-device", "virtio-rng-pci",
+		"-netdev", "user,id=net0",
+		"-device", "virtio-net-pci,netdev=net0",
+		"-display", "none",
+		"-monitor", "none",
+		"-serial", "file:" + serialLog,
+		"-smbios", "type=11,value=io.systemd.credential.binary:ssh.ephemeral-authorized_keys-all=" +
+			base64.StdEncoding.EncodeToString(config.authorizedKey),
+	}
+
+	cmd := exec.Command(config.qemuBinary, args...)
+	cmd.Stdout = logFile
+	cmd.Stderr = logFile
+	if err := cmd.Start(); err != nil {
+		return nil, fmt.Errorf("start QEMU: %w", err)
+	}
+
+	vm := &qemuVM{
+		cmd:       cmd,
+		done:      make(chan struct{}),
+		guestCID:  config.guestCID,
+		qemuLog:   qemuLog,
+		serialLog: serialLog,
+		workDir:   workDir,
+	}
+	go func() {
+		vm.waitErr = cmd.Wait()
+		close(vm.done)
+	}()
+
+	return vm, nil
+}
+
+func (vm *qemuVM) close() {
+	if vm.cmd.Process != nil {
+		_ = vm.cmd.Process.Signal(syscall.SIGTERM)
+		select {
+		case <-vm.done:
+		case <-time.After(5 * time.Second):
+			_ = vm.cmd.Process.Kill()
+			<-vm.done
+		}
+	}
+	_ = os.RemoveAll(vm.workDir)
+}
+
+func (vm *qemuVM) waitForSSH(ctx context.Context, signer ssh.Signer) (*ssh.Client, error) {
+	ticker := time.NewTicker(500 * time.Millisecond)
+	defer ticker.Stop()
+
+	var lastErr error
+	for {
+		client, err := vm.sshClient(signer)
+		if err == nil {
+			return client, nil
+		}
+		lastErr = err
+
+		select {
+		case <-vm.done:
+			return nil, fmt.Errorf("QEMU exited before SSH became ready: %v\n%s", vm.waitErr, vm.logs())
+		case <-ctx.Done():
+			return nil, fmt.Errorf("wait for SSH over vsock: %w (last error: %v)\n%s", ctx.Err(), lastErr, vm.logs())
+		case <-ticker.C:
+		}
+	}
+}
+
+func (vm *qemuVM) sshClient(signer ssh.Signer) (*ssh.Client, error) {
+	conn, err := dialVSock(vm.guestCID, sshPort)
+	if err != nil {
+		return nil, err
+	}
+
+	deadline := time.Now().Add(5 * time.Second)
+	if err := conn.SetDeadline(deadline); err != nil {
+		conn.Close()
+		return nil, fmt.Errorf("set vsock deadline: %w", err)
+	}
+
+	config := &ssh.ClientConfig{
+		User:            "root",
+		Auth:            []ssh.AuthMethod{ssh.PublicKeys(signer)},
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(), // The test VM and its host key are ephemeral.

CodeQL / Use of insecure HostKeyCallback implementation

Configuring SSH ClientConfig with insecure HostKeyCallback implementation from [this source](1).

Show more details

mkulke mkulke commented on code on Oct 02, 2026 06:13 UTC
Code Review
src/cloud-api-adaptor/test/podvm/qemu.go:1
@@ -0,0 +1,295 @@
+// (C) Copyright Confidential Containers Contributors
+// SPDX-License-Identifier: Apache-2.0
+
+//go:build linux && amd64
+
+package podvm
+
+import (
+	"context"
+	"encoding/base64"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"io"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"strconv"
+	"syscall"
+	"time"
+
+	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
+	"github.com/mdlayher/vsock"
+	"golang.org/x/crypto/ssh"
+)
+
+const (
+	defaultGuestCID = 3
+	sshPort         = 22
+)
+
+type qemuConfig struct {
+	image         string
+	qemuBinary    string
+	ovmfCode      string
+	ovmfVars      string
+	guestCID      uint32
+	authorizedKey []byte
+	userData      cloudinit.CloudConfigGenerator
+}
+
+type qemuVM struct {
+	cmd       *exec.Cmd
+	done      chan struct{}
+	waitErr   error
+	guestCID  uint32
+	qemuLog   string
+	serialLog string
+	workDir   string
+}
+
+type imageInfo struct {
+	Format string `json:"format"`
+}
+
+func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
+	format, err := getImageFormat(config.image)
+	if err != nil {
+		return nil, err
+	}
+
+	workDir, err := os.MkdirTemp("", "podvm-test-")
+	if err != nil {
+		return nil, fmt.Errorf("create temporary directory: %w", err)
+	}
+	defer func() {
+		if err != nil {
+			_ = os.RemoveAll(workDir)
+		}
+	}()
+
+	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
+	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
+		return nil, fmt.Errorf("copy OVMF variables: %w", err)
+	}
+
+	serialLog := filepath.Join(workDir, "serial.log")
+	qemuLog := filepath.Join(workDir, "qemu.log")
+	configDrive := filepath.Join(workDir, "config-drive.iso")
+	if err := createConfigDrive(configDrive, config.userData); err != nil {
+		return nil, err
+	}
+	logFile, err := os.Create(qemuLog)
+	if err != nil {
+		return nil, fmt.Errorf("create QEMU log: %w", err)
+	}
+	defer logFile.Close()
+
+	args := []string{
+		"-machine", "q35,accel=kvm",
+		"-cpu", "host",
+		"-m", "2048",
+		"-smp", "2",
+		"-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", config.ovmfCode),
+		"-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", ovmfVars),
+		"-drive", fmt.Sprintf("if=virtio,format=%s,file=%s,snapshot=on", format, config.image),
+		"-drive", fmt.Sprintf("file=%s,media=cdrom,readonly=on", configDrive),
+		"-device", fmt.Sprintf("vhost-vsock-pci,guest-cid=%d", config.guestCID),
+		"-device", "virtio-rng-pci",
+		"-netdev", "user,id=net0",
+		"-device", "virtio-net-pci,netdev=net0",
+		"-display", "none",
+		"-monitor", "none",
+		"-serial", "file:" + serialLog,
+		"-smbios", "type=11,value=io.systemd.credential.binary:ssh.ephemeral-authorized_keys-all=" +
+			base64.StdEncoding.EncodeToString(config.authorizedKey),
+	}
+
+	cmd := exec.Command(config.qemuBinary, args...)
+	cmd.Stdout = logFile
+	cmd.Stderr = logFile
+	if err := cmd.Start(); err != nil {
+		return nil, fmt.Errorf("start QEMU: %w", err)
+	}
+
+	vm := &qemuVM{
+		cmd:       cmd,
+		done:      make(chan struct{}),
+		guestCID:  config.guestCID,
+		qemuLog:   qemuLog,
+		serialLog: serialLog,
+		workDir:   workDir,
+	}
+	go func() {
+		vm.waitErr = cmd.Wait()
+		close(vm.done)
+	}()
+
+	return vm, nil
+}
+
+func (vm *qemuVM) close() {
+	if vm.cmd.Process != nil {
+		_ = vm.cmd.Process.Signal(syscall.SIGTERM)
+		select {
+		case <-vm.done:
+		case <-time.After(5 * time.Second):
+			_ = vm.cmd.Process.Kill()
+			<-vm.done
+		}
+	}
+	_ = os.RemoveAll(vm.workDir)
+}
+
+func (vm *qemuVM) waitForSSH(ctx context.Context, signer ssh.Signer) (*ssh.Client, error) {
+	ticker := time.NewTicker(500 * time.Millisecond)
+	defer ticker.Stop()
+
+	var lastErr error
+	for {
+		client, err := vm.sshClient(signer)
+		if err == nil {
+			return client, nil
+		}
+		lastErr = err
+
+		select {
+		case <-vm.done:
+			return nil, fmt.Errorf("QEMU exited before SSH became ready: %v\n%s", vm.waitErr, vm.logs())
+		case <-ctx.Done():
+			return nil, fmt.Errorf("wait for SSH over vsock: %w (last error: %v)\n%s", ctx.Err(), lastErr, vm.logs())
+		case <-ticker.C:
+		}
+	}
+}
+
+func (vm *qemuVM) sshClient(signer ssh.Signer) (*ssh.Client, error) {
+	conn, err := dialVSock(vm.guestCID, sshPort)
+	if err != nil {
+		return nil, err
+	}
+
+	deadline := time.Now().Add(5 * time.Second)
+	if err := conn.SetDeadline(deadline); err != nil {
+		conn.Close()
+		return nil, fmt.Errorf("set vsock deadline: %w", err)
+	}
+
+	config := &ssh.ClientConfig{
+		User:            "root",
+		Auth:            []ssh.AuthMethod{ssh.PublicKeys(signer)},
+		HostKeyCallback: ssh.InsecureIgnoreHostKey(), // The test VM and its host key are ephemeral.

fixed, caching the host key not

Copilot Copilot commented on code on Oct 02, 2026 06:19 UTC
Code Review
src/cloud-api-adaptor/test/podvm/podvm_test.go:1
@@ -0,0 +1,410 @@
+// (C) Copyright Confidential Containers Contributors
+// SPDX-License-Identifier: Apache-2.0
+
+//go:build linux && amd64
+
+package podvm
+
+import (
+	"context"
+	"crypto/ed25519"
+	"crypto/rand"
+	"crypto/tls"
+	"encoding/json"
+	"os"
+	"os/exec"
+	"path/filepath"
+	"testing"
+	"time"
+
+	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
+	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/util/tlsutil"
+	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
+	"github.com/containerd/ttrpc"
+	agent "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
+	"github.com/stretchr/testify/require"
+	"golang.org/x/crypto/ssh"
+)
+
+const (
+	testForwarderServerName = "podvm-test"
+	testContainerImage      = "quay.io/prometheus/busybox@sha256:f07fff1d7544464a1041fc2b6be79873a335a3af8f0b747b82fa630287968d4d"
+)
+
+func TestPodVM(t *testing.T) {
+	image := os.Getenv("TEST_PODVM_IMAGE")
+	if image == "" {
+		t.Skip("TEST_PODVM_IMAGE is not set")
+	}
+
+	image, err := filepath.Abs(image)
+	require.NoError(t, err)
+	require.FileExists(t, image)
+	requireDevice(t, "/dev/kvm")
+	requireDevice(t, "/dev/vhost-vsock")
+
+	qemuBinary := os.Getenv("TEST_PODVM_QEMU_BINARY")
+	if qemuBinary == "" {
+		qemuBinary = "qemu-system-x86_64"
+	}
+	qemuBinary, err = exec.LookPath(qemuBinary)
+	require.NoError(t, err, "find QEMU")
+	_, err = exec.LookPath("qemu-img")
+	require.NoError(t, err, "find qemu-img")
+
+	ovmfCode, ovmfVars, err := findOVMF()
+	require.NoError(t, err)
+	cid, err := guestCID()
+	require.NoError(t, err)
+	signer := newSSHSigner(t)
+	forwarderConfig, forwarderClientTLS := newForwarderFixture(t)
+	forwarderJSON, err := json.Marshal(forwarderConfig)
+	require.NoError(t, err)
+
+	vm, err := startQEMU(qemuConfig{
+		image:         image,
+		qemuBinary:    qemuBinary,
+		ovmfCode:      ovmfCode,
+		ovmfVars:      ovmfVars,
+		guestCID:      cid,
+		authorizedKey: ssh.MarshalAuthorizedKey(signer.PublicKey()),
+		userData: &cloudinit.CloudConfig{
+			WriteFiles: []cloudinit.WriteFile{
+				{
+					Path:    forwarder.DefaultConfigPath,
+					Content: string(forwarderJSON),
+				},
+			},
+		},
+	})
+	require.NoError(t, err)
+	t.Cleanup(vm.close)
+
+	bootTimeout := 2 * time.Minute
+	if value := os.Getenv("TEST_PODVM_BOOT_TIMEOUT"); value != "" {
+		bootTimeout, err = time.ParseDuration(value)
+		require.NoError(t, err, "parse TEST_PODVM_BOOT_TIMEOUT")
+	}
+
+	var client *ssh.Client
+	if !t.Run("SSHReady", func(t *testing.T) {
+		ctx, cancel := context.WithTimeout(context.Background(), bootTimeout)
+		defer cancel()
+
+		client, err = vm.waitForSSH(ctx, signer)
+		require.NoError(t, err)
+	}) {
+		return
+	}

The documented RUN_TESTS=TestPodVM/SystemdServices/AttestationAgent command filters out SSHReady, but a filtered t.Run still returns true. This leaves client nil, so the selected test and cleanup panic. Initialize SSH in the parent test, outside the filterable subtest, so every selected test receives a connected client.

Copilot Copilot commented on code on Oct 02, 2026 06:19 UTC
Code Review
src/cloud-api-adaptor/test/podvm/ssh.go:1
@@ -0,0 +1,12 @@
+package podvm
+
+import "golang.org/x/crypto/ssh"
+
+func runSSHCommand(client *ssh.Client, command string) ([]byte, error) {
+	session, err := client.NewSession()
+	if err != nil {
+		return nil, err
+	}
+	defer session.Close()
+	return session.CombinedOutput(command)

Neither NewSession nor CombinedOutput observes a context, and sshClient clears the connection's handshake deadline. If the guest stops responding, a service check can remain blocked here after both its five-second attempt timeout and ten-second overall timeout expire. The global test timeout can then abort the run without normal VM cleanup. Pass bounded contexts through this helper and its callers, make session creation and execution interruptible, and bound diagnostic commands too.

Copilot Copilot commented on code on Oct 02, 2026 06:19 UTC
Code Review
src/cloud-api-adaptor/test/podvm/systemd.go:1
@@ -0,0 +1,89 @@
+package podvm
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"os"
+	"time"
+
+	"golang.org/x/crypto/ssh"
+)
+
+func retryUntil(ctx context.Context, description string, operation func(context.Context) error) error {
+	ticker := time.NewTicker(500 * time.Millisecond)
+	defer ticker.Stop()
+
+	var lastErr error
+	for {
+		attemptCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
+		err := operation(attemptCtx)
+		cancel()
+		if err == nil {
+			return nil
+		}
+		lastErr = err
+
+		select {
+		case <-ctx.Done():
+			return fmt.Errorf("wait for %s: %w (last error: %v)", description, ctx.Err(), lastErr)
+		case <-ticker.C:
+		}
+	}
+}
+func waitForSystemdService(ctx context.Context, client *ssh.Client, unit string) error {
+	err := retryUntil(ctx, unit, func(ctx context.Context) error {
+		_, err := runSSHCommand(client, "systemctl is-active --quiet "+unit)
+		if err != nil {
+			return err
+		}
+
+		timer := time.NewTimer(2 * time.Second)
+		defer timer.Stop()
+		select {
+		case <-ctx.Done():
+			return ctx.Err()
+		case <-timer.C:
+		}
+
+		_, err = runSSHCommand(client, "systemctl is-active --quiet "+unit)
+		return err

Two successful is-active checks do not establish that the service stayed running between samples. A service can crash, restart, and be active again at the second check, so this can report a flapping service as stable. Capture InvocationID with each active check and retry when the ID changes during the two-second interval.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 02, 2026 06:19 UTC
Reviewer

<!-- ccr-overview-v2 -->

Copilot review overview

🟡 Changes recommended

Test initialization, service stability checks, and SSH timeout handling have unresolved correctness issues.

Review effort: Balanced
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> · 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>

<details open>
<summary><strong>Open (3)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Filtered subtests use an uninitialized SSH client](#discussion_r4163328846) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [SSH commands ignore timeouts and can block cleanup](#discussion_r4163328877) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Active checks miss service restarts between samples](#discussion_r4163328894) · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Adds a standalone QEMU-based PodVM test suite to shorten development feedback without requiring Kubernetes or a CAA deployment.

    Changes:

  • Boot debug images with ephemeral SSH credentials and config-drive provisioning.

  • Exercise service health, mutual TLS, sandbox/container lifecycle, and attestation evidence.

  • Add a Makefile target, dependencies, and usage documentation.
  • | File | Description |
    | ---- | ----------- |
    | src/​cloud-api-adaptor/​test/​podvm/​systemd.go | Service readiness checks and diagnostics. |
    | src/​cloud-api-adaptor/​test/​podvm/​ssh.go | SSH command helper. |
    | src/​cloud-api-adaptor/​test/​podvm/​README.md | Requirements and test instructions. |
    | src/​cloud-api-adaptor/​test/​podvm/​qemu.go | VM startup, SSH connectivity, and cleanup. |
    | src/​cloud-api-adaptor/​test/​podvm/​podvm_test.go | PodVM integration tests and fixtures. |
    | src/​cloud-api-adaptor/​test/​podvm/​config_drive.go | User-data ISO generation. |
    | src/​cloud-api-adaptor/​Makefile | Configurable test-podvm target. |
    | src/​cloud-api-adaptor/​go.sum | Checksums for new dependencies. |
    | src/​cloud-api-adaptor/​go.mod | Direct test dependencies and socket support. |
    </details>

    ---

    💡 <a href="/confidential-containers/cloud-api-adaptor/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a code-review agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 14:32 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/ssh.go:1
    @@ -0,0 +1,40 @@
    +package podvm
    +
    +import (
    +	"context"
    +	"fmt"
    +
    +	"golang.org/x/crypto/ssh"
    +)
    +

    I'm not sure it's particularly harmful, but I wondered if there was a reason for ssh.go and systemd.go not having:

    //go:build linux && amd64
    

    like the others as I'm not sure they are worth compiling on other platforms currently?

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 14:46 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/podvm_test.go:1

    nit: Not a massive deal, but it looks like the base test name and some of the tests have been changes since the commit message was written, so it's a bit stale.

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 14:49 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/qemu.go:1
    @@ -0,0 +1,336 @@
    +// (C) Copyright Confidential Containers Contributors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build linux && amd64
    +
    +package podvm
    +
    +import (
    +	"bytes"
    +	"context"
    +	"encoding/base64"
    +	"encoding/json"
    +	"errors"
    +	"fmt"
    +	"io"
    +	"net"
    +	"os"
    +	"os/exec"
    +	"path/filepath"
    +	"strconv"
    +	"syscall"
    +	"time"
    +
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
    +	"github.com/mdlayher/vsock"
    +	"golang.org/x/crypto/ssh"
    +)
    +
    +const (
    +	defaultGuestCID = 3
    +	sshPort         = 22
    +)
    +
    +type qemuConfig struct {
    +	image         string
    +	qemuBinary    string
    +	ovmfCode      string
    +	ovmfVars      string
    +	guestCID      uint32
    +	authorizedKey []byte
    +	userData      cloudinit.CloudConfigGenerator
    +}
    +
    +type qemuVM struct {
    +	cmd           *exec.Cmd
    +	done          chan struct{}
    +	waitErr       error
    +	guestCID      uint32
    +	qemuLog       string
    +	serialLog     string
    +	workDir       string
    +	hostKey       ssh.PublicKey
    +	forwarderAddr string
    +}
    +
    +type imageInfo struct {
    +	Format string `json:"format"`
    +}
    +
    +func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
    +	format, err := getImageFormat(config.image)
    +	if err != nil {
    +		return nil, err
    +	}
    +
    +	workDir, err := os.MkdirTemp("", "podvm-test-")
    +	if err != nil {
    +		return nil, fmt.Errorf("create temporary directory: %w", err)
    +	}
    +	defer func() {
    +		if err != nil {
    +			_ = os.RemoveAll(workDir)
    +		}
    +	}()
    +
    +	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
    +	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
    +		return nil, fmt.Errorf("copy OVMF variables: %w", err)
    +	}
    +
    +	serialLog := filepath.Join(workDir, "serial.log")
    +	qemuLog := filepath.Join(workDir, "qemu.log")
    +	configDrive := filepath.Join(workDir, "config-drive.iso")
    +	if err := createConfigDrive(configDrive, config.userData); err != nil {
    +		return nil, err
    +	}
    +	logFile, err := os.Create(qemuLog)
    +	if err != nil {
    +		return nil, fmt.Errorf("create QEMU log: %w", err)
    +	}
    +	defer logFile.Close()

    Is there an issue with this defer? IIUC this with run once startQEMU returns, but I think we want to keep the logFile open for the duration of the tests, so maybe it needs to be stored in qemuVM and then called in close()?

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 14:53 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/qemu.go:1
    @@ -0,0 +1,336 @@
    +// (C) Copyright Confidential Containers Contributors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build linux && amd64
    +
    +package podvm
    +
    +import (
    +	"bytes"
    +	"context"
    +	"encoding/base64"
    +	"encoding/json"
    +	"errors"
    +	"fmt"
    +	"io"
    +	"net"
    +	"os"
    +	"os/exec"
    +	"path/filepath"
    +	"strconv"
    +	"syscall"
    +	"time"
    +
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
    +	"github.com/mdlayher/vsock"
    +	"golang.org/x/crypto/ssh"
    +)
    +
    +const (
    +	defaultGuestCID = 3
    +	sshPort         = 22
    +)
    +
    +type qemuConfig struct {
    +	image         string
    +	qemuBinary    string
    +	ovmfCode      string
    +	ovmfVars      string
    +	guestCID      uint32
    +	authorizedKey []byte
    +	userData      cloudinit.CloudConfigGenerator
    +}
    +
    +type qemuVM struct {
    +	cmd           *exec.Cmd
    +	done          chan struct{}
    +	waitErr       error
    +	guestCID      uint32
    +	qemuLog       string
    +	serialLog     string
    +	workDir       string
    +	hostKey       ssh.PublicKey
    +	forwarderAddr string
    +}
    +
    +type imageInfo struct {
    +	Format string `json:"format"`
    +}
    +
    +func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
    +	format, err := getImageFormat(config.image)
    +	if err != nil {
    +		return nil, err
    +	}
    +
    +	workDir, err := os.MkdirTemp("", "podvm-test-")
    +	if err != nil {
    +		return nil, fmt.Errorf("create temporary directory: %w", err)
    +	}
    +	defer func() {
    +		if err != nil {
    +			_ = os.RemoveAll(workDir)
    +		}
    +	}()
    +
    +	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
    +	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
    +		return nil, fmt.Errorf("copy OVMF variables: %w", err)
    +	}
    +
    +	serialLog := filepath.Join(workDir, "serial.log")
    +	qemuLog := filepath.Join(workDir, "qemu.log")
    +	configDrive := filepath.Join(workDir, "config-drive.iso")
    +	if err := createConfigDrive(configDrive, config.userData); err != nil {
    +		return nil, err
    +	}
    +	logFile, err := os.Create(qemuLog)
    +	if err != nil {
    +		return nil, fmt.Errorf("create QEMU log: %w", err)
    +	}
    +	defer logFile.Close()
    +
    +	forwarderListener, err := net.Listen("tcp", "127.0.0.1:0")
    +	if err != nil {
    +		return nil, fmt.Errorf("reserve agent protocol forwarder port: %w", err)
    +	}
    +	defer forwarderListener.Close()
    +	forwarderAddr := forwarderListener.Addr().String()
    +	_, forwarderPort, err := net.SplitHostPort(forwarderAddr)
    +	if err != nil {
    +		return nil, fmt.Errorf("parse agent protocol forwarder address: %w", err)
    +	}
    +
    +	args := []string{
    +		"-machine", "q35,accel=kvm",
    +		"-cpu", "host",
    +		"-m", "2048",
    +		"-smp", "2",
    +		"-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", config.ovmfCode),
    +		"-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", ovmfVars),
    +		"-drive", fmt.Sprintf("if=virtio,format=%s,file=%s,snapshot=on", format, config.image),
    +		"-drive", fmt.Sprintf("file=%s,media=cdrom,readonly=on", configDrive),
    +		"-device", fmt.Sprintf("vhost-vsock-pci,guest-cid=%d", config.guestCID),
    +		"-device", "virtio-rng-pci",
    +		"-netdev", fmt.Sprintf(
    +			"user,id=net0,hostfwd=tcp:127.0.0.1:%s-:%s",
    +			forwarderPort,
    +			forwarder.DefaultListenPort,
    +		),
    +		"-device", "virtio-net-pci,netdev=net0",
    +		"-display", "none",
    +		"-monitor", "none",
    +		"-serial", "file:" + serialLog,
    +		"-smbios", "type=11,value=io.systemd.credential.binary:ssh.ephemeral-authorized_keys-all=" +
    +			base64.StdEncoding.EncodeToString(config.authorizedKey),
    +	}
    +
    +	cmd := exec.Command(config.qemuBinary, args...)
    +	cmd.Stdout = logFile
    +	cmd.Stderr = logFile
    +	if err := forwarderListener.Close(); err != nil {
    +		return nil, fmt.Errorf("release agent protocol forwarder port: %w", err)
    +	}
    +	if err := cmd.Start(); err != nil {
    +		return nil, fmt.Errorf("start QEMU: %w", err)
    +	}
    +
    +	vm := &qemuVM{
    +		cmd:           cmd,
    +		done:          make(chan struct{}),
    +		guestCID:      config.guestCID,
    +		qemuLog:       qemuLog,
    +		serialLog:     serialLog,
    +		workDir:       workDir,
    +		forwarderAddr: forwarderAddr,
    +	}
    +	go func() {
    +		vm.waitErr = cmd.Wait()
    +		close(vm.done)
    +	}()
    +
    +	return vm, nil
    +}
    +
    +func (vm *qemuVM) close() {
    +	if vm.cmd.Process != nil {
    +		_ = vm.cmd.Process.Signal(syscall.SIGTERM)
    +		select {
    +		case <-vm.done:
    +		case <-time.After(5 * time.Second):
    +			_ = vm.cmd.Process.Kill()
    +			<-vm.done
    +		}
    +	}
    +	_ = os.RemoveAll(vm.workDir)
    +}
    +
    +func (vm *qemuVM) waitForSSH(ctx context.Context, signer ssh.Signer) (*ssh.Client, error) {
    +	ticker := time.NewTicker(500 * time.Millisecond)

    This is just my vibes, but 500ms feels like a short timeout, which could lead to lots of repeated attempts (which probably isn't a big deal). Do you have any data on how quickly it "normally" is ready, in case it's ~30s and then we could make the ticker larger?

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 14:59 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/podvm_test.go:1
    @@ -0,0 +1,414 @@
    +// (C) Copyright Confidential Containers Contributors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build linux && amd64
    +
    +package podvm
    +
    +import (
    +	"context"
    +	"crypto/ed25519"
    +	"crypto/rand"
    +	"crypto/tls"
    +	"encoding/json"
    +	"net"
    +	"os"
    +	"os/exec"
    +	"path/filepath"
    +	"testing"
    +	"time"
    +
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/util/tlsutil"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
    +	"github.com/containerd/ttrpc"
    +	agent "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
    +	"github.com/stretchr/testify/require"
    +	"golang.org/x/crypto/ssh"
    +)
    +
    +const (
    +	testForwarderServerName = "podvm-test"
    +	testContainerImage      = "quay.io/prometheus/busybox@sha256:f07fff1d7544464a1041fc2b6be79873a335a3af8f0b747b82fa630287968d4d"
    +)
    +
    +func TestDebugPodVM(t *testing.T) {
    +	image := os.Getenv("TEST_PODVM_IMAGE")
    +	if image == "" {
    +		t.Skip("TEST_PODVM_IMAGE is not set")
    +	}
    +
    +	image, err := filepath.Abs(image)
    +	require.NoError(t, err)
    +	require.FileExists(t, image)
    +	requireDevice(t, "/dev/kvm")
    +	requireDevice(t, "/dev/vhost-vsock")
    +
    +	qemuBinary := os.Getenv("TEST_PODVM_QEMU_BINARY")
    +	if qemuBinary == "" {
    +		qemuBinary = "qemu-system-x86_64"
    +	}
    +	qemuBinary, err = exec.LookPath(qemuBinary)
    +	require.NoError(t, err, "find QEMU")
    +	_, err = exec.LookPath("qemu-img")
    +	require.NoError(t, err, "find qemu-img")
    +
    +	ovmfCode, ovmfVars, err := findOVMF()
    +	require.NoError(t, err)
    +	cid, err := guestCID()
    +	require.NoError(t, err)
    +	signer := newSSHSigner(t)
    +	forwarderConfig, forwarderClientTLS := newForwarderFixture(t)
    +	forwarderJSON, err := json.Marshal(forwarderConfig)
    +	require.NoError(t, err)
    +
    +	vm, err := startQEMU(qemuConfig{
    +		image:         image,
    +		qemuBinary:    qemuBinary,
    +		ovmfCode:      ovmfCode,
    +		ovmfVars:      ovmfVars,
    +		guestCID:      cid,
    +		authorizedKey: ssh.MarshalAuthorizedKey(signer.PublicKey()),
    +		userData: &cloudinit.CloudConfig{
    +			WriteFiles: []cloudinit.WriteFile{
    +				{
    +					Path:    forwarder.DefaultConfigPath,
    +					Content: string(forwarderJSON),
    +				},
    +			},
    +		},
    +	})
    +	require.NoError(t, err)
    +	t.Cleanup(vm.close)
    +
    +	bootTimeout := 2 * time.Minute
    +	if value := os.Getenv("TEST_PODVM_BOOT_TIMEOUT"); value != "" {
    +		bootTimeout, err = time.ParseDuration(value)
    +		require.NoError(t, err, "parse TEST_PODVM_BOOT_TIMEOUT")
    +	}
    +
    +	bootCtx, cancelBoot := context.WithTimeout(context.Background(), bootTimeout)
    +	client, err := vm.waitForSSH(bootCtx, signer)
    +	cancelBoot()

    Bob suggests this:

    	defer cancelBoot()
    	client, err := vm.waitForSSH(bootCtx, signer)
    

    is more idiomatic and the defer covers more cases of (admitedly esoteric) failures.

    It does seem to match the official doc on this.

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 15:13 UTC
    Code Review
    .github/workflows/podvm_test.yaml:1
    @@ -0,0 +1,61 @@
    +name: PodVM test
    +
    +on:
    +  pull_request:
    +  workflow_dispatch:
    +
    +concurrency:
    +  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
    +  cancel-in-progress: true
    +
    +permissions: {}
    +
    +jobs:
    +  test:
    +    name: Test PodVM
    +    runs-on: 'ubuntu-24.04'
    +    permissions:
    +      contents: read  # Required to checkout code
    +    steps:
    +      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    +        with:
    +          persist-credentials: false
    +
    +      - name: Install dependencies
    +        run: |
    +          sudo apt-get update
    +          sudo apt-get install --no-install-recommends -y \
    +            alien \
    +            bubblewrap \
    +            dnf \
    +            qemu-system-x86 \
    +            qemu-utils \
    +            ovmf \
    +            uidmap
    +
    +      - name: Read properties from versions.yaml
    +        working-directory: src/cloud-api-adaptor
    +        run: |
    +          {
    +            echo "GO_VERSION=$(./hack/versions.py -q tools.golang)"
    +            echo "MKOSI_VERSION=$(./hack/versions.py -q tools.mkosi)"
    +          } >> "$GITHUB_ENV"
    +
    +      - name: Setup Golang version ${{ env.GO_VERSION }}
    +        uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
    +        with:
    +          go-version: ${{ env.GO_VERSION }}
    +          cache-dependency-path: "**/go.sum"
    +
    +      - name: Build binaries
    +        id: build_binaries
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make podvm-binaries
    +
    +      - name: Build mkosi debug image
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make image-debug

    I do wonder if we can do any caching, or check if this build is available as it will take longer than the tests, but that's for future and not needed here.

    stevenhorsman stevenhorsman commented on Oct 02, 2026 15:14 UTC
    Reviewer

    This looks great, but I have a few comments, also, the first time I tried this it failed, but it passed on re-run which is maybe a combination of a timeout being a little low on a slow machine and the ssh client close issue mentioned below?

    sudo env "PATH=$PATH" "MKOSI_VERSION=$MKOSI_VERSION" make test-podvm TEST_PODVM_IMAGE=podvm/build/podvm-ubuntu-amd64.qcow2
    go: downloading github.com/spf13/cobra v1.10.0
    go: downloading github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.14.1
    go: downloading github.com/Azure/azure-sdk-for-go/sdk/azcore v1.23.1
    go: downloading github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4 v4.2.1
    go: downloading github.com/google/uuid v1.6.0
    go: downloading k8s.io/api v0.35.2
    go: downloading k8s.io/apimachinery v0.35.2
    go: downloading k8s.io/client-go v0.35.2
    go: downloading github.com/containerd/ttrpc v1.2.7
    go: downloading github.com/kata-containers/kata-containers/src/runtime v0.0.0-20260915102810-c7351e797eff
    go: downloading github.com/avast/retry-go/v4 v4.6.1
    go: downloading google.golang.org/protobuf v1.36.11
    go: downloading google.golang.org/grpc v1.83.2
    go: downloading github.com/containerd/containerd v1.7.36
    go: downloading github.com/pelletier/go-toml/v2 v2.1.0
    go: downloading github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f
    go: downloading golang.org/x/sys v0.48.0
    go: downloading github.com/fenglyu/go-dmidecode v0.0.0-20220417074508-03f52eb45fe9
    go: downloading github.com/klauspost/cpuid/v2 v2.3.0
    go: downloading github.com/coreos/go-iptables v0.6.0
    go: downloading github.com/moby/sys/mountinfo v0.7.2
    go: downloading github.com/opencontainers/runtime-spec v1.2.1
    go: downloading github.com/vishvananda/netlink v1.3.1
    go: downloading github.com/vishvananda/netns v0.0.5
    go: downloading golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
    go: downloading k8s.io/component-base v0.35.2
    go: downloading golang.org/x/crypto v0.57.0
    go: downloading github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0
    go: downloading github.com/AzureAD/microsoft-authentication-library-for-go v1.8.0
    go: downloading github.com/spf13/pflag v1.0.9
    go: downloading sigs.k8s.io/controller-runtime v0.23.1
    go: downloading k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
    go: downloading sigs.k8s.io/randfill v1.0.0
    go: downloading k8s.io/klog/v2 v2.130.1
    go: downloading github.com/containerd/log v0.1.0
    go: downloading google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d
    go: downloading github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
    go: downloading google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7
    go: downloading golang.org/x/net v0.59.0
    go: downloading github.com/pkg/sftp v1.13.9
    go: downloading k8s.io/cri-api v0.33.0
    go: downloading github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e
    go: downloading github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
    go: downloading github.com/kylelemons/godebug v1.1.0
    go: downloading k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
    go: downloading sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482
    go: downloading gopkg.in/inf.v0 v0.9.1
    go: downloading sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730
    go: downloading github.com/google/gnostic-models v0.7.0
    go: downloading golang.org/x/time v0.15.0
    go: downloading github.com/go-logr/logr v1.4.4
    go: downloading github.com/sirupsen/logrus v1.9.4
    go: downloading github.com/fxamacker/cbor/v2 v2.9.0
    go: downloading golang.org/x/term v0.46.0
    go: downloading golang.org/x/oauth2 v0.36.0
    go: downloading github.com/containerd/continuity v0.4.4
    go: downloading github.com/containerd/platforms v0.2.1
    go: downloading github.com/moby/sys/user v0.4.0
    go: downloading github.com/moby/sys/userns v0.1.0
    go: downloading github.com/opencontainers/image-spec v1.1.1
    go: downloading github.com/containerd/cgroups/v3 v3.0.5
    go: downloading github.com/opencontainers/selinux v1.13.1
    go: downloading tags.cncf.io/container-device-interface v1.0.1
    go: downloading github.com/kr/fs v0.1.0
    go: downloading github.com/gogo/protobuf v1.3.2
    go: downloading golang.org/x/sync v0.23.0
    go: downloading github.com/golang-jwt/jwt/v5 v5.3.1
    go: downloading github.com/json-iterator/go v1.1.12
    go: downloading go.yaml.in/yaml/v2 v2.4.4
    go: downloading go.yaml.in/yaml/v3 v3.0.5
    go: downloading sigs.k8s.io/yaml v1.6.0
    go: downloading github.com/x448/float16 v0.8.4
    go: downloading github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
    go: downloading github.com/containerd/typeurl/v2 v2.2.3
    go: downloading github.com/opencontainers/go-digest v1.0.0
    go: downloading github.com/containerd/containerd/api v1.9.0
    go: downloading github.com/containerd/fifo v1.1.0
    go: downloading github.com/containerd/errdefs v1.0.0
    go: downloading github.com/moby/sys/symlink v0.2.0
    go: downloading github.com/moby/sys/signal v0.7.0
    go: downloading github.com/fsnotify/fsnotify v1.9.0
    go: downloading github.com/opencontainers/runtime-tools v0.9.1-0.20250303011046-260e151b8552
    go: downloading tags.cncf.io/container-device-interface/specs-go v1.0.0
    go: downloading golang.org/x/text v0.42.0
    go: downloading github.com/go-openapi/swag v0.23.1
    go: downloading github.com/go-openapi/jsonreference v0.21.0
    go: downloading gopkg.in/evanphx/json-patch.v4 v4.13.0
    go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
    go: downloading github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee
    go: downloading github.com/klauspost/compress v1.18.7
    go: downloading github.com/distribution/reference v0.6.0
    go: downloading github.com/google/go-cmp v0.7.0
    go: downloading github.com/moby/locker v1.0.1
    go: downloading go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0
    go: downloading go.opentelemetry.io/otel v1.45.0
    go: downloading go.opentelemetry.io/otel/trace v1.45.0
    go: downloading github.com/cyphar/filepath-securejoin v0.6.0
    go: downloading golang.org/x/mod v0.41.0
    go: downloading github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
    go: downloading github.com/emicklei/go-restful/v3 v3.12.2
    go: downloading github.com/mailru/easyjson v0.9.0
    go: downloading github.com/go-openapi/jsonpointer v0.21.1
    go: downloading github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c
    go: downloading github.com/felixge/httpsnoop v1.0.4
    go: downloading go.opentelemetry.io/otel/metric v1.45.0
    go: downloading github.com/josharian/intern v1.0.0
    go: downloading github.com/go-logr/stdr v1.2.2
    go: downloading go.opentelemetry.io/auto/sdk v1.2.1
    go: downloading github.com/cespare/xxhash/v2 v2.3.0
    TEST_PODVM_IMAGE=/root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/podvm/build/podvm-ubuntu-amd64.qcow2 go test -v -timeout 5m -count=1 -run '' ./test/podvm
    go: downloading github.com/kdomanski/iso9660 v0.4.0
    go: downloading github.com/mdlayher/vsock v1.3.0
    go: downloading github.com/stretchr/testify v1.12.1
    go: downloading github.com/mdlayher/socket v0.6.0
    === RUN   TestDebugPodVM
    === RUN   TestDebugPodVM/ExecuteCommandOverVSock
    === RUN   TestDebugPodVM/ProvisionUserData
        podvm_test.go:116: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:116
                    Error:          Received unexpected error:
                                    wait for provisioned user data: context deadline exceeded (last error: run SSH command: context deadline exceeded)
                    Test:           TestDebugPodVM/ProvisionUserData
    === RUN   TestDebugPodVM/SystemdServices
    === RUN   TestDebugPodVM/SystemdServices/ProcessUserData
    === PAUSE TestDebugPodVM/SystemdServices/ProcessUserData
    === RUN   TestDebugPodVM/SystemdServices/AttestationAgent
    === PAUSE TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === PAUSE TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === RUN   TestDebugPodVM/SystemdServices/APIServerREST
    === PAUSE TestDebugPodVM/SystemdServices/APIServerREST
    === RUN   TestDebugPodVM/SystemdServices/KataAgent
    === PAUSE TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/ProcessUserData
    === CONT  TestDebugPodVM/SystemdServices/APIServerREST
    === CONT  TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === CONT  TestDebugPodVM/SystemdServices/AttestationAgent
    === NAME  TestDebugPodVM/SystemdServices/ProcessUserData
        podvm_test.go:139: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:139
                    Error:          Received unexpected error:
                                    wait for process-user-data.service: context deadline exceeded (last error: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection)
                                
                                    ==> systemd state <==
                                    failed to collect diagnostics: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection
                    Test:           TestDebugPodVM/SystemdServices/ProcessUserData
    === NAME  TestDebugPodVM/SystemdServices/ConfidentialDataHub
        podvm_test.go:139: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:139
                    Error:          Received unexpected error:
                                    wait for confidential-data-hub.service: context deadline exceeded (last error: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection)
                                
                                    ==> systemd state <==
                                    failed to collect diagnostics: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection
                    Test:           TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === CONT  TestDebugPodVM/SystemdServices/KataAgent
    === NAME  TestDebugPodVM/SystemdServices/AttestationAgent
        podvm_test.go:139: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:139
                    Error:          Received unexpected error:
                                    wait for attestation-agent.service: context deadline exceeded (last error: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection)
                                
                                    ==> systemd state <==
                                    failed to collect diagnostics: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection
                    Test:           TestDebugPodVM/SystemdServices/AttestationAgent
    === NAME  TestDebugPodVM/SystemdServices/APIServerREST
        podvm_test.go:139: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:139
                    Error:          Received unexpected error:
                                    wait for api-server-rest.service: context deadline exceeded (last error: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection)
                                
                                    ==> systemd state <==
                                    failed to collect diagnostics: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection
                    Test:           TestDebugPodVM/SystemdServices/APIServerREST
    === NAME  TestDebugPodVM/SystemdServices/KataAgent
        podvm_test.go:139: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:139
                    Error:          Received unexpected error:
                                    wait for kata-agent.service: context deadline exceeded (last error: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection)
    
                                    ==> systemd state <==
                                    failed to collect diagnostics: read vsock vm(4294967295):1996731343->vm(3):22: use of closed network connection
                    Test:           TestDebugPodVM/SystemdServices/KataAgent
    === RUN   TestDebugPodVM/ForwarderMutualTLS
        podvm_test.go:147: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:147
                    Error:          Received unexpected error:
                                    wait for agent protocol forwarder TLS: context deadline exceeded (last error: dial tcp 127.0.0.1:44333: i/o timeout)
                    Test:           TestDebugPodVM/ForwarderMutualTLS
    === RUN   TestDebugPodVM/KataAgentHealth
        podvm_test.go:153: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:153
                    Error:          Received unexpected error:
                                    wait for kata agent health: context deadline exceeded (last error: dial tcp 127.0.0.1:44333: i/o timeout)
                    Test:           TestDebugPodVM/KataAgentHealth
    === RUN   TestDebugPodVM/SandboxLifecycle
        podvm_test.go:161: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:161
                    Error:          Received unexpected error:
                                    read tcp 127.0.0.1:53428->127.0.0.1:44333: read: connection reset by peer
                    Test:           TestDebugPodVM/SandboxLifecycle
    --- FAIL: TestDebugPodVM (85.83s)
        --- PASS: TestDebugPodVM/ExecuteCommandOverVSock (0.04s)
        --- FAIL: TestDebugPodVM/ProvisionUserData (10.00s)
        --- FAIL: TestDebugPodVM/SystemdServices (0.00s)
            --- FAIL: TestDebugPodVM/SystemdServices/ProcessUserData (10.00s)
            --- FAIL: TestDebugPodVM/SystemdServices/ConfidentialDataHub (10.00s)
            --- FAIL: TestDebugPodVM/SystemdServices/AttestationAgent (10.00s)
            --- FAIL: TestDebugPodVM/SystemdServices/APIServerREST (10.00s)
            --- FAIL: TestDebugPodVM/SystemdServices/KataAgent (10.00s)
        --- FAIL: TestDebugPodVM/ForwarderMutualTLS (10.00s)
        --- FAIL: TestDebugPodVM/KataAgentHealth (10.00s)
        --- FAIL: TestDebugPodVM/SandboxLifecycle (0.00s)
    FAIL
    FAIL    github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm   85.862s
    FAIL
    make: *** [Makefile:119: test-podvm] Error 1
    root@sh-dev1:~/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor# sudo env "PATH=$PATH" "MKOSI_VERSION=$MKOSI_VERSION" make test-podvm TEST_PODVM_IMAGE=podvm/build/podvm-ubuntu-amd64.qcow2
    TEST_PODVM_IMAGE=/root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/podvm/build/podvm-ubuntu-amd64.qcow2 go test -v -timeout 5m -count=1 -run '' ./test/podvm
    === RUN   TestDebugPodVM
    === RUN   TestDebugPodVM/ExecuteCommandOverVSock
    === RUN   TestDebugPodVM/ProvisionUserData
    === RUN   TestDebugPodVM/SystemdServices
    === RUN   TestDebugPodVM/SystemdServices/ProcessUserData
    === PAUSE TestDebugPodVM/SystemdServices/ProcessUserData
    === RUN   TestDebugPodVM/SystemdServices/AttestationAgent
    === PAUSE TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === PAUSE TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === RUN   TestDebugPodVM/SystemdServices/APIServerREST
    === PAUSE TestDebugPodVM/SystemdServices/APIServerREST
    === RUN   TestDebugPodVM/SystemdServices/KataAgent
    === PAUSE TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/ProcessUserData
    === CONT  TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/APIServerREST
    === CONT  TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === CONT  TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/ForwarderMutualTLS
    === RUN   TestDebugPodVM/KataAgentHealth
    === RUN   TestDebugPodVM/SandboxLifecycle
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers/Message
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers/GetEvidence
    --- PASS: TestDebugPodVM (45.11s)
        --- PASS: TestDebugPodVM/ExecuteCommandOverVSock (0.02s)
        --- PASS: TestDebugPodVM/ProvisionUserData (0.07s)
        --- PASS: TestDebugPodVM/SystemdServices (0.00s)
            --- PASS: TestDebugPodVM/SystemdServices/ProcessUserData (2.39s)
            --- PASS: TestDebugPodVM/SystemdServices/ConfidentialDataHub (2.55s)
            --- PASS: TestDebugPodVM/SystemdServices/APIServerREST (2.56s)
            --- PASS: TestDebugPodVM/SystemdServices/KataAgent (2.57s)
            --- PASS: TestDebugPodVM/SystemdServices/AttestationAgent (2.07s)
        --- PASS: TestDebugPodVM/ForwarderMutualTLS (0.04s)
        --- PASS: TestDebugPodVM/KataAgentHealth (0.03s)
        --- PASS: TestDebugPodVM/SandboxLifecycle (3.98s)
            --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers (3.92s)
                --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers/Message (2.66s)
                --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers/GetEvidence (1.26s)
    PASS
    ok      github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm   45.129s
    

    mkulke mkulke commented on code on Oct 02, 2026 15:32 UTC
    Code Review
    .github/workflows/podvm_test.yaml:1
    @@ -0,0 +1,61 @@
    +name: PodVM test
    +
    +on:
    +  pull_request:
    +  workflow_dispatch:
    +
    +concurrency:
    +  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
    +  cancel-in-progress: true
    +
    +permissions: {}
    +
    +jobs:
    +  test:
    +    name: Test PodVM
    +    runs-on: 'ubuntu-24.04'
    +    permissions:
    +      contents: read  # Required to checkout code
    +    steps:
    +      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    +        with:
    +          persist-credentials: false
    +
    +      - name: Install dependencies
    +        run: |
    +          sudo apt-get update
    +          sudo apt-get install --no-install-recommends -y \
    +            alien \
    +            bubblewrap \
    +            dnf \
    +            qemu-system-x86 \
    +            qemu-utils \
    +            ovmf \
    +            uidmap
    +
    +      - name: Read properties from versions.yaml
    +        working-directory: src/cloud-api-adaptor
    +        run: |
    +          {
    +            echo "GO_VERSION=$(./hack/versions.py -q tools.golang)"
    +            echo "MKOSI_VERSION=$(./hack/versions.py -q tools.mkosi)"
    +          } >> "$GITHUB_ENV"
    +
    +      - name: Setup Golang version ${{ env.GO_VERSION }}
    +        uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
    +        with:
    +          go-version: ${{ env.GO_VERSION }}
    +          cache-dependency-path: "**/go.sum"
    +
    +      - name: Build binaries
    +        id: build_binaries
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make podvm-binaries
    +
    +      - name: Build mkosi debug image
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make image-debug

    you mean for re-running? we could decouple it into build/test jobs. otherwise, I think a rebuild of the image is intended, no? generally, I would hope that this test is very reliable b/c it has so little dependencies

    mkulke mkulke commented on code on Oct 02, 2026 15:33 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/qemu.go:1
    @@ -0,0 +1,336 @@
    +// (C) Copyright Confidential Containers Contributors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build linux && amd64
    +
    +package podvm
    +
    +import (
    +	"bytes"
    +	"context"
    +	"encoding/base64"
    +	"encoding/json"
    +	"errors"
    +	"fmt"
    +	"io"
    +	"net"
    +	"os"
    +	"os/exec"
    +	"path/filepath"
    +	"strconv"
    +	"syscall"
    +	"time"
    +
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
    +	"github.com/mdlayher/vsock"
    +	"golang.org/x/crypto/ssh"
    +)
    +
    +const (
    +	defaultGuestCID = 3
    +	sshPort         = 22
    +)
    +
    +type qemuConfig struct {
    +	image         string
    +	qemuBinary    string
    +	ovmfCode      string
    +	ovmfVars      string
    +	guestCID      uint32
    +	authorizedKey []byte
    +	userData      cloudinit.CloudConfigGenerator
    +}
    +
    +type qemuVM struct {
    +	cmd           *exec.Cmd
    +	done          chan struct{}
    +	waitErr       error
    +	guestCID      uint32
    +	qemuLog       string
    +	serialLog     string
    +	workDir       string
    +	hostKey       ssh.PublicKey
    +	forwarderAddr string
    +}
    +
    +type imageInfo struct {
    +	Format string `json:"format"`
    +}
    +
    +func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
    +	format, err := getImageFormat(config.image)
    +	if err != nil {
    +		return nil, err
    +	}
    +
    +	workDir, err := os.MkdirTemp("", "podvm-test-")
    +	if err != nil {
    +		return nil, fmt.Errorf("create temporary directory: %w", err)
    +	}
    +	defer func() {
    +		if err != nil {
    +			_ = os.RemoveAll(workDir)
    +		}
    +	}()
    +
    +	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
    +	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
    +		return nil, fmt.Errorf("copy OVMF variables: %w", err)
    +	}
    +
    +	serialLog := filepath.Join(workDir, "serial.log")
    +	qemuLog := filepath.Join(workDir, "qemu.log")
    +	configDrive := filepath.Join(workDir, "config-drive.iso")
    +	if err := createConfigDrive(configDrive, config.userData); err != nil {
    +		return nil, err
    +	}
    +	logFile, err := os.Create(qemuLog)
    +	if err != nil {
    +		return nil, fmt.Errorf("create QEMU log: %w", err)
    +	}
    +	defer logFile.Close()
    +
    +	forwarderListener, err := net.Listen("tcp", "127.0.0.1:0")
    +	if err != nil {
    +		return nil, fmt.Errorf("reserve agent protocol forwarder port: %w", err)
    +	}
    +	defer forwarderListener.Close()
    +	forwarderAddr := forwarderListener.Addr().String()
    +	_, forwarderPort, err := net.SplitHostPort(forwarderAddr)
    +	if err != nil {
    +		return nil, fmt.Errorf("parse agent protocol forwarder address: %w", err)
    +	}
    +
    +	args := []string{
    +		"-machine", "q35,accel=kvm",
    +		"-cpu", "host",
    +		"-m", "2048",
    +		"-smp", "2",
    +		"-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", config.ovmfCode),
    +		"-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", ovmfVars),
    +		"-drive", fmt.Sprintf("if=virtio,format=%s,file=%s,snapshot=on", format, config.image),
    +		"-drive", fmt.Sprintf("file=%s,media=cdrom,readonly=on", configDrive),
    +		"-device", fmt.Sprintf("vhost-vsock-pci,guest-cid=%d", config.guestCID),
    +		"-device", "virtio-rng-pci",
    +		"-netdev", fmt.Sprintf(
    +			"user,id=net0,hostfwd=tcp:127.0.0.1:%s-:%s",
    +			forwarderPort,
    +			forwarder.DefaultListenPort,
    +		),
    +		"-device", "virtio-net-pci,netdev=net0",
    +		"-display", "none",
    +		"-monitor", "none",
    +		"-serial", "file:" + serialLog,
    +		"-smbios", "type=11,value=io.systemd.credential.binary:ssh.ephemeral-authorized_keys-all=" +
    +			base64.StdEncoding.EncodeToString(config.authorizedKey),
    +	}
    +
    +	cmd := exec.Command(config.qemuBinary, args...)
    +	cmd.Stdout = logFile
    +	cmd.Stderr = logFile
    +	if err := forwarderListener.Close(); err != nil {
    +		return nil, fmt.Errorf("release agent protocol forwarder port: %w", err)
    +	}
    +	if err := cmd.Start(); err != nil {
    +		return nil, fmt.Errorf("start QEMU: %w", err)
    +	}
    +
    +	vm := &qemuVM{
    +		cmd:           cmd,
    +		done:          make(chan struct{}),
    +		guestCID:      config.guestCID,
    +		qemuLog:       qemuLog,
    +		serialLog:     serialLog,
    +		workDir:       workDir,
    +		forwarderAddr: forwarderAddr,
    +	}
    +	go func() {
    +		vm.waitErr = cmd.Wait()
    +		close(vm.done)
    +	}()
    +
    +	return vm, nil
    +}
    +
    +func (vm *qemuVM) close() {
    +	if vm.cmd.Process != nil {
    +		_ = vm.cmd.Process.Signal(syscall.SIGTERM)
    +		select {
    +		case <-vm.done:
    +		case <-time.After(5 * time.Second):
    +			_ = vm.cmd.Process.Kill()
    +			<-vm.done
    +		}
    +	}
    +	_ = os.RemoveAll(vm.workDir)
    +}
    +
    +func (vm *qemuVM) waitForSSH(ctx context.Context, signer ssh.Signer) (*ssh.Client, error) {
    +	ticker := time.NewTicker(500 * time.Millisecond)

    it wouldn't hurt to bump it to 1s

    mkulke mkulke commented on code on Oct 02, 2026 15:39 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/qemu.go:1
    @@ -0,0 +1,336 @@
    +// (C) Copyright Confidential Containers Contributors
    +// SPDX-License-Identifier: Apache-2.0
    +
    +//go:build linux && amd64
    +
    +package podvm
    +
    +import (
    +	"bytes"
    +	"context"
    +	"encoding/base64"
    +	"encoding/json"
    +	"errors"
    +	"fmt"
    +	"io"
    +	"net"
    +	"os"
    +	"os/exec"
    +	"path/filepath"
    +	"strconv"
    +	"syscall"
    +	"time"
    +
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/pkg/forwarder"
    +	"github.com/confidential-containers/cloud-api-adaptor/src/cloud-providers/util/cloudinit"
    +	"github.com/mdlayher/vsock"
    +	"golang.org/x/crypto/ssh"
    +)
    +
    +const (
    +	defaultGuestCID = 3
    +	sshPort         = 22
    +)
    +
    +type qemuConfig struct {
    +	image         string
    +	qemuBinary    string
    +	ovmfCode      string
    +	ovmfVars      string
    +	guestCID      uint32
    +	authorizedKey []byte
    +	userData      cloudinit.CloudConfigGenerator
    +}
    +
    +type qemuVM struct {
    +	cmd           *exec.Cmd
    +	done          chan struct{}
    +	waitErr       error
    +	guestCID      uint32
    +	qemuLog       string
    +	serialLog     string
    +	workDir       string
    +	hostKey       ssh.PublicKey
    +	forwarderAddr string
    +}
    +
    +type imageInfo struct {
    +	Format string `json:"format"`
    +}
    +
    +func startQEMU(config qemuConfig) (_ *qemuVM, err error) {
    +	format, err := getImageFormat(config.image)
    +	if err != nil {
    +		return nil, err
    +	}
    +
    +	workDir, err := os.MkdirTemp("", "podvm-test-")
    +	if err != nil {
    +		return nil, fmt.Errorf("create temporary directory: %w", err)
    +	}
    +	defer func() {
    +		if err != nil {
    +			_ = os.RemoveAll(workDir)
    +		}
    +	}()
    +
    +	ovmfVars := filepath.Join(workDir, "OVMF_VARS.fd")
    +	if err := copyFile(config.ovmfVars, ovmfVars); err != nil {
    +		return nil, fmt.Errorf("copy OVMF variables: %w", err)
    +	}
    +
    +	serialLog := filepath.Join(workDir, "serial.log")
    +	qemuLog := filepath.Join(workDir, "qemu.log")
    +	configDrive := filepath.Join(workDir, "config-drive.iso")
    +	if err := createConfigDrive(configDrive, config.userData); err != nil {
    +		return nil, err
    +	}
    +	logFile, err := os.Create(qemuLog)
    +	if err != nil {
    +		return nil, fmt.Errorf("create QEMU log: %w", err)
    +	}
    +	defer logFile.Close()

    that's sort of the case by assigning it to cmd.Stdout/Err, the logs should be open for writing by the qemu process while it runs

    mkulke mkulke commented on code on Oct 02, 2026 15:40 UTC
    Code Review
    src/cloud-api-adaptor/test/podvm/ssh.go:1
    @@ -0,0 +1,40 @@
    +package podvm
    +
    +import (
    +	"context"
    +	"fmt"
    +
    +	"golang.org/x/crypto/ssh"
    +)
    +

    yeah, the idea was to disable for platforms w/o kvm. we can add it in each file of this package

    stevenhorsman stevenhorsman commented on code on Oct 02, 2026 16:11 UTC
    Code Review
    .github/workflows/podvm_test.yaml:1
    @@ -0,0 +1,61 @@
    +name: PodVM test
    +
    +on:
    +  pull_request:
    +  workflow_dispatch:
    +
    +concurrency:
    +  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
    +  cancel-in-progress: true
    +
    +permissions: {}
    +
    +jobs:
    +  test:
    +    name: Test PodVM
    +    runs-on: 'ubuntu-24.04'
    +    permissions:
    +      contents: read  # Required to checkout code
    +    steps:
    +      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    +        with:
    +          persist-credentials: false
    +
    +      - name: Install dependencies
    +        run: |
    +          sudo apt-get update
    +          sudo apt-get install --no-install-recommends -y \
    +            alien \
    +            bubblewrap \
    +            dnf \
    +            qemu-system-x86 \
    +            qemu-utils \
    +            ovmf \
    +            uidmap
    +
    +      - name: Read properties from versions.yaml
    +        working-directory: src/cloud-api-adaptor
    +        run: |
    +          {
    +            echo "GO_VERSION=$(./hack/versions.py -q tools.golang)"
    +            echo "MKOSI_VERSION=$(./hack/versions.py -q tools.mkosi)"
    +          } >> "$GITHUB_ENV"
    +
    +      - name: Setup Golang version ${{ env.GO_VERSION }}
    +        uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
    +        with:
    +          go-version: ${{ env.GO_VERSION }}
    +          cache-dependency-path: "**/go.sum"
    +
    +      - name: Build binaries
    +        id: build_binaries
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make podvm-binaries
    +
    +      - name: Build mkosi debug image
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make image-debug

    I just mean in general as we will build the image a few times in our workflows I think and if it's a test only change we could try and grab an old build like we do in kata - that is admittedly fairly complex, so maybe it's not worth it yet.

    mkulke mkulke commented on Oct 02, 2026 16:20 UTC
    Author

    This looks great, but I have a few comments, also, the first time I tried this it failed, but it passed on re-run which is maybe a combination of a timeout being a little low on a slow machine and the ssh client close issue mentioned below?

    thanks for testing,. 45s is certainly longer than what I am seeing locally (~20s) and on the CI (~17s).

    I think you might have ran into a race condition in the podvm with mounting config disks, which makes the provisioning test fail, but this failing test also tears down the ssh client for every other test. the latter is bug in the test code, I'll have to fix that.

    mkulke mkulke commented on Oct 02, 2026 16:32 UTC
    Author

    > This looks great, but I have a few comments, also, the first time I tried this it failed, but it passed on re-run which is maybe a combination of a timeout being a little low on a slow machine and the ssh client close issue mentioned below?

    > thanks for testing,. 45s is certainly longer than what I am seeing locally (~20s) and on the CI (~17s).

    > I think you might have ran into a race condition in the podvm with mounting config disks, which makes the provisioning test fail, but this failing test also tears down the ssh client for every other test. the latter is bug in the test code, I'll have to fix that.

    ok, now it's using a dedicated ssh connection for each test and I bumped the timeout for the provisioning test to 15s, but we probably shouldn't increase it more. that really points to something being borked if provisioning is not done 15s after ssh is up.

    mkulke mkulke commented on code on Oct 02, 2026 16:35 UTC
    Code Review
    .github/workflows/podvm_test.yaml:1
    @@ -0,0 +1,61 @@
    +name: PodVM test
    +
    +on:
    +  pull_request:
    +  workflow_dispatch:
    +
    +concurrency:
    +  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
    +  cancel-in-progress: true
    +
    +permissions: {}
    +
    +jobs:
    +  test:
    +    name: Test PodVM
    +    runs-on: 'ubuntu-24.04'
    +    permissions:
    +      contents: read  # Required to checkout code
    +    steps:
    +      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    +        with:
    +          persist-credentials: false
    +
    +      - name: Install dependencies
    +        run: |
    +          sudo apt-get update
    +          sudo apt-get install --no-install-recommends -y \
    +            alien \
    +            bubblewrap \
    +            dnf \
    +            qemu-system-x86 \
    +            qemu-utils \
    +            ovmf \
    +            uidmap
    +
    +      - name: Read properties from versions.yaml
    +        working-directory: src/cloud-api-adaptor
    +        run: |
    +          {
    +            echo "GO_VERSION=$(./hack/versions.py -q tools.golang)"
    +            echo "MKOSI_VERSION=$(./hack/versions.py -q tools.mkosi)"
    +          } >> "$GITHUB_ENV"
    +
    +      - name: Setup Golang version ${{ env.GO_VERSION }}
    +        uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
    +        with:
    +          go-version: ${{ env.GO_VERSION }}
    +          cache-dependency-path: "**/go.sum"
    +
    +      - name: Build binaries
    +        id: build_binaries
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make podvm-binaries
    +
    +      - name: Build mkosi debug image
    +        working-directory: src/cloud-api-adaptor/podvm
    +        run: make image-debug

    hmm yeah, for just changing test code that could make sense. but not sure it's worth it, either. the podvm build is pretty fast. If tests are developed I would run this locally

    mkulke mkulke commented on Oct 02, 2026 16:44 UTC
    Author

    good, now there is a test run on the CI that reproduces the problem and isolated it more clearly: SSH is up, services are up, but it the PodVM is misconfigured because the config-drive is not available in time.

    https://github.com/confidential-containers/cloud-api-adaptor/actions/runs/37034424135/job/110928976186?pr=3361

    I am trying to address this in another PR, it's hairy.

    stevenhorsman stevenhorsman commented on Oct 02, 2026 16:45 UTC
    Contributor

    > > This looks great, but I have a few comments, also, the first time I tried this it failed, but it passed on re-run which is maybe a combination of a timeout being a little low on a slow machine and the ssh client close issue mentioned below?

    >

    >

    > thanks for testing,. 45s is certainly longer than what I am seeing locally (~20s) and on the CI (~17s).

    > I think you might have ran into a race condition in the podvm with mounting config disks, which makes the provisioning test fail, but this failing test also tears down the ssh client for every other test. the latter is bug in the test code, I'll have to fix that.

    > ok, now it's using a dedicated ssh connection for each test and I bumped the timeout for the provisioning test to 15s, but we probably shouldn't increase it more. that really points to something being borked if provisioning is not done 15s after ssh is up.

    For reference I ran it on a 4 vCPU, 8GB RAM VM. I've updating to the latest code and re-ran twice and got passing first time, failing second:

    sudo env "PATH=$PATH" "MKOSI_VERSION=$MKOSI_VERSION" make test-podvm TEST_PODVM_IMAGE=podvm/build/podvm-ubuntu-amd64.qcow2
    TEST_PODVM_IMAGE=/root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/podvm/build/podvm-ubuntu-amd64.qcow2 go test -v -timeout 5m -count=1 -run '' ./test/podvm
    === RUN   TestDebugPodVM
    === RUN   TestDebugPodVM/ExecuteCommandOverVSock
    === RUN   TestDebugPodVM/ProvisionUserData
    === RUN   TestDebugPodVM/SystemdServices
    === RUN   TestDebugPodVM/SystemdServices/ProcessUserData
    === PAUSE TestDebugPodVM/SystemdServices/ProcessUserData
    === RUN   TestDebugPodVM/SystemdServices/AttestationAgent
    === PAUSE TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === PAUSE TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === RUN   TestDebugPodVM/SystemdServices/APIServerREST
    === PAUSE TestDebugPodVM/SystemdServices/APIServerREST
    === RUN   TestDebugPodVM/SystemdServices/KataAgent
    === PAUSE TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/ProcessUserData
    === CONT  TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/APIServerREST
    === CONT  TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === CONT  TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/ForwarderMutualTLS
    === RUN   TestDebugPodVM/KataAgentHealth
    === RUN   TestDebugPodVM/SandboxLifecycle
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers/Message
    === RUN   TestDebugPodVM/SandboxLifecycle/LaunchContainers/GetEvidence
    --- PASS: TestDebugPodVM (46.74s)
        --- PASS: TestDebugPodVM/ExecuteCommandOverVSock (0.27s)
        --- PASS: TestDebugPodVM/ProvisionUserData (0.49s)
        --- PASS: TestDebugPodVM/SystemdServices (0.00s)
            --- PASS: TestDebugPodVM/SystemdServices/ProcessUserData (3.08s)
            --- PASS: TestDebugPodVM/SystemdServices/APIServerREST (3.13s)
            --- PASS: TestDebugPodVM/SystemdServices/ConfidentialDataHub (3.16s)
            --- PASS: TestDebugPodVM/SystemdServices/KataAgent (3.19s)
            --- PASS: TestDebugPodVM/SystemdServices/AttestationAgent (2.30s)
        --- PASS: TestDebugPodVM/ForwarderMutualTLS (0.04s)
        --- PASS: TestDebugPodVM/KataAgentHealth (0.03s)
        --- PASS: TestDebugPodVM/SandboxLifecycle (3.50s)
            --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers (3.43s)
                --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers/Message (2.22s)
                --- PASS: TestDebugPodVM/SandboxLifecycle/LaunchContainers/GetEvidence (1.22s)
    PASS
    ok      github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm   46.765s
    root@sh-dev1:~/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor# free
                   total        used        free      shared  buff/cache   available
    Mem:         8131792     1818872     3192632        2652     3436376     6312920
    Swap:        2097148       36640     2060508
    root@sh-dev1:~/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor# sudo env "PATH=$PATH" "MKOSI_VERSION=$MKOSI_VERSION" make test-podvm TEST_PODVM_IMAGE=podvm/build/podvm-ubuntu-amd64.qcow2
    TEST_PODVM_IMAGE=/root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/podvm/build/podvm-ubuntu-amd64.qcow2 go test -v -timeout 5m -count=1 -run '' ./test/podvm
    === RUN   TestDebugPodVM
    === RUN   TestDebugPodVM/ExecuteCommandOverVSock
    === RUN   TestDebugPodVM/ProvisionUserData
        podvm_test.go:116: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:116
                    Error:          Received unexpected error:
                                    wait for provisioned user data: context deadline exceeded (last error: run SSH command: context deadline exceeded)
                    Test:           TestDebugPodVM/ProvisionUserData
    === RUN   TestDebugPodVM/SystemdServices
    === RUN   TestDebugPodVM/SystemdServices/ProcessUserData
    === PAUSE TestDebugPodVM/SystemdServices/ProcessUserData
    === RUN   TestDebugPodVM/SystemdServices/AttestationAgent
    === PAUSE TestDebugPodVM/SystemdServices/AttestationAgent
    === RUN   TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === PAUSE TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === RUN   TestDebugPodVM/SystemdServices/APIServerREST
    === PAUSE TestDebugPodVM/SystemdServices/APIServerREST
    === RUN   TestDebugPodVM/SystemdServices/KataAgent
    === PAUSE TestDebugPodVM/SystemdServices/KataAgent
    === CONT  TestDebugPodVM/SystemdServices/ProcessUserData
    === CONT  TestDebugPodVM/SystemdServices/APIServerREST
    === CONT  TestDebugPodVM/SystemdServices/ConfidentialDataHub
    === CONT  TestDebugPodVM/SystemdServices/AttestationAgent
    === CONT  TestDebugPodVM/SystemdServices/KataAgent
    === RUN   TestDebugPodVM/ForwarderMutualTLS
        podvm_test.go:147: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:147
                    Error:          Received unexpected error:
                                    wait for agent protocol forwarder TLS: context deadline exceeded (last error: read tcp 127.0.0.1:39302->127.0.0.1:44195: read: connection reset by peer)
                    Test:           TestDebugPodVM/ForwarderMutualTLS
    === RUN   TestDebugPodVM/KataAgentHealth
        podvm_test.go:153: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:153
                    Error:          Received unexpected error:
                                    wait for kata agent health: context deadline exceeded (last error: dial tcp 127.0.0.1:44195: i/o timeout)
                    Test:           TestDebugPodVM/KataAgentHealth
    === RUN   TestDebugPodVM/SandboxLifecycle
        podvm_test.go:161: 
                    Error Trace:    /root/go/src/github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm/podvm_test.go:161
                    Error:          Received unexpected error:
                                    read tcp 127.0.0.1:49408->127.0.0.1:44195: read: connection reset by peer
                    Test:           TestDebugPodVM/SandboxLifecycle
    --- FAIL: TestDebugPodVM (76.92s)
        --- PASS: TestDebugPodVM/ExecuteCommandOverVSock (0.42s)
        --- FAIL: TestDebugPodVM/ProvisionUserData (15.10s)
        --- PASS: TestDebugPodVM/SystemdServices (0.00s)
            --- PASS: TestDebugPodVM/SystemdServices/APIServerREST (2.47s)
            --- PASS: TestDebugPodVM/SystemdServices/ProcessUserData (2.49s)
            --- PASS: TestDebugPodVM/SystemdServices/AttestationAgent (2.56s)
            --- PASS: TestDebugPodVM/SystemdServices/ConfidentialDataHub (2.56s)
            --- PASS: TestDebugPodVM/SystemdServices/KataAgent (2.31s)
        --- FAIL: TestDebugPodVM/ForwarderMutualTLS (10.00s)
        --- FAIL: TestDebugPodVM/KataAgentHealth (10.00s)
        --- FAIL: TestDebugPodVM/SandboxLifecycle (0.00s)
    FAIL
    FAIL    github.com/confidential-containers/cloud-api-adaptor/src/cloud-api-adaptor/test/podvm   76.947s
    FAIL
    

    If I don't meet the system requirements with this VM then I don't want to block this, but shared it in case it's helpful

    mkulke mkulke commented on Oct 02, 2026 16:55 UTC
    Author

    For reference I ran it on a 4 vCPU, 8GB RAM VM. I've updating to the latest code and re-ran twice and got passing first time, failing second:

    > If I don't meet the system requirements with this VM then I don't want to block this, but shared it in case it's helpful

    no, it's good, I suspect low specs surface a race that we have with the config disk in general. (it should not allow to continue if it fails to mount the config disk). I cannot reproduce it reliably locally and I have only seen it once on the CI either, maybe I should limit the specs for a repro.

    mkulke mkulke commented on Oct 03, 2026 15:51 UTC
    Author

    The tests seem to run reliable now (configured to run 20 times), so I'm somewhat confident that issues are either identified or addressed.

    putting this back to draft for now until at least #3367 is resolved, there is also an ttrpc issue on shutdown that already bit us elsewhere, but we can ignore it for now I think.

    Reviewers
    Assignees
    mkulke mkulke
    Labels
    risk: low confidence: 84.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 85.5% (HIGH) · Higher = larger blast radius
    85.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.0% · Lower = rushed or shallow review
    84.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.7% · Safe to merge
    13.7%