From b7b64a79755eb26a14d62a54d9c42d41f7145fe8 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Mon, 22 Aug 2016 16:36:50 +0000 Subject: [PATCH 1/2] Use login shells in terminals --- probe/docker/controls.go | 2 +- probe/host/controls_darwin.go | 2 +- probe/host/controls_linux.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/probe/docker/controls.go b/probe/docker/controls.go index 5fc85a417..375d86a9d 100644 --- a/probe/docker/controls.go +++ b/probe/docker/controls.go @@ -111,7 +111,7 @@ func (r *registry) execContainer(containerID string, req xfer.Request) xfer.Resp AttachStdout: true, AttachStderr: true, Tty: true, - Cmd: []string{"/bin/sh", "-c", "TERM=xterm exec $( (type getent > /dev/null 2>&1 && getent passwd root | cut -d: -f7 2>/dev/null) || echo /bin/sh)"}, + Cmd: []string{"/bin/sh", "-l", "-c", "TERM=xterm exec $( (type getent > /dev/null 2>&1 && getent passwd root | cut -d: -f7 2>/dev/null) || echo /bin/sh)"}, Container: containerID, }) if err != nil { diff --git a/probe/host/controls_darwin.go b/probe/host/controls_darwin.go index cae9c363e..8171d4d10 100644 --- a/probe/host/controls_darwin.go +++ b/probe/host/controls_darwin.go @@ -1,5 +1,5 @@ package host func getHostShellCmd() []string { - return []string{"/bin/bash"} + return []string{"/bin/bash", "-l"} } diff --git a/probe/host/controls_linux.go b/probe/host/controls_linux.go index f4870c33d..bb3fc0cdc 100644 --- a/probe/host/controls_linux.go +++ b/probe/host/controls_linux.go @@ -23,12 +23,12 @@ func getHostShellCmd() []string { "/usr/bin/nsenter", "-t1", "-m", "-i", "-n", "-p", "--no-fork", "--setuid", uid, "--setgid", gid, - shell, + shell, "-l", } } _, _, shell := getRootUserDetails([]string{"cat", "/etc/passwd"}) - return []string{shell} + return []string{shell, "-l"} } func getRootUserDetails(readPasswdCmd []string) (uid, gid, shell string) { From 12a33002868dfa9c8657facc8967cfdcbf918425 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 23 Aug 2016 16:29:00 +0000 Subject: [PATCH 2/2] Fix integration tests --- integration/410_container_control_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/410_container_control_test.sh b/integration/410_container_control_test.sh index b85a57a8b..5b898af52 100755 --- a/integration/410_container_control_test.sh +++ b/integration/410_container_control_test.sh @@ -16,7 +16,7 @@ PROBEID=$(docker_on $HOST1 logs weavescope 2>&1 | grep "probe starting" | sed -n # Execute 'echo foo' in a container tty and check its output PIPEID=$(curl -s -f -X POST "http://$HOST1:4040/api/control/$PROBEID/$CID;/docker_exec_container" | jq -r '.pipe' ) -assert "(sleep 1 && echo 'echo foo' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "/ # 6necho foo\nfoo\n/ # 6n" +assert "(sleep 1 && echo 'echo foo' && sleep 1) | wscat -b 'ws://$HOST1:4040/api/pipe/$PIPEID' | col -pb" "alpine:/# 6necho foo\nfoo\nalpine:/# 6n" assert_raises "curl -f -X POST 'http://$HOST1:4040/api/control/$PROBEID/$CID;/docker_stop_container'"