Skip to content

Commit 69775f6

Browse files
committed
This commit should be squashed
This commit removes the NET_ADMIN capability. This change also removes the network interfaces for the jailer test since Firecracker will attempt to create a tap device if one does not exist, and since the jailer currently has no netns, it makes sense that one would be created which causes the permission denied error when attempting to create a tap device Signed-off-by: xibz <[email protected]>
1 parent d7be79c commit 69775f6

File tree

4 files changed

+38
-144
lines changed

4 files changed

+38
-144
lines changed

runtime/firecracker-runc-config.json.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
"bounding": [
2222
],
2323
"inheritable": [
24-
"CAP_NET_ADMIN"
2524
],
2625
"permitted": [
27-
"CAP_NET_ADMIN"
2826
],
2927
"ambient": [
30-
"CAP_NET_ADMIN"
3128
]
3229
},
3330
"rlimits": [

runtime/jailer_integ_test.go

Lines changed: 0 additions & 125 deletions
This file was deleted.

runtime/service_integ_test.go

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ func createTapDevice(ctx context.Context, tapName string) error {
221221
}
222222

223223
func TestMultipleVMs_Isolated(t *testing.T) {
224-
prepareIntegTest(t)
224+
prepareIntegTest(t, func(cfg *Config) {
225+
cfg.JailerConfig.RuncBinaryPath = "/usr/local/bin/runc"
226+
})
225227

226228
cases := []struct {
227229
MaxContainers int32
@@ -276,7 +278,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
276278
rootfsPath := defaultVMRootfsPath
277279

278280
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
279-
_, err = fcClient.CreateVM(ctx, &proto.CreateVMRequest{
281+
req := &proto.CreateVMRequest{
280282
VMID: strconv.Itoa(vmID),
281283
MachineCfg: &proto.FirecrackerMachineConfiguration{
282284
MemSizeMib: 512,
@@ -296,7 +298,13 @@ func TestMultipleVMs_Isolated(t *testing.T) {
296298
},
297299
ContainerCount: containerCount,
298300
JailerConfig: jailerConfig,
299-
})
301+
}
302+
303+
if jailerConfig != nil {
304+
req.NetworkInterfaces = nil
305+
}
306+
307+
_, err = fcClient.CreateVM(ctx, req)
300308
require.NoError(t, err, "failed to create vm")
301309

302310
var containerWg sync.WaitGroup
@@ -306,18 +314,26 @@ func TestMultipleVMs_Isolated(t *testing.T) {
306314
defer containerWg.Done()
307315
containerName := fmt.Sprintf("container-%d-%d", vmID, containerID)
308316
snapshotName := fmt.Sprintf("snapshot-%d-%d", vmID, containerID)
317+
processArgs := oci.WithProcessArgs("/bin/sh", "-c", strings.Join([]string{
318+
fmt.Sprintf("/bin/cat /sys/class/net/%s/address", defaultVMNetDevName),
319+
"/usr/bin/readlink /proc/self/ns/mnt",
320+
fmt.Sprintf("/bin/sleep %d", testTimeout/time.Second),
321+
}, " && "))
322+
323+
if jailerConfig != nil {
324+
// TODO: this if statement block can go away once we add netns
325+
processArgs = oci.WithProcessArgs("/bin/sh", "-c", strings.Join([]string{
326+
fmt.Sprintf("/bin/sleep %d", testTimeout/time.Second),
327+
}, " && "))
328+
}
309329

310330
// spawn a container that just prints the VM's eth0 mac address (which we have set uniquely per VM)
311331
newContainer, err := client.NewContainer(ctx,
312332
containerName,
313333
containerd.WithSnapshotter(naiveSnapshotterName),
314334
containerd.WithNewSnapshot(snapshotName, image),
315335
containerd.WithNewSpec(
316-
oci.WithProcessArgs("/bin/sh", "-c", strings.Join([]string{
317-
fmt.Sprintf("/bin/cat /sys/class/net/%s/address", defaultVMNetDevName),
318-
"/usr/bin/readlink /proc/self/ns/mnt",
319-
fmt.Sprintf("/bin/sleep %d", testTimeout/time.Second),
320-
}, " && ")),
336+
processArgs,
321337
oci.WithHostNamespace(specs.NetworkNamespace),
322338
firecrackeroci.WithVMID(strconv.Itoa(vmID)),
323339
),
@@ -438,13 +454,21 @@ func TestMultipleVMs_Isolated(t *testing.T) {
438454
}
439455

440456
stdoutLines := strings.Split(strings.TrimSpace(taskStdout.String()), "\n")
441-
require.Len(t, stdoutLines, 2)
457+
lines := 2
458+
if jailerConfig != nil {
459+
lines = 1
460+
}
461+
require.Len(t, stdoutLines, lines)
442462

443463
printedVMID := strings.TrimSpace(stdoutLines[0])
444-
require.Equal(t, vmIDtoMacAddr(uint(vmID)), printedVMID, "unexpected VMID output from container %q", containerName)
464+
// TODO: Remove this if statement once we can add a netns which
465+
// will allow firecracker to have visibility of the tap devices.
466+
if jailerConfig == nil {
467+
require.Equal(t, vmIDtoMacAddr(uint(vmID)), printedVMID, "unexpected VMID output from container %q", containerName)
445468

446-
taskMntNS := strings.TrimSpace(stdoutLines[1])
447-
require.Equal(t, execMntNS, taskMntNS, "unexpected mnt NS output from container %q", containerName)
469+
taskMntNS := strings.TrimSpace(stdoutLines[1])
470+
require.Equal(t, execMntNS, taskMntNS, "unexpected mnt NS output from container %q", containerName)
471+
}
448472

449473
case <-ctx.Done():
450474
require.Fail(t, "context cancelled",
@@ -572,7 +596,6 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
572596
},
573597
},
574598
ContainerCount: 5,
575-
JailerConfig: &proto.JailerConfig{},
576599
})
577600
require.NoError(t, err, "failed to create VM")
578601

@@ -700,7 +723,6 @@ func testCreateContainerWithSameName(t *testing.T, vmID string) {
700723
IsRootDevice: true,
701724
},
702725
ContainerCount: 2,
703-
JailerConfig: &proto.JailerConfig{},
704726
})
705727
require.NoError(t, err)
706728
}

runtime/service_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestBuildVMConfiguration(t *testing.T) {
9595
{
9696
DriveID: firecracker.String("root_drive"),
9797
PathOnHost: firecracker.String("REQUEST ROOT DRIVE"),
98-
IsReadOnly: firecracker.Bool(true),
98+
IsReadOnly: firecracker.Bool(false),
9999
IsRootDevice: firecracker.Bool(true),
100100
},
101101
},
@@ -135,7 +135,7 @@ func TestBuildVMConfiguration(t *testing.T) {
135135
{
136136
DriveID: firecracker.String("root_drive"),
137137
PathOnHost: firecracker.String("REQUEST ROOT DRIVE"),
138-
IsReadOnly: firecracker.Bool(true),
138+
IsReadOnly: firecracker.Bool(false),
139139
IsRootDevice: firecracker.Bool(true),
140140
},
141141
},

0 commit comments

Comments
 (0)