Skip to content

Commit c0efc63

Browse files
authored
Merge pull request #8357 from thaJeztah/1.6_backport_oci_readonly_mounts
[release/1.6 backport] oci: Use WithReadonlyTempMount when adding users/groups
2 parents 710d928 + fb5e663 commit c0efc63

1 file changed

Lines changed: 5 additions & 28 deletions

File tree

oci/spec_opts.go

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,7 @@ func WithUser(userstr string) SpecOpts {
663663
return err
664664
}
665665

666-
mounts = tryReadonlyMounts(mounts)
667-
return mount.WithTempMount(ctx, mounts, f)
666+
return mount.WithReadonlyTempMount(ctx, mounts, f)
668667
default:
669668
return fmt.Errorf("invalid USER value %s", userstr)
670669
}
@@ -724,8 +723,7 @@ func WithUserID(uid uint32) SpecOpts {
724723
return err
725724
}
726725

727-
mounts = tryReadonlyMounts(mounts)
728-
return mount.WithTempMount(ctx, mounts, setUser)
726+
return mount.WithReadonlyTempMount(ctx, mounts, setUser)
729727
}
730728
}
731729

@@ -769,8 +767,7 @@ func WithUsername(username string) SpecOpts {
769767
return err
770768
}
771769

772-
mounts = tryReadonlyMounts(mounts)
773-
return mount.WithTempMount(ctx, mounts, setUser)
770+
return mount.WithReadonlyTempMount(ctx, mounts, setUser)
774771
} else if s.Windows != nil {
775772
s.Process.User.Username = username
776773
} else {
@@ -848,8 +845,7 @@ func WithAdditionalGIDs(userstr string) SpecOpts {
848845
return err
849846
}
850847

851-
mounts = tryReadonlyMounts(mounts)
852-
return mount.WithTempMount(ctx, mounts, setAdditionalGids)
848+
return mount.WithReadonlyTempMount(ctx, mounts, setAdditionalGids)
853849
}
854850
}
855851

@@ -910,8 +906,7 @@ func WithAppendAdditionalGroups(groups ...string) SpecOpts {
910906
return err
911907
}
912908

913-
mounts = tryReadonlyMounts(mounts)
914-
return mount.WithTempMount(ctx, mounts, setAdditionalGids)
909+
return mount.WithReadonlyTempMount(ctx, mounts, setAdditionalGids)
915910
}
916911
}
917912

@@ -1389,21 +1384,3 @@ func WithDevShmSize(kb int64) SpecOpts {
13891384
return ErrNoShmMount
13901385
}
13911386
}
1392-
1393-
// tryReadonlyMounts is used by the options which are trying to get user/group
1394-
// information from container's rootfs. Since the option does read operation
1395-
// only, this helper will append ReadOnly mount option to prevent linux kernel
1396-
// from syncing whole filesystem in umount syscall.
1397-
//
1398-
// TODO(fuweid):
1399-
//
1400-
// Currently, it only works for overlayfs. I think we can apply it to other
1401-
// kinds of filesystem. Maybe we can return `ro` option by `snapshotter.Mount`
1402-
// API, when the caller passes that experimental annotation
1403-
// `containerd.io/snapshot/readonly.mount` something like that.
1404-
func tryReadonlyMounts(mounts []mount.Mount) []mount.Mount {
1405-
if len(mounts) == 1 && mounts[0].Type == "overlay" {
1406-
mounts[0].Options = append(mounts[0].Options, "ro")
1407-
}
1408-
return mounts
1409-
}

0 commit comments

Comments
 (0)