Wednesday, November 28, 2007

Rails + pubcookie... finally

Well, I've finally gotten Pubcookie authentication working with my Apache + mongrel cluster configuration.  After talking to a guy on the Pubcookie team, he pointed me to this invaluable resource:
http://www.washington.edu/webinfo/case/zope/

It turns out that most of it is unnecessary if you've already followed the instructions for setting up the mod_proxy_balancer as found here.  The missing key to get Pubcookie working was the mod_fba module that is linked in the case above.  Here is what I did to get everything working (after following Coda Hale's process above):

1. Add mod_fba to your Apache setup:
% wget http://rici.ricilake.net/src/mod_fba.c
% apxs -c mod_fba.c
% apxs -i mod_fba.la 

2. Edit httpd.conf to load that module:
LoadModule fba_module modules/mod_fba.so 

3. Add the configuration for FakeBasicAuth to your myapp.common file:
FakeBasicAuthEnable on
FakeBasicAuthType authtype 

4. Since I want the entire app protected by Pubcookie authentication, add the AuthType directive to the myapp.proxy_cluster.conf file to require a login for everything sent to the mongrel cluster: 
<Proxy balancer://mongrel_cluster>
  BalancerMember http://127.0.0.1:8000
  BalancerMember http://127.0.0.1:8001

  AuthType authtype
  require valid-user
  PubcookieAppID "myapp" 
</Proxy>

5. Now, you'll be able to get access to the HTTP_AUTHORIZATION server variable in your ruby code.  This will be in the form of "Basic" followed by the user's login information encoded in Base64.  This line of ruby will extract out the username only for you to use in your app for authentication purposes:
userid = request.env['HTTP_AUTHORIZATION'].split(' ')[1].unpack("m").to_s.split(':')[0]

Monday, November 26, 2007

Is rails worth it?

I'm starting to regret the idea of using rails in this environment.  After spending a week to get apache + mod_proxy + balanced mongrels working, now I don't even know if I can use pubcookie authentication with rails at all.  I don't really have a choice on that one.  Starting to wonder if I should have just gone with an MVC framework in PHP, like Cake or Symfony.

Friday, November 16, 2007

Decided to start a blog

Well, I'm starting to build a new rails webapp for my office that is in pretty in depth... and I decided I needed a place to write some things down as I did it!  Who knows, maybe this will become a useful resource at point -- if no one else but me.