How do I update Ruby Gems from behind a Proxy (ISA-NTLM) - ruby

The firewall I'm behind is running Microsoft ISA server in NTLM-only mode. Hash anyone have success getting their Ruby gems to install/update via Ruby SSPI gem or other method?
... or am I just being lazy?
Note: rubysspi-1.2.4 does not work.
This also works for "igem", part of the IronRuby project

For the Windows OS, I used Fiddler to work around the issue.
Install/Run Fiddler from www.fiddler2.com
Run gem:
$ gem install --http-proxy http://localhost:8888 $gem_name

I wasn't able to get mine working from the command-line switch but I have been able to do it just by setting my HTTP_PROXY environment variable. (Note that case seems to be important). I have a batch file that has a line like this in it:
SET HTTP_PROXY=http://%USER%:%PASSWORD%#%SERVER%:%PORT%
I set the four referenced variables before I get to this line obviously. As an example if my username is "wolfbyte", my password is "secret" and my proxy is called "pigsy" and operates on port 8080:
SET HTTP_PROXY=http://wolfbyte:secret#pigsy:8080
You might want to be careful how you manage that because it stores your password in plain text in the machine's session but I don't think it should be too much of an issue.

This totally worked:
gem install --http-proxy http://COMPANY.PROXY.ADDRESS $gem_name

I've been using cntlm (http://cntlm.sourceforge.net/) at work. Configuration is very similar to ntlmaps.
gem install --http-proxy http://localhost:3128 _name_of_gem_
Works great, and also allows me to connect my Ubuntu box to the ISA proxy.
Check out http://cntlm.wiki.sourceforge.net/ for more information

I tried some of these solutions, and none of them worked. I finally found a solution that works for me:
gem install -p http://proxy_ip:proxy_port rails
using the -p parameter to pass the proxy. I'm using Gem version 1.9.1.

Create a .gemrc file (either in /etc/gemrc or ~/.gemrc or for example with chef gem in /opt/chef/embedded/etc/gemrc) containing:
http_proxy: http://proxy:3128
Then you can gem install as usual.

This solved my problem perfectly:
gem install -p http://proxy_ip:proxy_port compass
You might need to add your user name and password to it:
gem install -p http://[username]:[password]#proxy_ip:proxy_port compass

If you are having problems getting authenticated through your proxy, be sure to set the environment variables in exactly the format below:
set HTTP_PROXY=some.proxy.com
set HTTP_PROXY_USER=user
set HTTP_PROXY_PASS=password
The user:password# syntax doesn't seem to work and there are also some badly named environment variables floating around on Stack Overflow and various forum posts.
Also be aware that it can take a while for your gems to start downloading. At first I thought it wasn't working but with a bit of patience they started downloading as expected.

Quick answer : Add proxy configuration with parameter for both install/update
gem install --http-proxy http://host:port/ package_name
gem update --http-proxy http://host:port/ package_name

