Skip to content

Commit 3241530

Browse files
committed
This commit should be squashed
Provides shim context to runc jailer and clears up some documentation Signed-off-by: xibz <[email protected]>
1 parent 69775f6 commit 3241530

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

runtime/jailer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ func newJailer(
7272
}
7373

7474
l := logger.WithField("jailer", "runc")
75-
return newRuncJailer(l, ociBundlePath, service.config.JailerConfig.RuncBinaryPath, jailerUID, jailerGID)
75+
return newRuncJailer(ctx, l, ociBundlePath, service.config.JailerConfig.RuncBinaryPath, jailerUID, jailerGID)
7676
}

runtime/runc_jailer.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636

3737
// runcJailer uses runc to set up a jailed environment for the Firecracker VM.
3838
type runcJailer struct {
39+
ctx context.Context
3940
logger *logrus.Entry
4041
// ociBundlePath is the path that will be used to create an OCI bundle,
4142
// https://github.com/opencontainers/runtime-spec/blob/master/bundle.md
@@ -46,11 +47,12 @@ type runcJailer struct {
4647
gid uint32
4748
}
4849

49-
func newRuncJailer(logger *logrus.Entry, ociBundlePath, runcBinPath string, uid, gid uint32) (*runcJailer, error) {
50+
func newRuncJailer(ctx context.Context, logger *logrus.Entry, ociBundlePath, runcBinPath string, uid, gid uint32) (*runcJailer, error) {
5051
l := logger.WithField("ociBundlePath", ociBundlePath).
5152
WithField("runcBinaryPath", runcBinPath)
5253

5354
j := &runcJailer{
55+
ctx: ctx,
5456
logger: l,
5557
ociBundlePath: ociBundlePath,
5658
runcBinaryPath: runcBinPath,
@@ -141,7 +143,7 @@ func (j *runcJailer) BuildJailedRootHandler(cfg *Config, socketPath *string, vmI
141143
if err := copyFile(
142144
cfg.FirecrackerBinaryPath,
143145
newFirecrackerBinPath,
144-
0700,
146+
0500,
145147
); err != nil {
146148
return errors.Wrapf(err, "could not copy firecracker binary from path %v", cfg.FirecrackerBinaryPath)
147149
}
@@ -267,7 +269,11 @@ func (j runcJailer) ExposeDeviceToJail(srcDevicePath string) error {
267269
// Here we only care about block devices, ie S_IFBLK. If it is a block type
268270
// we will manually call mknod and create that device.
269271
if (stat.Mode & syscall.S_IFMT) == syscall.S_IFBLK {
270-
path := filepath.Join(j.RootPath(), "dev")
272+
path := filepath.Join(j.RootPath(), filepath.Dir(srcDevicePath))
273+
if err := os.MkdirAll(path, 0700); err != nil {
274+
return err
275+
}
276+
271277
dst := filepath.Join(path, filepath.Base(srcDevicePath))
272278
if err := exposeBlockDeviceToJail(dst, int(stat.Rdev), int(uid), int(gid)); err != nil {
273279
return err
@@ -318,7 +324,7 @@ func copyFile(src, dst string, mode os.FileMode) error {
318324
}
319325

320326
func (j runcJailer) jailerCommand(containerName string) *exec.Cmd {
321-
cmd := exec.Command(j.runcBinaryPath, "run", containerName)
327+
cmd := exec.CommandContext(j.ctx, j.runcBinaryPath, "run", containerName)
322328
cmd.Dir = j.OCIBundlePath()
323329
return cmd
324330
}

runtime/runc_jailer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestBuildJailedRootHandler_Isolated(t *testing.T) {
5252
defer firecrackerFd.Close()
5353

5454
l := logrus.NewEntry(logrus.New())
55-
jailer, err := newRuncJailer(l, dir, "bin-path", 123, 456)
55+
jailer, err := newRuncJailer(context.Background(), l, dir, "bin-path", 123, 456)
5656
require.NoError(t, err, "failed to create runc jailer")
5757

5858
cfg := Config{

runtime/service.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
462462
}()
463463

464464
s.logger.Info("creating new VM")
465-
s.jailer, err = newJailer(requestCtx, s.logger, string(s.shimDir), s, request)
465+
s.jailer, err = newJailer(s.shimCtx, s.logger, string(s.shimDir), s, request)
466466
if err != nil {
467467
return errors.Wrap(err, "failed to create jailer")
468468
}
@@ -487,7 +487,10 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
487487
}
488488
opts = append(opts, jailedOpts...)
489489

490-
// use shimCtx so the VM is killed when the shim shuts down
490+
// In the event that a noop jailer is used, we will pass in the shim context
491+
// and have the SDK construct a new machine using that context. Otherwise, a
492+
// custom process runner will be provided via options which will stomp over
493+
// the shim context that was provided here.
491494
s.machine, err = firecracker.NewMachine(s.shimCtx, *s.machineConfig, opts...)
492495
if err != nil {
493496
return errors.Wrapf(err, "failed to create new machine instance")

tools/docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/firecracker /usr
150150
COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/jailer /usr/local/bin/jailer
151151
COPY _submodules/runc/runc /usr/local/bin
152152
COPY tools/image-builder/rootfs.img /var/lib/firecracker-containerd/runtime/default-rootfs.img
153+
COPY runtime/firecracker-runc-config.json.example /etc/containerd/firecracker-runc-config.json
153154

154155
# pull the images the tests need into the content store so we don't need internet
155156
# access during the tests themselves

0 commit comments

Comments
 (0)