Thursday, 2 February 2012

Apache reverse-proxying and the REMOTE_USER variable

I spent an alarming amount of time yesterday attempting to make the most of Apache's ridiculously easy mod_auth_kerb module for SSO Kerberos authentication with a little in-house Sinatra app I've been working on. Apparently Kerberos within nginx or ruby is a bit of an unofficial ballache, so I decided to take the easy route out. However, it transpires that only one person on the whole internet knew of the existence of the ProxyPassInterpolateEnv boolean.

To put this in context, for my app I only want kerberos to validate the user and then pass on the username to the app. It's a git deploy frontend, and I like blaming people.

You'll find a lot of stuff about doing a complicated rewrite so that REMOTE_USER actually evaluates before a reverse proxy. I couldn't get any of this stuff to work - not only that but it's a horrible solution anyway requiring about three lines of rewrite - and I'll be honest, I'm not up together on my apache rewrites anyway.

So the following is the solution I ended up with. It simply makes Apache forward on the REMOTE_USER variable, created by your auth module, to whatever you're reverse proxying - in my case a Sinatra app. It actually appears as REMOTE_USER as opposed to the specified REMOTE-USER as well. I neither know why nor care.

Excuse the formatting.

<Virtualhost *:443>
SSLEngine on
SSLCipherSuite ...
              HA HA SSL BUSINESS
        ...
ServerName yer-mum.com
ProxyPassInterpolateEnv On
ProxyPass / http://localhost:4567/
RequestHeader set REMOTE-USER %{REMOTE_USER}s
    <Location />
        AuthType Kerberos
        AuthName "AD Login"
        KrbMethodNegotiate On
        KrbMethodK5Passwd On
        KrbAuthRealms MUMS.COM
        Krb5KeyTab /etc/krb5.keytab
        Require valid-user
    </Location>
</Virtualhost *:443>

3 comments:

  1. I feel compelled to note that I approve of this writing style. The post in no way helps me solve the issue I was searching about, but it entertained me anyway. :)

    Also, the OpenID thing below doesn't seem to work with arbitrary URLs, like the OpenID provider on my blog.

    ReplyDelete
    Replies
    1. Heh, cheers dude. I have no idea about the OpenID thing, this is a pretty basic blogger instance and I really can't be assed to muck about with it because I'm lazy.

      Delete
  2. Thank's to article your :)

    ReplyDelete

All comments and questions are welcome, just remember that I may not know the answer as I've only worked on my particular implimentation, and I have no responsibility to help you debug your problems.

That said, fire away!