Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
for version in v49.0 v51.1; do
for version in v51.2; do
for architecture in x86_64 aarch64; do
if [ "$architecture" = "x86_64" ]; then
asset="cloud-hypervisor-static"
Expand Down
25 changes: 10 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,16 @@ $(XCADDY): | $(BIN_DIR)

install-tools: $(OAPI_CODEGEN) $(AIR) $(WIRE) $(XCADDY)

# Download Cloud Hypervisor binaries (both v49.0 and v51.1 for backwards-compatible upgrades)
# Download Cloud Hypervisor binaries. Older releases are no longer shipped:
# CVE-2026-45782 is fixed in v51.2.
download-ch-binaries:
@echo "Downloading Cloud Hypervisor binaries..."
@mkdir -p lib/vmm/binaries/cloud-hypervisor/v49.0/{x86_64,aarch64}
@mkdir -p lib/vmm/binaries/cloud-hypervisor/v51.1/{x86_64,aarch64}
@echo "Downloading v49.0..."
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v49.0/x86_64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v49.0/cloud-hypervisor-static
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v49.0/aarch64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v49.0/cloud-hypervisor-static-aarch64
@echo "Downloading v51.1..."
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v51.1/x86_64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v51.1/cloud-hypervisor-static
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v51.1/aarch64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v51.1/cloud-hypervisor-static-aarch64
@mkdir -p lib/vmm/binaries/cloud-hypervisor/v51.2/{x86_64,aarch64}
@echo "Downloading v51.2..."
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v51.2/x86_64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v51.2/cloud-hypervisor-static
@curl -L -o lib/vmm/binaries/cloud-hypervisor/v51.2/aarch64/cloud-hypervisor \
https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v51.2/cloud-hypervisor-static-aarch64
@chmod +x lib/vmm/binaries/cloud-hypervisor/v*/*/cloud-hypervisor
@echo "Binaries downloaded successfully"

Expand Down Expand Up @@ -132,7 +127,7 @@ download-ch-spec:
@echo "Downloading Cloud Hypervisor API spec..."
@mkdir -p specs/cloud-hypervisor/api-v0.3.0
@curl -L -o specs/cloud-hypervisor/api-v0.3.0/cloud-hypervisor.yaml \
https://raw.githubusercontent.com/cloud-hypervisor/cloud-hypervisor/refs/tags/v51.1/vmm/src/api/openapi/cloud-hypervisor.yaml
https://raw.githubusercontent.com/cloud-hypervisor/cloud-hypervisor/refs/tags/v51.2/vmm/src/api/openapi/cloud-hypervisor.yaml
@echo "API spec downloaded"

# Generate Go code from OpenAPI spec
Expand Down Expand Up @@ -187,7 +182,7 @@ ensure-ch-binaries:
echo "Unsupported architecture: $$ARCH"; exit 1; \
fi; \
NEEDS_DOWNLOAD=0; \
for CH_VERSION in v49.0 v51.1; do \
for CH_VERSION in v51.2; do \
CH_BIN=lib/vmm/binaries/cloud-hypervisor/$$CH_VERSION/$$CH_ARCH/cloud-hypervisor; \
if [ ! -f "$$CH_BIN" ]; then \
echo "Cloud Hypervisor binary not found: $$CH_BIN"; \
Expand Down
2 changes: 1 addition & 1 deletion lib/hypervisor/cloudhypervisor/cloudhypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func CapabilitiesForVersion(v vmm.CHVersion) hypervisor.Capabilities {
SupportsSnapshotBaseReuse: false,
}
switch v {
case vmm.V51_1:
case vmm.V51_2:
caps.SupportsDiskResize = true
}
return caps
Expand Down
4 changes: 2 additions & 2 deletions lib/hypervisor/cloudhypervisor/register_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "github.com/kernel/hypeman/lib/hypervisor"
// Cloud Hypervisor requires KVM, so registration — and therefore its
// presence in hypervisor.RegisteredRuntimes — is Linux-only. Capabilities
// are resolved per registry read from the configured default version (which
// SetDefaultVersion may change after init, e.g. pinning v49.0 without
// disk-resize) rather than frozen from the compile-time default. No
// SetDefaultVersion may change after init, e.g. legacy v49.0 instances
// without disk-resize) rather than frozen from the compile-time default. No
// LaunchCheck: the binaries for every supported version ship embedded in
// hypeman.
func init() {
Expand Down
16 changes: 7 additions & 9 deletions lib/hypervisor/cloudhypervisor/register_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ import (
// boundary: the capability registry must resolve cloud-hypervisor
// capabilities from the configured default version at read time, not from a
// value frozen at package init. v49.0 lacks live disk resize; advertising it
// would misreport what ordinary configured launches can do.
// would misreport what ordinary configured launches can do. v49.0 is no
// longer shipped, but legacy instances keep its capabilities.
//
// Not parallel: it mutates the process-wide configured default version.
func TestRegisteredCapabilitiesTrackConfiguredDefaultVersion(t *testing.T) {
t.Cleanup(func() { require.NoError(t, SetDefaultVersion("")) })

require.NoError(t, SetDefaultVersion(string(vmm.V49_0)))
require.NoError(t, SetDefaultVersion(string(vmm.V51_2)))
caps, ok := hypervisor.CapabilitiesForType(hypervisor.TypeCloudHypervisor)
require.True(t, ok, "cloud-hypervisor must be registered on Linux")
require.False(t, caps.SupportsDiskResize, "a v49.0 default must not advertise disk-resize")
require.NotContains(t, caps.FeatureIDs(), hypervisor.FeatureDiskResize)

require.NoError(t, SetDefaultVersion(string(vmm.V51_1)))
caps, ok = hypervisor.CapabilitiesForType(hypervisor.TypeCloudHypervisor)
require.True(t, ok)
require.True(t, caps.SupportsDiskResize, "a v51.1 default must advertise disk-resize")
require.True(t, caps.SupportsDiskResize, "a v51.2 default must advertise disk-resize")
require.Contains(t, caps.FeatureIDs(), hypervisor.FeatureDiskResize)

require.False(t, CapabilitiesForVersion(vmm.CHVersion("v49.0")).SupportsDiskResize,
"a legacy v49.0 instance must not advertise disk-resize")

// The registry enumeration used by the capabilities endpoint must agree
// with the per-type lookup.
for _, rt := range hypervisor.RegisteredRuntimes() {
Expand Down
35 changes: 35 additions & 0 deletions lib/instances/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,26 @@ func isSystemDirectory(path string) bool {
return false
}

// resolveStartVersion maps the version stored in instance metadata onto one the
// starter can still launch. An upgrade can drop a build from the supported set
// (a vulnerable one, say), but a stopped instance keeps its pinned version, so a
// cold start falls back to the starter's default instead of failing forever.
// fellBack reports whether the requested version was unusable.
func resolveStartVersion(requested string, resolve func(requested string) (string, error)) (string, bool, error) {
version, err := resolve(requested)
if err == nil {
return version, false, nil
}
if requested == "" {
return "", false, err
}
fallback, fallbackErr := resolve("")
if fallbackErr != nil {
return "", false, err
}
return fallback, true, nil
}

// startAndBootVM starts the VMM and boots the VM
func (m *manager) startAndBootVM(
ctx context.Context,
Expand Down Expand Up @@ -838,6 +858,21 @@ func (m *manager) startAndBootVM(
stored.HypervisorVersion = resolvedVersion
}

// A stored version may no longer be supported (for example a dropped
// vulnerable build); boot on the starter default instead of failing.
resolvedVersion, fellBack, err := resolveStartVersion(stored.HypervisorVersion, func(requested string) (string, error) {
return starter.ResolveVersion(m.paths, requested)
})
if err != nil {
return fmt.Errorf("resolve version for hypervisor %s start: %w", stored.HypervisorType, err)
}
if fellBack {
log.WarnContext(ctx, "stored hypervisor version unsupported, using default",
"instance_id", stored.Id, "hypervisor", stored.HypervisorType,
"stored_version", stored.HypervisorVersion, "version", resolvedVersion)
}
stored.HypervisorVersion = resolvedVersion

// Build VM configuration
inst := &Instance{StoredMetadata: *stored}
vmConfig, err := m.buildHypervisorConfig(ctx, inst, imageInfo, netConfig)
Expand Down
117 changes: 117 additions & 0 deletions lib/instances/hypervisor_version_fallback_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package instances

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/kernel/hypeman/lib/hypervisor"
"github.com/kernel/hypeman/lib/images"
"github.com/kernel/hypeman/lib/paths"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestResolveStartVersion(t *testing.T) {
unsupported := errors.New("unsupported cloud-hypervisor version: v51.1")

resolver := func(requested string) (string, error) {
if requested == "" {
return "v51.2", nil
}
if requested != "v51.2" {
return "", unsupported
}
return requested, nil
}

t.Run("supported version is kept", func(t *testing.T) {
version, fellBack, err := resolveStartVersion("v51.2", resolver)
require.NoError(t, err)
assert.Equal(t, "v51.2", version)
assert.False(t, fellBack)
})

t.Run("removed version falls back to default", func(t *testing.T) {
version, fellBack, err := resolveStartVersion("v51.1", resolver)
require.NoError(t, err)
assert.Equal(t, "v51.2", version)
assert.True(t, fellBack)
})

t.Run("both resolutions failing returns the error", func(t *testing.T) {
_, _, err := resolveStartVersion("v51.1", func(string) (string, error) {
return "", unsupported
})
require.ErrorIs(t, err, unsupported)
})
}

// versionFallbackStarter mimics a host where only the default version exists.
type versionFallbackStarter struct {
startedVersion string
}

func (s *versionFallbackStarter) ValidateConfig(hypervisor.VMConfig) error { return nil }
func (s *versionFallbackStarter) SocketName() string { return "version-fallback.sock" }
func (s *versionFallbackStarter) GetBinaryPath(*paths.Paths, string) (string, error) {
return "", nil
}
func (s *versionFallbackStarter) GetVersion(*paths.Paths) (string, error) { return "v51.2", nil }
func (s *versionFallbackStarter) ResolveVersion(_ *paths.Paths, requested string) (string, error) {
if requested == "" || requested == "v51.2" {
return "v51.2", nil
}
return "", fmt.Errorf("unsupported cloud-hypervisor version: %s", requested)
}
func (s *versionFallbackStarter) StartVM(_ context.Context, _ *paths.Paths, version, _ string, _ hypervisor.VMConfig) (int, hypervisor.Hypervisor, error) {
s.startedVersion = version
return 0, lifecycleNoopHypervisor{state: hypervisor.StateRunning}, nil
}
func (s *versionFallbackStarter) RestoreVM(context.Context, *paths.Paths, string, string, string) (int, hypervisor.Hypervisor, error) {
return 0, nil, fmt.Errorf("restore must not be attempted")
}
func (s *versionFallbackStarter) PrepareFork(context.Context, hypervisor.ForkPrepareRequest) (hypervisor.ForkPrepareResult, error) {
return hypervisor.ForkPrepareResult{}, nil
}

// TestStartAndBootVMFallsBackForRemovedVersion drives a cold start whose
// on-disk metadata pins a version the starter no longer supports.
func TestStartAndBootVMFallsBackForRemovedVersion(t *testing.T) {
mgr, dataDir := setupTestManager(t)
hvType := hypervisor.Type("version-fallback-test")
starter := &versionFallbackStarter{}
mgr.vmStarters[hvType] = starter

id := "version-fallback"
dir := filepath.Join(dataDir, "guests", id)
require.NoError(t, os.MkdirAll(dir, 0o755))
seed := StoredMetadata{
Id: id,
Name: id,
HypervisorType: hvType,
HypervisorVersion: "v51.1",
KernelVersion: "ch-v6.12.9",
SocketPath: filepath.Join(dir, "version-fallback.sock"),
}
raw, err := json.Marshal(&seed)
require.NoError(t, err)
require.NoError(t, os.WriteFile(filepath.Join(dir, "metadata.json"), raw, 0o644))

loaded, err := mgr.loadMetadata(id)
require.NoError(t, err)
require.Equal(t, "v51.1", loaded.HypervisorVersion)

img := &images.Image{Name: "proof", Digest: "sha256:" + strings.Repeat("0", 64)}
err = mgr.startAndBootVM(context.Background(), &loaded.StoredMetadata, img, nil, true)
t.Logf("startAndBootVM: %v, StartVM version: %q, stored version: %q",
err, starter.startedVersion, loaded.HypervisorVersion)
require.NoError(t, err)
assert.Equal(t, "v51.2", starter.startedVersion)
assert.Equal(t, "v51.2", loaded.HypervisorVersion)
}
2 changes: 1 addition & 1 deletion lib/instances/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ func TestStorageOperations(t *testing.T) {
Env: map[string]string{"TEST": "value"},
CreatedAt: time.Now(),
HypervisorType: hypervisor.TypeCloudHypervisor,
HypervisorVersion: string(vmm.V51_1),
HypervisorVersion: string(vmm.V51_2),
SocketPath: "/tmp/test.sock",
DataDir: paths.New(tmpDir).InstanceDir("test-123"),
}
Expand Down
2 changes: 1 addition & 1 deletion lib/instances/restore_image_missing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestRestoreInstanceMissingImageReturnsNotFoundFast(t *testing.T) {
Vcpus: 1,
CreatedAt: time.Now(),
HypervisorType: hypervisor.TypeCloudHypervisor,
HypervisorVersion: string(vmm.V51_1),
HypervisorVersion: string(vmm.V51_2),
// A socket path that does not exist forces deriveState down the
// no-socket branch, where a present snapshot dir yields Standby.
SocketPath: filepath.Join(tmpDir, id, "nonexistent.sock"),
Expand Down
2 changes: 1 addition & 1 deletion lib/instances/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type StoredMetadata struct {

// Hypervisor configuration
HypervisorType hypervisor.Type // Hypervisor type (e.g., "cloud-hypervisor")
HypervisorVersion string // Hypervisor version (e.g., "v51.1")
HypervisorVersion string // Hypervisor version (e.g., "v51.2")
// Embedded so its fields keep their flat JSON keys in persisted metadata.
HypervisorProcessIdentity

Expand Down
38 changes: 18 additions & 20 deletions lib/instances/version_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import (
"github.com/stretchr/testify/require"
)

// TestCloudHypervisorVersionUpgradeRestore verifies that instances created on
// one CH version can be put in standby and restored after the default version
// changes. This tests the backwards-compatible upgrade path: deploy new binary
// with both versions embedded, flip the flag, and existing standbys still
// restore using their original version.
// TestCloudHypervisorVersionUpgradeRestore verifies that a standby instance is
// restored with the CH version stored in its metadata, while new instances
// follow the configured default version.
func TestCloudHypervisorVersionUpgradeRestore(t *testing.T) {
t.Parallel()
if _, err := os.Stat("/dev/kvm"); os.IsNotExist(err) {
Expand Down Expand Up @@ -64,8 +62,8 @@ func TestCloudHypervisorVersionUpgradeRestore(t *testing.T) {
_ = cloudhypervisor.SetDefaultVersion("")
})

// Phase 1: Create instance with explicit v49.0 version
t.Log("Creating instance with CH v49.0...")
// Phase 1: Create instance with an explicit version
t.Log("Creating instance with an explicit CH version...")
inst, err := mgr.CreateInstance(ctx, CreateInstanceRequest{
Name: "version-upgrade-test",
Image: integrationTestImageRef(t, "docker.io/library/alpine:latest"),
Expand All @@ -74,11 +72,11 @@ func TestCloudHypervisorVersionUpgradeRestore(t *testing.T) {
Vcpus: 1,
NetworkEnabled: false,
Hypervisor: hypervisor.TypeCloudHypervisor,
HypervisorVersion: string(vmm.V49_0),
HypervisorVersion: string(vmm.V51_2),
Cmd: []string{"sleep", "infinity"},
})
require.NoError(t, err)
assert.Equal(t, string(vmm.V49_0), inst.HypervisorVersion)
assert.Equal(t, string(vmm.V51_2), inst.HypervisorVersion)
t.Logf("Instance created: %s (version: %s)", inst.Id, inst.HypervisorVersion)

inst, err = waitForInstanceState(ctx, mgr, inst.Id, StateRunning, integrationTestTimeout(20*time.Second))
Expand All @@ -94,25 +92,25 @@ func TestCloudHypervisorVersionUpgradeRestore(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, StateStandby, inst.State)
assert.True(t, inst.HasSnapshot)
assert.Equal(t, string(vmm.V49_0), inst.HypervisorVersion)
assert.Equal(t, string(vmm.V51_2), inst.HypervisorVersion)

// Phase 3: Change default version to v51.1 (simulates a deploy with new config)
t.Log("Switching default CH version to v51.1...")
require.NoError(t, cloudhypervisor.SetDefaultVersion(string(vmm.V51_1)))
// Phase 3: Set the default version (simulates a deploy with new config)
t.Log("Setting default CH version...")
require.NoError(t, cloudhypervisor.SetDefaultVersion(string(vmm.V51_2)))

// Phase 4: Restore -- must use the stored v49.0, not the new default
t.Log("Restoring instance (should use stored v49.0)...")
// Phase 4: Restore -- must use the stored version
t.Log("Restoring instance (should use stored version)...")
inst, err = mgr.RestoreInstance(ctx, inst.Id)
require.NoError(t, err)
inst, err = waitForInstanceState(ctx, mgr, inst.Id, StateRunning, integrationTestTimeout(20*time.Second))
require.NoError(t, err)
assert.Equal(t, StateRunning, inst.State)
assert.Equal(t, string(vmm.V49_0), inst.HypervisorVersion,
"Restored instance must use original version, not the new default")
assert.Equal(t, string(vmm.V51_2), inst.HypervisorVersion,
"Restored instance must use its stored version")
t.Logf("Instance restored with version: %s", inst.HypervisorVersion)

// Phase 5: Verify a NEW instance picks up the v51.1 default
t.Log("Creating second instance (should use v51.1 via default)...")
// Phase 5: Verify a NEW instance picks up the configured default
t.Log("Creating second instance (should use the default version)...")
inst2, err := mgr.CreateInstance(ctx, CreateInstanceRequest{
Name: "version-upgrade-new",
Image: integrationTestImageRef(t, "docker.io/library/alpine:latest"),
Expand All @@ -124,7 +122,7 @@ func TestCloudHypervisorVersionUpgradeRestore(t *testing.T) {
Cmd: []string{"sleep", "infinity"},
})
require.NoError(t, err)
assert.Equal(t, string(vmm.V51_1), inst2.HypervisorVersion,
assert.Equal(t, string(vmm.V51_2), inst2.HypervisorVersion,
"New instance should use the updated default version")
t.Logf("New instance created: %s (version: %s)", inst2.Id, inst2.HypervisorVersion)

Expand Down
4 changes: 2 additions & 2 deletions lib/system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Manages versioned kernel and initrd files for Cloud Hypervisor VMs.

**Snapshots require exact matches:**
```
Standby: kernel ch-6.12.8-kernel-1.2-20251213, CH v51.1
Restore: kernel ch-6.12.8-kernel-1.2-20251213, CH v51.1 (MUST match)
Standby: kernel ch-6.12.8-kernel-1.2-20251213, CH v51.2
Restore: kernel ch-6.12.8-kernel-1.2-20251213, CH v51.2 (MUST match)
```

**Maintenance upgrades (shutdown → boot):**
Expand Down
Loading