Thursday, October 29, 2009

Chef Server behind a proxy

I'm trying to stand up a Chef server behind our corporate firewall (actually on a Amazon EC2 instance running in the VPC). Setting the http_proxy variable is clearly necessary for yum but there are other gotchas.

First, rpm doesn't obey $http_proxy. This is freaking annoying. So you have to use the --httpproxy and --httpport options.

But the big one is that chef uses OpenID to authenticate users logging into the chef server web UI. The chef web app tries to contact my OpenID provider but it can't reach it through the proxy. Luckily, the ruby OpenID library makes it easy to use an http_proxy. Just add these two lines to the init.rb file of the chef server merb app in the Merb::BootLoader.after_app_loads block.

/usr/lib/ruby/gems/1.8/gems/chef-server-0.7.10/config/init.rb:


Merb::BootLoader.after_app_loads do
# This will get executed after your app's classes have been loaded.
OpenID::Util.logger = Merb.logger
ENV['http_proxy'] = 'http://yourproxy.com:port' # <- set your http_proxy env var
OpenID.fetcher_use_env_http_proxy # <- tell OpenID to use http_proxy
end

2 comments:

Chris Chalfant said...

ok, this doesn't work any more with 0.7.14! What did I do wrong?

Chris Chalfant said...

Actually, I'm a dork. I just forgot to restart httpd.

Carry on.