Nesting and authenticating resque-web on ey-cloud

September 13, 2010 Mike Barinek

Wouldn’t it be nice to include the resque-web interface underneath your current application’s url?

Wouldn’t it then be nice to use the same authentication mechanism that your web application uses?

Here’s a solution that we used on a recent Rails 2.3 ey-cloud project that accomplished both goals.

First, we created a simple resque_web.ru file within our Rails 2.3 project. In this example we used the same Warden SSO authentication mechanism and fired up the resque-web server from the new mapping.


# Set up Resque environment
resque_config = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'resque.yml'))

env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
Resque.redis = resque_config[env]

map '/resque-web' do
  use Rack::Session::Cookie, :key => 'rack.session',
    :path => '/',
    :expire_after => 60 ** 2,
    :secret => 'supersecretresquekey'

  use CasrackTheAuthenticator::Simple, :cas_server => "http://sso.your_sso_server.com"
  use CasrackTheAuthenticator::RequireCAS
  use Rack::ShowExceptions
  run Resque::Server.new
end

The important piece here is that we use ‘/resque-web’, we’ll use this same path in a bit within our Nginx configuration. We also used the rack session cookies with our SSO authenticator.

Another interesting piece here is that we’re using Castronaut and Casrack the Authenticator, which makes SSO pretty straight forward.

Next we created an upstream server in Nginx to resolve the path. We’re just using Thin here.

Here’s our Chef template for the upstream server.


upstream resque_web_upstream {
   server unix:/var/run/engineyard/<%= @app_name %>/<%= @app_name %>.thin.1.sock;
}

The important piece here is that the upstream server lives outside of our web application config area.

Here’s our Chef recipe for creating the upstream server file.


template "/etc/nginx/servers/resque_web.conf" do
  owner "root"
  group "root"
  mode 0755
  source "resque_web.conf.erb"
  variables({
    :app_name => app_name
  })
end

And then finally, we created a new custom location within our Nginx server configuration.

Here’s our Chef template for the custom Nginx Location.


location /resque-web {
  proxy_set_header Host $http_host;
  include /etc/nginx/common/proxy.conf;
  proxy_pass http://resque_web_upstream;
}

And here’s our Chef recipe for creating the custom location file.


template "/etc/nginx/servers/#{app_name}/custom.locations.conf" do
  owner "root"
  group "root"
  mode 0755
  source "custom.locations.conf.erb"
  variables({
    :app_name => app_name
  })
end

That’s it!

About the Author

Biography

More Content by Mike Barinek
Previous
Identify memory abusing partials with GC stats
Identify memory abusing partials with GC stats

Recently we had to investigate a page that had very poor performance. The project used newrelic, but neith...

Next
New Tech Talk: Sencha Touch
New Tech Talk: Sencha Touch

Sencha's Sr. Software Architect Ed Spencer describes and demonstrates their Touch framework. Sencha Touch i...

How do you measure digital transformation?

Take the Benchmark