You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.0 KiB

  1. Allow users to be automatically logged in
  2. =========================================
  3. This module initialize the session by looking for the field HTTP_REMOTE_USER in
  4. the HEADER of the HTTP request and trying to bind the given value to a user.
  5. To be active, the module must be installed in the expected databases and loaded
  6. at startup; Add the *--load* parameter to the startup command: ::
  7. --load=web,web_kanban,auth_from_http_remote_user, ...
  8. If the field is found in the header and no user matches the given one, the
  9. system issue a login error page. (*401* `Unauthorized`)
  10. Use case.
  11. ---------
  12. The module allows integration with external security systems [#]_ that can pass
  13. along authentication of a user via Remote_User HTTP header field. In many
  14. cases, this is achieved via server like Apache HTTPD or nginx proxying Odoo.
  15. .. important:: When proxying your Odoo server with Apache or nginx, It's
  16. important to filter out the Remote_User HTTP header field before your
  17. request is processed by the proxy to avoid security issues. In apache you
  18. can do it by using the RequestHeader directive in your VirtualHost
  19. section ::
  20. <VirtualHost *:80>
  21. ServerName MY_VHOST.com
  22. ProxyRequests Off
  23. ...
  24. RequestHeader unset Remote-User early
  25. ProxyPass / http://127.0.0.1:8069/ retry=10
  26. ProxyPassReverse / http://127.0.0.1:8069/
  27. ProxyPreserveHost On
  28. </VirtualHost>
  29. How to test the module with Apache [#]_
  30. ----------------------------------------
  31. Apache can be used as a reverse proxy providing the authentication and adding
  32. the required field in the Http headers.
  33. Install apache: ::
  34. $ sudo apt-get install apache2
  35. Define a new vhost to Apache by putting a new file in
  36. /etc/apache2/sites-available: ::
  37. $ sudo vi /etc/apache2/sites-available/MY_VHOST.com
  38. with the following content: ::
  39. <VirtualHost *:80>
  40. ServerName MY_VHOST.com
  41. ProxyRequests Off
  42. <Location />
  43. AuthType Basic
  44. AuthName "Test Odoo auth_from_http_remote_user"
  45. AuthBasicProvider file
  46. AuthUserFile /etc/apache2/MY_VHOST.htpasswd
  47. Require valid-user
  48. RewriteEngine On
  49. RewriteCond %{LA-U:REMOTE_USER} (.+)
  50. RewriteRule . - [E=RU:%1]
  51. RequestHeader set Remote-User "%{RU}e" env=RU
  52. </Location>
  53. RequestHeader unset Remote-User early
  54. ProxyPass / http://127.0.0.1:8069/ retry=10
  55. ProxyPassReverse / http://127.0.0.1:8069/
  56. ProxyPreserveHost On
  57. </VirtualHost>
  58. .. important:: The *RequestHeader* directive is used to add the *Remote-User*
  59. field in the http headers. By default an *'Http-'* prefix is added to the
  60. field name.
  61. In Odoo, header's fields name are normalized. As result of this
  62. normalization, the 'Http-Remote-User' is available as 'HTTP_REMOTE_USER'.
  63. If you don't know how your specified field is seen by Odoo, run your
  64. server in debug mode once the module is activated and look for an entry
  65. like: ::
  66. DEBUG openerp1 openerp.addons.auth_from_http_remote_user.controllers.
  67. session:
  68. Field 'HTTP_MY_REMOTE_USER' not found in http headers
  69. {'HTTP_AUTHORIZATION': 'Basic YWRtaW46YWRtaW4=', ...,
  70. 'HTTP_REMOTE_USER': 'demo')
  71. Enable the required apache modules: ::
  72. $ sudo a2enmod headers
  73. $ sudo a2enmod proxy
  74. $ sudo a2enmod rewrite
  75. $ sudo a2enmod proxy_http
  76. Enable your new vhost: ::
  77. $ sudo a2ensite MY_VHOST.com
  78. Create the *htpassword* file used by the configured basic authentication: ::
  79. $ sudo htpasswd -cb /etc/apache2/MY_VHOST.htpasswd admin admin
  80. $ sudo htpasswd -b /etc/apache2/MY_VHOST.htpasswd demo demo
  81. For local test, add the *MY_VHOST.com* in your /etc/vhosts file.
  82. Finally reload the configuration: ::
  83. $ sudo service apache2 reload
  84. Open your browser and go to MY_VHOST.com. If everything is well configured, you
  85. are prompted for a login and password outside Odoo and are automatically
  86. logged in the system.
  87. .. [#] Shibolleth, Tivoli access manager, ..
  88. .. [#] Based on a ubuntu 12.04 env
  89. Contributors
  90. ------------
  91. * Laurent Mignon