Plugin Information
This plugin lets you delegate the authentication to the reverse proxy that you run in front of Jenkins. It also includes Authorisation, which is done via LDAP groups loaded from the HTTP header or LDAP search - based on the username. The default values for the HTTP header fields are:
Apache Configuration Example <Proxy http://localhost:8080/jenkins*>
AuthName "Please sign in with your Apache user name and password"
AuthType BASIC
AuthUserFile /etc/apache2/passwd
Require valid-user
# prevent the client from setting this header
RequestHeader unset X-Forwarded-User
# Adds the X-Forwarded-User header that indicates the current user name.
# this portion came from http://old.nabble.com/Forcing-a-proxied-host-to-generate-REMOTE_USER-td2911573.html#a2914465
RewriteEngine On
# see the Apache documentation on why this has to be lookahead
RewriteCond %{LA-U:REMOTE_USER} (.+)
# this actually doesn't rewrite anything. what we do here is to set RU to the match above
# "NS" prevents flooding the error log
RewriteRule .* - [E=RU:%1,NS]
RequestHeader set X-Forwarded-User %{RU}e
# strip the REALM of Kerberos Login
# RequestHeader edit X-Forwarded-User "@REALM$" ""
</Proxy>
Notes
Jenkins says my reverse proxy setup is broken...
If you see the error message "It appears that your reverse proxy set up is broken" in the "Manage Jenkins" page, here's what's happening. For a reverse proxy to work correctly, it needs to rewrite both the request and the response. Request rewriting involves receiving an inbound HTTP call and then make a forwarding request to Jenkins (sometimes with some HTTP headers modified, sometimes not.) Failing to configure the request rewriting is easy to catch, because you just won't see any pages at all. But proper reverse proxying also involves rewriting response. (Details: Hyperlinks in HTML) The primary place where this needs to happen is the "Location" header in the response, which is used during redirects. Jenkins would send back "Location: http://actual.server:8080/jenkins/foobar" and the reverse proxy needs to rewrite this to "Location: http://nice.name/jenkins/foobar". Unfortunately, failing to configure this correctly is harder to catch. So Jenkins has a proactive monitoring to make sure this is configured correctly. It uses XmlHttpRequest to request a specific URL in Jenkins (via relative path, so this will always get through provided the request is properly rewritten), which will then redirect the user to another page in Jenkins (this works correctly only if you got the reponse rewriting configured correctly), which then returns 200. This error message indicates that this test is failing. The most likely cause is that you got the response rewriting incorrectly done. See Running Jenkins behind Apache for additional tips about reverse proxy. While the page talks primarily about Apache, it has some information that applies to other reverse proxies. Note. The reverse proxy tests were improved in release 1.552 so users with previously working proxy setups may start to receive proxy warnings. If using Apache check that nocanon is set on ProxyPass and that AllowEncodedSlashes is set as per the Apache link above. (AllowEncodedSlashes is not inherited in Apache configs, so this directive must be placed inside the VirtualHost definition.) Also, make sure to set the X-Forwarded-Proto header if your reverse proxy is accessed via HTTPS, but Jenkins itself is not. For further diagnosis, try using cURL: curl -iL -e http://your.reverse.proxy/jenkins/manage http://your.reverse.proxy/jenkins/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test (assuming your Jenkins should be visible at http://your.reverse.proxy/jenkins/) ChangelogVersion 1.4.0 (2014 May 27)
Version 1.3.3 (2014 March 14)
Version 1.3.2 (2014 March 5)
Version 1.3.1 (2014 January 8)
Version 1.3 (2014 January 7)
Version 1.2 (2013 December 20)
Version 1.0.1 (2013 May 7)
Version 1.0 (2011 March 26)
|
Reverse Proxy Auth Plugin
Skip to end of metadata
Go to start of metadata
Comments (6)
Oct 25, 2011
David Baird says:
In the Apache Configuration Example, better: RewriteRule .* - [E=RU:%1,NS] ...In the Apache Configuration Example, better:
RewriteRule .* - [E=RU:%1,NS]
The NS flag forces the rewriting engine to skip a rewriting rule if the current request is an internal sub-request, it will resolve errors like: "Request exceeded the limit of 10 subrequest nesting levels due to probable confguration error"
Apr 18, 2012
Andrea Bernardo Ciddio says:
You can actually avoid issuing sub-requests at all by disabling the lookahead fl...You can actually avoid issuing sub-requests at all by disabling the lookahead flag:
<Location /> ... RewriteEngine On # see the Apache documentation on why this has to be lookahead RewriteCond %{REMOTE_USER} (.+) # this actually doesn't rewrite anything. what we do here is to set RU to the match above RewriteRule .* - [E=RU:%1] RequestHeader set X-Forwarded-User %{RU}e </Location>It appears that lookahead is required only if the rewrite rule is set in a more generic scope (mod_rewrite should apply the rule during the Fixup phase of the API when in a Location block).
Mar 01, 2012
C. S. says:
If I use an username, which doesn't exists in jenkins I got the following except...If I use an username, which doesn't exists in jenkins I got the following exception:
hudson.security.AccessDeniedException2: abc is missing the Read permission
Solution: Set the Read permission under overall.
Aug 07, 2013
Brian Mathis says:
I'm not sure I understand the need for the Rewrite shenanigans. Maybe olde...I'm not sure I understand the need for the Rewrite shenanigans. Maybe older versions of apache needed this because of a bug, or is it just being copied because someone once said it somewhere on a mailing list?
This works perfectly well for me:
RequestHeader unset "X-Forwarded-User" RequestHeader set "X-Forwarded-User" %{REMOTE_USER}eNote the trailing 'e' for environment variable. Change 'e' to 's' when using over SSL.
Jan 26
Brian Hinz says:
Great plugin! Can you provide some examples on using HTTP Header Group...Great plugin! Can you provide some examples on using HTTP Header Groups for authorization? I can see the groups listed along with "authenticated" under the "Authorities:" section of the whoAmI page, but I can't seem to actually use those groups to limit access using the Role Strategy Plugin (which I assume is what you're referring to when you reference "... Role Based Matrix Authorization ..."). TIA
Apr 02
Ireneusz Makowski says:
Do you know how to configure Groups?Do you know how to configure Groups?
Add Comment