I tried all the above solutions, however none of them worked. If you're on linux/macOS i highly suggest using tsocks over an ssh tunnel. What you need in order to get this setup working is a machine where you can log in via ssh, and in addition to that a programm called tsocks installed.
The idea here is to create a dynamic tunnel via SSH (a socks5 proxy). We then configure tsocks to use this tunnel and to start our applications, in this case:
tsocks gem install ...
or to account for rails 3.0:
tsocks bundle install
A more detailed guide can be found under:
http://blog.byscripts.info/2011/04/bypass-a-proxy-with-ssh-tunnel-and-tsocks-under-ubuntu/
Despite being written for Ubuntu the procedure should be applicable for all Unix based machines. An alternative to tsocks for Windows is FreeCap (http://www.freecap.ru/eng/). A viable SSH client on windows is called putty.

Posts abound regarding this topic, and to help others save hours of trying different solutions, here is the final result of my hours of tinkering.
The three solutions around the internet at the moment are:
rubysspi
apserver
cntlm
rubysspi only works from a Windows machine, AFAIK, as it relies on the Win32Api library. So if you are on a Windows box trying to run through a proxy, this is the solution for you. If you are on a Linux distro, you're out of luck.
apserver seems to be a dead project. The link listed in the posts I've seen lead to 404 page on sourceforge. I search for "apserver" on sourceforge returns nothing.
The sourceforge link for cntlm that I've seen redirects to http://cntlm.awk.cz/, but that times out. A search on sourceforge turns up this link, which does work: http://sourceforge.net/projects/cntlm/
After downloading and configuring cntlm I have managed to install a gem through the proxy, so this seems to be the best solution for Linux distros.

A workaround is to install http://web.archive.org/web/20060913093359/http://apserver.sourceforge.net:80/ on your local machine, configure it and run gems through this proxy.
Install: Just download apserver 097 (and not the experimental 098!) and unpack.
Configure: Edit the server.cfg file and put the values for your MS proxy in PARENT_PROXY and PARENT_PROXY_PORT. Enter the values for DOMAIN and USER. Leave PASSWORD blank (nothing after the colon) – you will be prompted when launching it.
Run apserver: cd aps097; python main.py
Run Gems: gem install—http-proxy http://localhost:5865/ library

I am working behind a proxy and just installed SASS by downloading directly from http://rubygems.org.
I then ran sudo gem install [path/to/downloaded/gem/file]. I cannot say this will work for all gems, but it may help some people.

This worked for me in a Windows box:
set HTTP_PROXY=http://server:port
set HTTP_PROXY_USER=username
set HTTP_PROXY_PASS=userparssword
set HTTPS_PROXY=http://server:port
set HTTPS_PROXY_USER=username
set HTTPS_PROXY_PASS=userpassword
I have a batch file with these lines that I use to set environment values when I need it.
The trick, in my case, was HTTPS_PROXY sets. Without them, I always got a 407 proxy authentication error.

If you are on a *nix system, use this:
export http_proxy=http://${proxy.host}:${port}
export https_proxy=http://${proxy.host}:${port}
and then try:
gem install ${gem_name}

rubysspi-1.3.1 worked for me on Windows 7, using the instructions from this page:
http://www.stuartellis.eu/articles/installing-ruby/

If you want to use SOCKS5 proxy, you may try rubygems-socksproxy https://github.com/gussan/rubygems-socksproxy.
It works for me on OSX 10.9.3.

If behind a proxy, you can navigate to Ruby downloads, click on Download, which will download the specified update ( or Gem ) to a desired location.
Next, via Ruby command line, navigate to the downloaded location by using : pushd [directory]
eg : pushd D:\Setups
then run the following command: gem install [update name] --local
eg: gem install rubygems-update --local.
Tested on Windows 7 with Ruby update version 2.4.1.
To check use following command : ruby -v

Rather than editing batch files (which you may have to do for other Ruby gems, e.g. Bundler), it's probably better to do this once, and do it properly.
On Windows, behind my corporate proxy, all I had to do was add the HTTP_PROXY environment variable to my system.
Start -> right click Computer -> Properties
Choose "Advanced System Settings"
Click Advanced -> Environment Variables
Create a new System variable named "HTTP_PROXY", and set the Value to your proxy server
Reboot or log out and back in again
Depending on your authentication requirements, the HTTP_PROXY value can be as simple as:
http://proxy-server-name
Or more complex as others have pointed out
http://username:password#proxy-server-name:port-number

for anyone tunnelling with SSH; you can create a version of the gem command that uses SOCKS proxy:
Install socksify with gem install socksify (you'll need to be able to do this step without proxy, at least)
Copy your existing gem exe
cp $(command which gem) /usr/local/bin/proxy_gem
Open it in your favourite editor and add this at the top (after the shebang)
require 'socksify'
if ENV['SOCKS_PROXY']
require 'socksify'
host, port = ENV['SOCKS_PROXY'].split(':')
TCPSocket.socks_server = host || 'localhost'
TCPSocket.socks_port = port.to_i || 1080
end
Set up your tunnel
ssh -D 8123 -f -C -q -N user#proxy
Run your gem command with proxy_gem
SOCKS_PROXY=localhost:8123 proxy_gem push mygem

Related

Optimal way to install ruby on Docker where base-OS access is required?

I'm trying to install Ruby on Docker (no Rails), but I'm having some issues. I initially tried with RVM, but I had issues with it; after I'd installed it in the usual way, commands such as ruby or gem install aren't recognised, and I understand that RVM is not best practice for a docker environment. I tried building from binary, but that seemed to be missing so many essential things, it seemed to be an exercise in futility.
I've now tried using the official docker ruby:2.5.1 image, however when I attach to this, I get an irb prompt, and am unable to use operating system commands, such as apt-get due to this.
It's essential that I have operating system access - this script will be using a browser through headless Watir webdriver, attaching to Geckodriver, so there are a number of dependencies required that won't be included in the base ruby install.
What's the best way to handle this with Docker?
This will get you on the command-line of the Ruby box:
docker run -it ruby:2.5.1 bash
You'll now be able to run ruby tools as normal, e.g. ruby, irb, gem. As well as regular Debian commands including apt-get.
Suggestion:
If you want to roam around inside a separated environment, you should choose something like Vagrant.
If you are intended to use docker, give a try this approach.
You can place any code in your ruby file whichever you would like to.
$ docker run -it -v $(pwd)/:/data ruby:2.5 ruby -- /data/hello.rb
hello world!

Install chromedriver using a remote host

I deployed my application using Ruby, Sinatra and Redis DataBase, on my ubuntu remote host named Scaleway.
In this way, i've install all what i need, and i can acces to my application. So when i want to use my script, who use Watir gem (selenium), it's always show me this error :
Selenium::WebDriver::Error::WebDriverError at /show_result
unable to connect to chromedriver 127.0.0.1:9515
I know that i need Xvfb (who is installed), the headless gem (that i implemented in my code), and chromedriver that i installed by the same way that i installed it on my local machine.
On my local machine, it works perfectly, but in my remote host, it show me this error above.
Did you know how to fix this problem ? How did you install Chromedriver so that my program recognizes it ?
Did you run the watir command using xvfb with something like this
xvfb-run <here is your command>
Also Chromedriver should place properly so it can be access anywhere, usually I put chromedriver at /usr/bin/ or /usr/sbin/

i cannot install haml using "gem install haml"

i have already downloaded ruby 2.2.1 and in command prompt i hv tried the command
gem install haml
but error is coming like:
ERROR: Could not find a valid gem 'haml' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - Errno::ECONNREFUS ED: No connection could be made because the target
machine actively refused it.
- connect(2) for "api.rubygems.org" port 443 (https://api.rubygems.org/specs.4.8 .gz)
It might be because of the firewall company have put up in every system. I have gone through trying different proxies picked up from different websites. Can anybody tell how to install or use haml/sass?
Company firewalls, the bane of many a developer's existence.
The best thing you can do:
Talk to the local networking team and get it unblocked for direct access.
If that fails:
Do they have a proxy you can use? gem will honor proxy variables, so if you get access to one, you can do an export https_proxy="http://someaddress:someport", and then your command should work.
If that also fails
Now we're left with circumventing the network policies - Be careful, as this could get you in trouble.
Options include:
Getting an external proxy that allows port 80 (it sounds like 80 works from your question). You could set up a squid instance on your home machine and access it that way via the variable method above.
Doing an SSH tunnel through a machine that does have unrestricted internet access, and using tsocks to tunnel through there.
There are others, but these two are relatively easy to set up.
I must emphasize here, be careful! Even if your networking group is impeding your ability to do your job, either get your boss's support, or be as stealthy as possible and discontinue use of these tools once you have what you need.
If it's a rails project, you can try to change the first line of your Gemfile from source 'https://rubygems.org' to source 'http://rubygems.org'.
If you are using a ruby project, try to download gem without https, like : gem install -s http://rubygems.org haml

Jekyll regeneration doesn't work inside Vagrant

Running the otherwise working command:
jekyll serve --watch
inside Vagrant is not leading to regeneration of the files unless I restart the jekyll server. I am editing on Windows. Is this a problem with Jekyll running inside Vagrant or is there some configuration that I need to do to make this work? I even tried using foreman with the following Procfile configuration but with the same result
web: jekyll serve --watch
It's implemented in the latest pre release (jekyll 2.0.0.alpha.3 by the time of writing).
You should use --force_polling option to get benefit of it.
Try running the jekyll server like this:
jekyll serve --watch --force_polling
My guess, based on nothing more than my own experience of this issue is that you are running your jekyll site in the /vagrant folder which vagrant maps/syncs back to the host os.
These mapped or synchronised folders are using some kind of crazy filesystem driver (basically a type of network share) and the file watch features don't work on them.
This SO question shows the same symptom.
(You will see what I mean of you run your jekyll site outside `/vagrant' like in the home folder. Make a change (using nano) and you will see the Regeneration triggering)
What provider are you using? I was able to get it to work on Windows 8 using Virtual Box as a provider and Ubuntu 12.04 as a guest OS. I had to use version 1.2.1 and not the latest version however.
When I use the latest Jekyll version (1.4.2), watch does not work as expected (it doesn't notice the file change and does not rebuild). It does work when I edit them on the guest OS though (it does notice the file change and will rebuild).
Version 1.2.1 works regardless of where the files are edited from (Guest OS or Host OS).
To revert back to version 1.2.1 I ran the following commands:
gem uninstall jekyll
gem install jekyll -v 1.2.1
Note: The jekyll site is running from the vagrant directory
In vagrant, just add --force_polling, then jekyll will watch almost all files except "_config.yml"
jekyll serve --force_polling
When you change the other files except for "_config.yml", you will see the regeneration.
But if you are changing "_config.yml" it will not trigger the regeneration.
Are you excepting the regeneration when you are changing "_config.yml"?
My guess (without knowing the details) is that you need to be running headless, as in:
jekyll serve -w --detach
as mentioned in the jekyll documentation. If it's not that, then describe the issue in more detail, as I asked about in the comment. Also, are you using any type of provisioner in Vagrant, e.g. shell, chef, ansible, etc.?

How to install gem through proxy with authorization [duplicate]

This question already has answers here:
How do I update Ruby Gems from behind a Proxy (ISA-NTLM)
(20 answers)
Closed 7 years ago.
I am behind a corporate proxy and it needs authorization to use it. When I try just to use option -p http://ip.of.my.proxy:3128, it throws error 407. Is there a workaround?
this solution works for me in analog situation (corporate network behind autenticated proxy):
Create a file .gemrc under your HOME (in my case C:\Documents and Settings\my_username\.gemrc
Write inside the previous file this single line:
http_proxy: http://<YOUR_USER>:<YOUR_PASSWORD>#<YOUR_PROXY_HOST>:<YOUR_PROXY_PORT>
This is the way I figured it out. Hope it works for you too.
Fill in the proxy in your Proxy settings(varies as per your system).
Once, you are done with the proxy settings, just do (assuming a Linux system)
sudo -i gem install GEM_NAME
Note that the authorizationi.e username and password need to be filled in the proxy settings for the system.
If you are not the root user, or you wish to install the gem locally (if using RVM), don't use sudo then.

Resources