ctr: add --user for task exec
set user in exec container $ ctr t exec --exec-id e1 --user admin container id uid=500(admin) gid=500(admin) groups=500(admin) Signed-off-by: chuangxue <chenglong.lcl@alibaba-inc.com> Signed-off-by: acetang <aceapril@126.com>
This commit is contained in:
parent
31a0f92df1
commit
5e94745f26
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -61,6 +62,10 @@ var execCommand = cli.Command{
|
|||||||
Name: "log-uri",
|
Name: "log-uri",
|
||||||
Usage: "log uri for custom shim logging",
|
Usage: "log uri for custom shim logging",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "user",
|
||||||
|
Usage: "user id or name",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
@ -85,15 +90,25 @@ var execCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
task, err := container.Task(ctx, nil)
|
if user := context.String("user"); user != "" {
|
||||||
|
c, err := container.Info(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := oci.WithUser(user)(ctx, client, &c, spec); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pspec := spec.Process
|
pspec := spec.Process
|
||||||
pspec.Terminal = tty
|
pspec.Terminal = tty
|
||||||
pspec.Args = args
|
pspec.Args = args
|
||||||
|
|
||||||
|
task, err := container.Task(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ioCreator cio.Creator
|
ioCreator cio.Creator
|
||||||
stdinC = &stdinCloser{
|
stdinC = &stdinCloser{
|
||||||
|
Loading…
Reference in New Issue
Block a user