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

Fix operation not permitted with systemd-homed #2064

Merged
merged 1 commit into from
Mar 1, 2023
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
20 changes: 20 additions & 0 deletions cmd/nerdctl/container_run_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/pkg/userns"
"github.com/containerd/continuity/fs"
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/idgen"
Expand Down Expand Up @@ -189,6 +190,25 @@ func generateMountOpts(ctx context.Context, cmd *cobra.Command, client *containe
return nil, nil, nil, err
}
}
} else if runtime.GOOS == "linux" {
defer unmounter(tempDir)
for _, m := range mounts {
m := m
if m.Type == "bind" && userns.RunningInUserNS() {
// For https://github.com/containerd/nerdctl/issues/2056
unpriv, err := mountutil.UnprivilegedMountFlags(m.Source)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have an integ or an unit test for this that the unpriv mount flags are carried over?
If my understanding is correct; a user will still have to ensure that the right subuid and subgid ranges are specified.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally yes, but not sure how to do that

if err != nil {
return nil, nil, nil, err
}
m.Options = strutil.DedupeStrSlice(append(m.Options, unpriv...))
}
if err := m.Mount(tempDir); err != nil {
if rmErr := s.Remove(ctx, tempDir); rmErr != nil && !errdefs.IsNotFound(rmErr) {
Copy link
Member

@fahedouch fahedouch Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure! but why not appending the layerID to the root as done before.
cc @AkihiroSuda

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC it was never appended for linux

return nil, nil, nil, rmErr
}
return nil, nil, nil, fmt.Errorf("failed to mount %+v on %q: %w", m, tempDir, err)
}
}
} else {
defer unmounter(tempDir)
if err := mount.All(mounts, tempDir); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mountutil/mountutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore) (*Processed, error
Options: options,
}
if userns.RunningInUserNS() {
unpriv, err := getUnprivilegedMountFlags(src)
unpriv, err := UnprivilegedMountFlags(src)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mountutil/mountutil_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/sirupsen/logrus"
)

func getUnprivilegedMountFlags(path string) ([]string, error) {
func UnprivilegedMountFlags(path string) ([]string, error) {
m := []string{}
return m, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/mountutil/mountutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ import (
NOTICE: https://github.com/moby/moby/blob/v20.10.5/NOTICE
*/

// getUnprivilegedMountFlags is from https://github.com/moby/moby/blob/v20.10.5/daemon/oci_linux.go#L420-L450
// UnprivilegedMountFlags is from https://github.com/moby/moby/blob/v20.10.5/daemon/oci_linux.go#L420-L450
//
// Get the set of mount flags that are set on the mount that contains the given
// path and are locked by CL_UNPRIVILEGED. This is necessary to ensure that
// bind-mounting "with options" will not fail with user namespaces, due to
// kernel restrictions that require user namespace mounts to preserve
// CL_UNPRIVILEGED locked flags.
func getUnprivilegedMountFlags(path string) ([]string, error) {
func UnprivilegedMountFlags(path string) ([]string, error) {
var statfs unix.Statfs_t
if err := unix.Statfs(path, &statfs); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/mountutil/mountutil_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/sirupsen/logrus"
)

func getUnprivilegedMountFlags(path string) ([]string, error) {
func UnprivilegedMountFlags(path string) ([]string, error) {
m := []string{}
return m, nil
}
Expand Down