I’m unable to pass user authentication info via the HTTP headers to RhodeCode. In my case I’m using RC 4.18.2 with an Apache https proxy server authenticating against an LDAP server and then proxying over regular plain HTP to RC… I’ve tried many permutations based on info I’ve found on the web, some of which pertains to quite old versions of RC so I don’t know how relevant it is any more.
On the RhodeCode side, I’ve disabled anonymous usage and enabled the LDAP Authentication plugin, which works fine. I’ve also enabled the Headers Authentication plugin with default settings, which is the header “REMOTE_USER” or the fallback header “HTTP_X_FORWARDED_USER”. This latter value looks suspicious, as if it’s undergone some name mangling, but I’ll let that go for the moment.
Here is the final list of Authentication plugins:
egg:rhodecode-enterprise-ce#token,
egg:rhodecode-enterprise-ce#headers,
egg:rhodecode-enterprise-ce#rhodecode,
egg:rhodecode-enterprise-ce#ldap
Note I’ve also tried putting the headers as the last entry.
On the Apache side I’ve simplified things to match examples I found on the web just using file-based auth. So I ended up with:
<location “/rhodecode”>
ProxyPass http://127.0.0.1:8083/rhodecode timeout=7200 Keepalive=On
ProxyPassReverse http://127.0.0.1:8083/rhodecode
AuthType Basic
AuthName "Credentials Required"
AuthUserFile "/var/www/passwd"
require valid-user
RequestHeader unset X-Forwarded-User
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule .* - [E=RU:%1]
RequestHeader set X-Forwarded-User %{RU}e
Using that config ends up with the RC login screen being displayed - ie the userID is not getting interpreted by RC as a valid user. The same happens when I place a valid user ID directly in the X-Forwarded-User header(!) or use REMOTE_USER / HTTP_X_FORWARDED_USER as the header names.
The only hint I get that something is actually happening is when I accidentally forgot to turn on the rewrite engine. Commenting out that line in the above Apache config results in RC showing it’s main page with the list of repositories but with a username of “(null)”! This only happens when using the X-Forwarded-User header, not the other two mentioned. BUT… I then changed the RC Headers config to specify HTTP_REMOTE_USER as the primary header to check - ie using the same form of name mangling that the fallback header uses. Then testing Apache again, all of the following headers will result in the (null) user being displayed: REMOTE_USER; REMOTE-USER; X_Forwarded_User. So the conclusion there is the name mangling is required, and hyphens and underscores are interchangeable.
In terms of full disclosure I also tried a couple of seemingly old RC settings in rhodecode.ini, setting container_auth_enabled & to true - they made no difference either
FWIW we happen to have another Java application, Sonatype Nexus, behind the same Apache proxy. The only configuration line we have to specify to successfully pass through the userid is “RequestHeader set REMOTE_USER %{REMOTE_USER}s”: Ie we don’t need to use mod-rewrite. Needless to say I tried this with RC, and it resulted in the RC login dialog again - ie it didn’t work. I’m pretty confident with the Apache side of things, but not the RC side.
So the questions / observations I have are:
- What is the correct way to set this up?!
- Are there any useful diagnostics I could enable to see what’s happening on the RC side
- The default Headers config within RC seems self-inconsistent / wrong, and the use of name mangling is confusing to me. The defaults ought be REMOTE_USER and X-Forwarded-User - name mangling should really happen behind the scenes.
Thanks for bearing with me!