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

Conversation

bparees
Copy link
Contributor

@bparees bparees commented Jan 4, 2017

also set it without using env so it will work in containers
that don't have /bin/env

fixes #12348

@bparees
Copy link
Contributor Author

bparees commented Jan 4, 2017

@smarterclayton ptal

@bparees
Copy link
Contributor Author

bparees commented Jan 4, 2017

(this is effectively running /bin/sh -c "TERM=foo /bin/sh" which is the only way i could figure out to inject the TERM variable into a shell invocation w/o using env)

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] == "/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.

This should probably be checking against o.Executable

o.Command = append([]string{"env", term}, o.Command...)

if len(o.Command) == 1 && o.Command[0] == "/bin/sh" {
termsh := fmt.Sprintf("TERM=%s /bin/sh", util.Env("TERM", "xterm"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be o.Executable here too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you may have broken quotes here if term has spaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably need to use %q

@bparees
Copy link
Contributor Author

bparees commented Jan 4, 2017

@smarterclayton thanks, updated.


if len(o.Command) == 1 && o.Command[0] == o.Executable {
termsh := fmt.Sprintf("TERM=%q %s", util.Env("TERM", "xterm"), o.Executable)
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.

@bparees
Copy link
Contributor Author

bparees commented Jan 4, 2017

@smarterclayton updated again, to a more conservative approach (only sets TERM if shell is /bin/sh)

@bparees
Copy link
Contributor Author

bparees commented Jan 5, 2017

@smarterclayton bump

@bparees
Copy link
Contributor Author

bparees commented Jan 9, 2017

@smarterclayton since you're in review mode.......bump

@bparees
Copy link
Contributor Author

bparees commented Jan 13, 2017

@smarterclayton bump.

@smarterclayton
Copy link
Contributor

Test case? :)

@bparees
Copy link
Contributor Author

bparees commented Jan 16, 2017

[test]


# test that rsh inherits the TERM variable by default
oldterm=$TERM
TERM=test_terminal
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this on each line.

Copy link
Contributor

Choose a reason for hiding this comment

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

I.e. inside the test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

also set it without using env so it will work in containers
that don't have /bin/env
@smarterclayton
Copy link
Contributor

LGTM [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 8afb300

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 8afb300

@openshift-bot
Copy link
Contributor

openshift-bot commented Jan 17, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/12928/) (Base Commit: 68b25d5) (Image: devenv-rhel7_5693)

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/12926/) (Base Commit: a3e2498)

@openshift-bot openshift-bot merged commit dc5ca90 into openshift:master Jan 17, 2017
@bparees bparees deleted the rsh_term branch January 21, 2017 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

oc rsh fails when accessing container without env on the path
3 participants