apache and lighttpd auth with Ruby on Rails

If you run a Ruby on Rails Web Application and in addition a trac or an subversion repository on the same host you might want to use a shared authentication database. With Apache you might use mod_auth_mysql and friends but that does not work with lighttpd. But you can create a htpasswd file on the fly. Let’s say your Person Object does the authentication and the people table has columns like username, passwd and csalt:

class Person  e

  def realpasswd

Now, whenever a Person object is updated a htpasswd file should be created in the directory set by AUTHFILE. Now you can set in lighttpd 1.4.6 authentication rules like this:

auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = AUTHFILE
auth.require = ("/trac" => ("method"  => "basic",
                            "realm"   => "Pi1 Web",
                            "require" => "valid-user"),
                "/svn"  => ("method"  => "basic",
                            "realm"   => "Pi1 Web",   
                            "require" => "valid-user")

The same file also works in Apache. E.g.

   DAV svn
   SVNPath /var/svn/pi1
   # Limit write permission to list of valid users.
      AuthType Basic
      AuthName "Pi1 Web"
      AuthUserFile AUTHFILE
      Require valid-user

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s