Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only set term if rsh is running /bin/sh #12386

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/cmd/cli/cmd/rsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)

const RshRecommendedName = "rsh"
const (
RshRecommendedName = "rsh"
DefaultShell = "/bin/sh"
)

var (
rshLong = templates.LongDesc(`
Expand Down Expand Up @@ -94,7 +97,7 @@ func NewCmdRsh(name string, parent string, f *clientcmd.Factory, in io.Reader, o
}
cmd.Flags().BoolVarP(&options.ForceTTY, "tty", "t", false, "Force a pseudo-terminal to be allocated")
cmd.Flags().BoolVarP(&options.DisableTTY, "no-tty", "T", false, "Disable pseudo-terminal allocation")
cmd.Flags().StringVar(&options.Executable, "shell", "/bin/sh", "Path to the shell command")
cmd.Flags().StringVar(&options.Executable, "shell", DefaultShell, "Path to the shell command")
cmd.Flags().IntVar(&options.Timeout, "timeout", 10, "Request timeout for obtaining a pod from the server; defaults to 10 seconds")
cmd.Flags().StringVarP(&options.ContainerName, "container", "c", "", "Container name; defaults to first container")
cmd.Flags().SetInterspersed(false)
Expand Down Expand Up @@ -155,8 +158,9 @@ func (o *RshOptions) Validate() error {
// Run starts a remote shell session on the server
func (o *RshOptions) Run() error {
// Insert the TERM into the command to be run
term := fmt.Sprintf("TERM=%s", util.Env("TERM", "xterm"))
o.Command = append([]string{"env", term}, o.Command...)

if len(o.Command) == 1 && o.Command[0] == DefaultShell {
termsh := fmt.Sprintf("TERM=%q %s", util.Env("TERM", "xterm"), DefaultShell)
o.Command = append(o.Command, "-c", termsh)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only fear now is that since we're doing this for any value of --shell the user passes, if they pass a --shell value that doesn't support "-c", things will be broken. That was part of my motivation to only do this logic when the shell was explicitly "/bin/sh".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think anyone passing a custom executable or custom command is probably on their own. However, I would probably expect this to work for --shell=/bin/bash. Ultimately this is a losing game, so it's probably ok to only do this substitution in exactly one case - no command, and o.Executable is the default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree if they pass a custom executable they are on their own, but if we tack a "-c" onto their custom executable and break it, we've screwed them and given them no real recourse (well, oc exec). i'll change it back to only enter this block if it's /bin/sh.

}
return o.ExecOptions.Run()
}
8 changes: 8 additions & 0 deletions test/end-to-end/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ frontend_pod=$(oc get pod -l deploymentconfig=frontend --template='{{(index .ite
os::cmd::expect_success_and_text "oc exec -p ${frontend_pod} id" '1000'
os::cmd::expect_success_and_text "oc rsh pod/${frontend_pod} id -u" '1000'
os::cmd::expect_success_and_text "oc rsh -T ${frontend_pod} id -u" '1000'

# test that rsh inherits the TERM variable by default
# this must be done as an echo and not an argument to rsh because rsh only sets the TERM if
# no arguments are supplied.
TERM=test_terminal os::cmd::expect_success_and_text "echo 'echo $TERM' | oc rsh ${frontend_pod}" $TERM
# and does not inherit it when the user provides a command.
TERM=test_terminal os::cmd::expect_success_and_not_text "oc rsh ${frontend_pod} echo \$TERM" $TERM

# Wait for the rollout to finish
os::cmd::expect_success "oc rollout status dc/frontend --revision=1"
# Test retrieving application logs from dc
Expand Down