mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13491 from jfrazelle/revert-exec-privileged
Revert "Add docker exec run a command in privileged mode"
This commit is contained in:
commit
b50e780925
7 changed files with 15 additions and 53 deletions
|
@ -407,7 +407,7 @@ _docker_events() {
|
||||||
_docker_exec() {
|
_docker_exec() {
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
-*)
|
-*)
|
||||||
COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--detach -d --help --interactive -i -t --tty -u --user" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_containers_running
|
__docker_containers_running
|
||||||
|
|
|
@ -128,7 +128,6 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
|
||||||
Entrypoint: entrypoint,
|
Entrypoint: entrypoint,
|
||||||
Arguments: args,
|
Arguments: args,
|
||||||
User: config.User,
|
User: config.User,
|
||||||
Privileged: config.Privileged,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
execConfig := &execConfig{
|
execConfig := &execConfig{
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/docker/libcontainer/utils"
|
"github.com/docker/libcontainer/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO(vishh): Add support for running in privileged mode.
|
||||||
func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
|
func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
|
||||||
active := d.activeContainers[c.ID]
|
active := d.activeContainers[c.ID]
|
||||||
if active == nil {
|
if active == nil {
|
||||||
|
@ -27,10 +28,6 @@ func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessCo
|
||||||
User: processConfig.User,
|
User: processConfig.User,
|
||||||
}
|
}
|
||||||
|
|
||||||
if processConfig.Privileged {
|
|
||||||
p.Capabilities = execdriver.GetAllCapabilities()
|
|
||||||
}
|
|
||||||
|
|
||||||
config := active.Config()
|
config := active.Config()
|
||||||
if err := setupPipes(&config, processConfig, p, pipes); err != nil {
|
if err := setupPipes(&config, processConfig, p, pipes); err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
|
|
|
@ -9,7 +9,6 @@ docker-exec - Run a command in a running container
|
||||||
[**-d**|**--detach**[=*false*]]
|
[**-d**|**--detach**[=*false*]]
|
||||||
[**--help**]
|
[**--help**]
|
||||||
[**-i**|**--interactive**[=*false*]]
|
[**-i**|**--interactive**[=*false*]]
|
||||||
[**--privileged**[=*false*]]
|
|
||||||
[**-t**|**--tty**[=*false*]]
|
[**-t**|**--tty**[=*false*]]
|
||||||
[**-u**|**--user**[=*USER*]]
|
[**-u**|**--user**[=*USER*]]
|
||||||
CONTAINER COMMAND [ARG...]
|
CONTAINER COMMAND [ARG...]
|
||||||
|
@ -34,13 +33,6 @@ container is unpaused, and then run
|
||||||
**-i**, **--interactive**=*true*|*false*
|
**-i**, **--interactive**=*true*|*false*
|
||||||
Keep STDIN open even if not attached. The default is *false*.
|
Keep STDIN open even if not attached. The default is *false*.
|
||||||
|
|
||||||
**--privileged**=*true*|*false*
|
|
||||||
Give extended privileges to the process to run in a running container. The default is *false*.
|
|
||||||
|
|
||||||
By default, the process run by docker exec in a running container
|
|
||||||
have the same capabilities of the container. By setting --privileged will give
|
|
||||||
all the capabilities to the process.
|
|
||||||
|
|
||||||
**-t**, **--tty**=*true*|*false*
|
**-t**, **--tty**=*true*|*false*
|
||||||
Allocate a pseudo-TTY. The default is *false*.
|
Allocate a pseudo-TTY. The default is *false*.
|
||||||
|
|
||||||
|
|
|
@ -1201,7 +1201,6 @@ You'll need two shells for this example.
|
||||||
|
|
||||||
-d, --detach=false Detached mode: run command in the background
|
-d, --detach=false Detached mode: run command in the background
|
||||||
-i, --interactive=false Keep STDIN open even if not attached
|
-i, --interactive=false Keep STDIN open even if not attached
|
||||||
--privileged=false Give extended privileges to the command
|
|
||||||
-t, --tty=false Allocate a pseudo-TTY
|
-t, --tty=false Allocate a pseudo-TTY
|
||||||
-u, --user= Username or UID (format: <name|uid>[:<group|gid>])
|
-u, --user= Username or UID (format: <name|uid>[:<group|gid>])
|
||||||
|
|
||||||
|
|
|
@ -634,28 +634,3 @@ func (s *DockerSuite) TestExecWithUser(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestExecWithPrivileged(c *check.C) {
|
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "--cap-drop=ALL", "busybox", "top")
|
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
|
||||||
c.Fatal(out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(dockerBinary, "exec", "parent", "sh", "-c", "mknod /tmp/sda b 8 0")
|
|
||||||
out, _, err := runCommandWithOutput(cmd)
|
|
||||||
if err == nil || !strings.Contains(out, "Operation not permitted") {
|
|
||||||
c.Fatalf("exec mknod in --cap-drop=ALL container without --privileged should failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = exec.Command(dockerBinary, "exec", "--privileged", "parent", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok")
|
|
||||||
out, _, err = runCommandWithOutput(cmd)
|
|
||||||
if err != nil {
|
|
||||||
c.Fatal(err, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
if actual := strings.TrimSpace(out); actual != "ok" {
|
|
||||||
c.Fatalf("exec mknod in --cap-drop=ALL container with --privileged failed: %v, output: %q", err, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,13 +18,12 @@ type ExecConfig struct {
|
||||||
|
|
||||||
func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
||||||
var (
|
var (
|
||||||
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
|
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
|
||||||
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
|
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
|
||||||
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
|
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
|
||||||
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
||||||
flPrivileged = cmd.Bool([]string{"-privileged"}, false, "Give extended privileges to the command")
|
execCmd []string
|
||||||
execCmd []string
|
container string
|
||||||
container string
|
|
||||||
)
|
)
|
||||||
cmd.Require(flag.Min, 2)
|
cmd.Require(flag.Min, 2)
|
||||||
if err := cmd.ParseFlags(args, true); err != nil {
|
if err := cmd.ParseFlags(args, true); err != nil {
|
||||||
|
@ -35,12 +34,13 @@ func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
||||||
execCmd = parsedArgs[1:]
|
execCmd = parsedArgs[1:]
|
||||||
|
|
||||||
execConfig := &ExecConfig{
|
execConfig := &ExecConfig{
|
||||||
User: *flUser,
|
User: *flUser,
|
||||||
Privileged: *flPrivileged,
|
// TODO(vishh): Expose 'Privileged' once it is supported.
|
||||||
Tty: *flTty,
|
// + //Privileged: job.GetenvBool("Privileged"),
|
||||||
Cmd: execCmd,
|
Tty: *flTty,
|
||||||
Container: container,
|
Cmd: execCmd,
|
||||||
Detach: *flDetach,
|
Container: container,
|
||||||
|
Detach: *flDetach,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If -d is not set, attach to everything by default
|
// If -d is not set, attach to everything by default
|
||||||
|
|
Loading…
Reference in a new issue