Add --user support for ctr run Windows

Adds the ability to override the default user
ContainerUser with a custom user if present in
the image or ContainerAdministrator if needed.

Signed-off-by: Justin Terry <jlterry@amazon.com>
This commit is contained in:
Justin Terry 2022-03-01 15:28:51 -08:00
parent 82bce322da
commit 0c79257f59

View File

@ -36,6 +36,10 @@ var platformRunFlags = []cli.Flag{
Name: "isolated", Name: "isolated",
Usage: "run the container with vm isolation", Usage: "run the container with vm isolation",
}, },
cli.StringFlag{
Name: "user",
Usage: "run the container as the specified user",
},
} }
// NewContainer creates a new container // NewContainer creates a new container
@ -104,6 +108,9 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
if cwd := context.String("cwd"); cwd != "" { if cwd := context.String("cwd"); cwd != "" {
opts = append(opts, oci.WithProcessCwd(cwd)) opts = append(opts, oci.WithProcessCwd(cwd))
} }
if user := context.String("user"); user != "" {
opts = append(opts, oci.WithUsername(user))
}
if context.Bool("tty") { if context.Bool("tty") {
opts = append(opts, oci.WithTTY) opts = append(opts, oci.WithTTY)