chruby icon indicating copy to clipboard operation
chruby copied to clipboard

Possible issue with chruby-exec in Ubuntu?

Open kgrz opened this issue 11 years ago • 5 comments

We're trying to provide support for the invoker gem on Linux with chruby, as requested here. A bit of background about invoker:

  1. It's a mashup of the features of Pow web server and Foreman task runner.
  2. The gem is installed without sudo which means chruby will place the executable under ~/.gem/ruby/<version>/bin.
  3. After installation, the next step is running sudo invoker setup. This is straight forward in OSX since sudo gem env and gem env are same. However, on Linux, the sudo-ed command should be run by the command listed in the issue sudo -E chruby-exec 2.1.2 -- invoker setup.

However, that command returns an error saying the executable invoker was not found. The outputs of env, gem env and $PATH when using sudo chruby-exec ... and without it are listed in this gist. You can see that the output of echo $PATH under sudo -E chruby-exec and without it are the same. However, the PATH key in the output of env is different.

Solutions to make the invoker gem to work are these:

  1. Install the gem using the command gem install invoker --bindir $RUBY_ROOT/bin and the n run sudo -E chruby-exec 2.1.2 -- invoker setup. or

  2. Install with gem install invoker and run the sudo invoker setup part with this command:

    sudo -E chruby-exec 2.1.2 -- ~/.gem/ruby//bin/invoker setup

Which is pretty tasking.

My question is, why isn't chruby-exec not loading binaries under ~/.gem/ruby/version/bin when run with sudo -E? Is this a design choice?

OS: Ubuntu 14.04
Ruby: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

kgrz avatar Jun 12 '14 15:06 kgrz

chruby will not add ~/.gem/... to $GEM_PATH when you are root. The idea being, if you are installing gems as root, you probably want to install them in the rubies own gemdir. Also, it's generally not a good idea to invoke user binaries with sudo.

postmodern avatar Jun 12 '14 20:06 postmodern

Perhaps you could do something like chruby-exec 2.1.2 -- sudo -E .... Although, it appears sudo -E is still clobbering $PATH.

postmodern avatar Jun 12 '14 20:06 postmodern

@postmodern The gem is not being installed as root btw. What we want is able to execute binary provided by gem via sudo . it should ideally work as documented here - https://github.com/postmodern/chruby/wiki/Sudo

Are we considering binaries provided by stock ruby to be safer than those provided by gems? I don't see why binaries installed in RUBY_ROOT works but not in gem root. The distinction seems arbitrary and entirely out of scope for something like chruby.

gnufied avatar Jun 12 '14 22:06 gnufied

sudo -E clobbers $PATH and other environment variables depending on security policy of operating system btw. But if chruby is at all meant to be used via sudo the workarounds should work.

gnufied avatar Jun 12 '14 22:06 gnufied

Note that I had the issue on OS X.

The gem installed fine, but when called using sudo without -E the setup wouldn't run due to path errors.

shaneog avatar Jun 13 '14 12:06 shaneog