Skip to content

Commit 78007d6

Browse files
committed
Shorten the socket path on runcJailer
The max length of the Unix domain socket path is 108 bytes. We need to use an relative path to workaround the limitation. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 22ccc1b commit 78007d6

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

runtime/runc_jailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (j *runcJailer) BuildJailedMachine(cfg *config.Config, machineConfig *firec
156156
func (j *runcJailer) BuildJailedRootHandler(cfg *config.Config, machineConfig *firecracker.Config, vmID string) firecracker.Handler {
157157
ociBundlePath := j.OCIBundlePath()
158158
rootPath := j.RootPath()
159-
machineConfig.SocketPath = filepath.Join(rootPath, "api.socket")
159+
machineConfig.SocketPath = filepath.Join(rootfsFolder, "api.socket")
160160

161161
return firecracker.Handler{
162162
Name: jailerHandlerName,

runtime/service_integ_test.go

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -583,35 +583,69 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
583583
// default location we store state results in a path like
584584
// "/run/firecracker-containerd/default/<vmID>" (with len 112).
585585
const maxUnixSockLen = 108
586-
vmID := strings.Repeat("x", 76)
586+
vmID := strings.Repeat("x", 72)
587587

588588
ctx := namespaces.WithNamespace(context.Background(), "default")
589589

590590
pluginClient, err := ttrpcutil.NewClient(containerdSockPath + ".ttrpc")
591591
require.NoError(t, err, "failed to create ttrpc client")
592592

593-
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
594-
_, err = fcClient.CreateVM(ctx, &proto.CreateVMRequest{
595-
VMID: vmID,
596-
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{},
597-
})
598-
require.NoError(t, err, "failed to create VM")
593+
subtests := []struct {
594+
name string
595+
request proto.CreateVMRequest
596+
}{
597+
{
598+
name: "Without Jailer",
599+
request: proto.CreateVMRequest{
600+
VMID: vmID + "noop",
601+
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{},
602+
},
603+
},
604+
{
605+
name: "With Jailer",
606+
request: proto.CreateVMRequest{
607+
// We somehow cannot use the same VM ID here.
608+
// https://github.com/firecracker-microvm/firecracker-containerd/issues/409
609+
VMID: vmID + "jail",
610+
NetworkInterfaces: []*proto.FirecrackerNetworkInterface{},
611+
JailerConfig: &proto.JailerConfig{
612+
UID: 30000,
613+
GID: 30000,
614+
},
615+
},
616+
},
617+
}
599618

600-
// double-check that the sockets are at the expected path and that their absolute
601-
// length exceeds 108 bytes
602-
shimDir, err := vm.ShimDir(cfg.ShimBaseDir, "default", vmID)
603-
require.NoError(t, err, "failed to get shim dir")
619+
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
620+
for _, subtest := range subtests {
621+
request := subtest.request
622+
vmID := request.VMID
623+
t.Run(subtest.name, func(t *testing.T) {
624+
_, err = fcClient.CreateVM(ctx, &request)
625+
require.NoError(t, err, "failed to create VM")
626+
627+
// double-check that the sockets are at the expected path and that their absolute
628+
// length exceeds 108 bytes
629+
shimDir, err := vm.ShimDir(cfg.ShimBaseDir, "default", vmID)
630+
require.NoError(t, err, "failed to get shim dir")
631+
632+
if request.JailerConfig == nil {
633+
_, err = os.Stat(shimDir.FirecrackerSockPath())
634+
require.NoError(t, err, "failed to stat firecracker socket path")
635+
if len(shimDir.FirecrackerSockPath()) <= maxUnixSockLen {
636+
assert.Failf(t, "firecracker sock absolute path %q is not greater than max unix socket path length", shimDir.FirecrackerSockPath())
637+
}
604638

605-
_, err = os.Stat(shimDir.FirecrackerSockPath())
606-
require.NoError(t, err, "failed to stat firecracker socket path")
607-
if len(shimDir.FirecrackerSockPath()) <= maxUnixSockLen {
608-
assert.Failf(t, "firecracker sock absolute path %q is not greater than max unix socket path length", shimDir.FirecrackerSockPath())
609-
}
639+
_, err = os.Stat(shimDir.FirecrackerVSockPath())
640+
require.NoError(t, err, "failed to stat firecracker vsock path")
641+
if len(shimDir.FirecrackerVSockPath()) <= maxUnixSockLen {
642+
assert.Failf(t, "firecracker vsock absolute path %q is not greater than max unix socket path length", shimDir.FirecrackerVSockPath())
643+
}
644+
}
610645

611-
_, err = os.Stat(shimDir.FirecrackerVSockPath())
612-
require.NoError(t, err, "failed to stat firecracker vsock path")
613-
if len(shimDir.FirecrackerVSockPath()) <= maxUnixSockLen {
614-
assert.Failf(t, "firecracker vsock absolute path %q is not greater than max unix socket path length", shimDir.FirecrackerVSockPath())
646+
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
647+
require.NoError(t, err)
648+
})
615649
}
616650
}
617651

0 commit comments

Comments
 (0)