Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: Reduce the mount points with namespace isolation #8760

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/runtime/pkg/containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress str
return cmd, nil
}

func setupMntNs() error {
err := unix.Unshare(unix.CLONE_NEWNS)
if err != nil {
return err
}

err = unix.Mount("", "/", "", unix.MS_REC|unix.MS_SLAVE, "")
if err != nil {
err = fmt.Errorf("failed to mount with slave: %v", err)
return err
}

err = unix.Mount("", "/", "", unix.MS_REC|unix.MS_SHARED, "")
if err != nil {
err = fmt.Errorf("failed to mount with shared: %v", err)
return err
}

return nil
}

// StartShim is a binary call that starts a kata shimv2 service which will
// implement the ShimV2 APIs such as create/start/update etc containers.
func (s *service) StartShim(ctx context.Context, opts cdshim.StartOpts) (_ string, retErr error) {
Expand Down Expand Up @@ -255,6 +276,10 @@ func (s *service) StartShim(ctx context.Context, opts cdshim.StartOpts) (_ strin
}
}

if err := setupMntNs(); err != nil {
return "", err
}

if err := cmd.Start(); err != nil {
return "", err
}
Expand Down