Debian Codegraph @

doc/sources/admin/header_remote_user_conversion.rst

raw
1 Convert HTTP header into environment variable
2 =============================================
3
4 Apache
5 ------
6
7 Using LL::NG in reverse proxy mode, you will not have the
8 ``REMOTE_USER`` environment variable set. Indeed, this variable is set
9 by the Handler on the physical server hosting the Handler, and not on
10 other servers where the Handler is not installed.
11
12 Apache `SetEnvIf
13 module <http://httpd.apache.org/docs/current/mod/mod_setenvif.html>`__
14 will let you transform the Auth-User HTTP header in ``REMOTE_USER``
15 environment variable:
16
17 .. code-block:: apache
18
19 SetEnvIfNoCase Auth-User "(.*)" REMOTE_USER=$1
20
21 This can be used to protect applications relying on ``REMOTE_USER``
22 environment variable in reverse proxy mode. In this case you will have
23 two Apache configuration files:
24
25 - Apache configuration file on LL::NG reverse proxy (hosting LL::NG
26 Handler):
27
28 .. code-block:: apache
29
30 <VirtualHost *:80>
31 ServerName application.example.com
32
33 PerlHeaderParserHandler Lemonldap::NG::Handler::ApacheMP2
34
35 ProxyPreserveHost on
36 ProxyPass / http://APPLICATION_IP/
37 ProxyPassReverse / http://APPLICATION_IP/
38
39 </VirtualHost>
40
41 - Apache configuration file on application server (hosting the
42 application):
43
44 .. code-block:: apache
45
46 <VirtualHost *:80>
47 ServerName application.example.com
48
49 SetEnvIfNoCase Auth-User "(.*)" REMOTE_USER=$1
50
51 DocumentRoot /var/www/application
52
53 </VirtualHost>
54
55
56 .. tip::
57
58 Sometimes, PHP applications also check the PHP_AUTH_USER and
59 PHP_AUHT_PW environment variables. You can set them the same way:
60
61 .. code:: apache
62
63 SetEnvIfNoCase Auth-User "(.*)" PHP_AUTH_USER=$1
64 SetEnvIfNoCase Auth-Password "(.*)" PHP_AUTH_PW=$1
65
66 Of course, you need to :doc:`store password in session<passwordstore>`
67 to fill PHP_AUTH_PW.
68
69 Nginx
70 -----
71
72 Nginx doesn't launch directly PHP pages (or other languages): it dials
73 with FastCGI servers (like php-fpm). As you can see in examples, it's
74 easy to map a LLNG header to a fastcgi param. Example:
75
76 .. code-block:: nginx
77
78 auth_request_set $authuser $upstream_http_auth_user;
79 fastcgi_param HTTP_MYVAR $authuser;
80