Skip to content
Merged
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
3 changes: 0 additions & 3 deletions microvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ func Run(ctx context.Context, imageRef string, opts ...Option) (*VM, error) {

// Egress policy validation.
if cfg.egressPolicy != nil {
if len(cfg.egressPolicy.AllowedHosts) == 0 {
return nil, fmt.Errorf("egress policy: AllowedHosts must not be empty")
}
for i, h := range cfg.egressPolicy.AllowedHosts {
if h.Name == "" {
return nil, fmt.Errorf("egress policy: AllowedHosts[%d].Name must not be empty", i)
Expand Down
24 changes: 22 additions & 2 deletions microvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,24 @@ func TestBuildNetConfig_WithEgressPolicy(t *testing.T) {
assert.Equal(t, uint8(0), netCfg.EgressPolicy.AllowedHosts[1].Protocol)
}

func TestBuildNetConfig_WithEgressPolicy_DenyAll(t *testing.T) {
t.Parallel()

cfg := defaultConfig()
cfg.egressPolicy = &EgressPolicy{
AllowedHosts: []EgressHost{},
}
// Run() sets this when egressPolicy is non-nil; simulate that here
// since buildNetConfig doesn't do validation.
cfg.firewallDefaultAction = firewall.Deny

netCfg := cfg.buildNetConfig()

require.NotNil(t, netCfg.EgressPolicy)
assert.Empty(t, netCfg.EgressPolicy.AllowedHosts)
assert.Equal(t, firewall.Deny, netCfg.FirewallDefaultAction)
}

func TestBuildNetConfig_Empty(t *testing.T) {
t.Parallel()

Expand All @@ -642,7 +660,7 @@ func TestBuildNetConfig_Empty(t *testing.T) {

// --- Egress validation tests ---

func TestRun_EgressPolicy_EmptyHosts(t *testing.T) {
func TestRun_EgressPolicy_EmptyHosts_DenyAll(t *testing.T) {
t.Parallel()

dataDir := t.TempDir()
Expand All @@ -651,8 +669,10 @@ func TestRun_EgressPolicy_EmptyHosts(t *testing.T) {
WithDataDir(dataDir),
WithEgressPolicy(EgressPolicy{AllowedHosts: nil}),
)
// Should NOT fail on empty AllowedHosts validation — empty means deny-all.
// It will fail later (e.g. image pull), but not at egress policy validation.
require.Error(t, err)
assert.Contains(t, err.Error(), "AllowedHosts must not be empty")
assert.NotContains(t, err.Error(), "AllowedHosts must not be empty")
}

func TestRun_EgressPolicy_EmptyName(t *testing.T) {
Expand Down
Loading