ctr/tasks: support remapped UID/GID
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
		@@ -40,7 +40,6 @@ import (
 | 
			
		||||
	"github.com/containerd/containerd/snapshots"
 | 
			
		||||
	"github.com/intel/goresctrl/pkg/blockio"
 | 
			
		||||
	"github.com/opencontainers/runtime-spec/specs-go"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -431,30 +430,6 @@ func getRuntimeOptions(context *cli.Context) (interface{}, error) {
 | 
			
		||||
	return nil, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getNewTaskOpts(context *cli.Context) []containerd.NewTaskOpts {
 | 
			
		||||
	var (
 | 
			
		||||
		tOpts []containerd.NewTaskOpts
 | 
			
		||||
	)
 | 
			
		||||
	if context.Bool("no-pivot") {
 | 
			
		||||
		tOpts = append(tOpts, containerd.WithNoPivotRoot)
 | 
			
		||||
	}
 | 
			
		||||
	if uidmap := context.String("uidmap"); uidmap != "" {
 | 
			
		||||
		uidMap, err := parseIDMapping(uidmap)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logrus.WithError(err).Warn("unable to parse uidmap; defaulting to uid 0 IO ownership")
 | 
			
		||||
		}
 | 
			
		||||
		tOpts = append(tOpts, containerd.WithUIDOwner(uidMap.HostID))
 | 
			
		||||
	}
 | 
			
		||||
	if gidmap := context.String("gidmap"); gidmap != "" {
 | 
			
		||||
		gidMap, err := parseIDMapping(gidmap)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			logrus.WithError(err).Warn("unable to parse gidmap; defaulting to gid 0 IO ownership")
 | 
			
		||||
		}
 | 
			
		||||
		tOpts = append(tOpts, containerd.WithGIDOwner(gidMap.HostID))
 | 
			
		||||
	}
 | 
			
		||||
	return tOpts
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func parseIDMapping(mapping string) (specs.LinuxIDMapping, error) {
 | 
			
		||||
	// We expect 3 parts, but limit to 4 to allow detection of invalid values.
 | 
			
		||||
	parts := strings.SplitN(mapping, ":", 4)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user