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.

162 lines
5.3 KiB

10 years ago
10 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Laurent Mignon
  5. # Copyright 2014 'ACSONE SA/NV'
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. {
  22. 'name': 'Authenticate via HTTP Remote User',
  23. 'version': '1.0',
  24. 'category': 'Tools',
  25. 'description': """
  26. Allow users to be automatically logged in.
  27. ==========================================
  28. This module initialize the session by looking for the field HTTP_REMOTE_USER in
  29. the HEADER of the HTTP request and trying to bind the given value to a user.
  30. To be active, the module must be installed in the expected databases and loaded
  31. at startup; Add the *--load* parameter to the startup command: ::
  32. --load=web,web_kanban,auth_from_http_remote_user, ...
  33. If the field is found in the header and no user matches the given one, the
  34. system issue a login error page. (*401* `Unauthorized`)
  35. Use case.
  36. ---------
  37. The module allows integration with external security systems [#]_ that can pass
  38. along authentication of a user via Remote_User HTTP header field. In many cases,
  39. this is achieved via server like Apache HTTPD or nginx proxying Odoo.
  40. .. important:: When proxying your Odoo server with Apache or nginx, It's
  41. important to filter out the Remote_User HTTP header field before your
  42. request is processed by the proxy to avoid security issues. In apache you
  43. can do it by using the RequestHeader directive in your VirtualHost
  44. section ::
  45. <VirtualHost *:80>
  46. ServerName MY_VHOST.com
  47. ProxyRequests Off
  48. ...
  49. RequestHeader unset Remote-User early
  50. ProxyPass / http://127.0.0.1:8069/ retry=10
  51. ProxyPassReverse / http://127.0.0.1:8069/
  52. ProxyPreserveHost On
  53. </VirtualHost>
  54. How to test the module with Apache [#]_
  55. ----------------------------------------
  56. Apache can be used as a reverse proxy providing the authentication and adding
  57. the required field in the Http headers.
  58. Install apache: ::
  59. $ sudo apt-get install apache2
  60. Define a new vhost to Apache by putting a new file in
  61. /etc/apache2/sites-available: ::
  62. $ sudo vi /etc/apache2/sites-available/MY_VHOST.com
  63. with the following content: ::
  64. <VirtualHost *:80>
  65. ServerName MY_VHOST.com
  66. ProxyRequests Off
  67. <Location />
  68. AuthType Basic
  69. AuthName "Test Odoo auth_from_http_remote_user"
  70. AuthBasicProvider file
  71. AuthUserFile /etc/apache2/MY_VHOST.htpasswd
  72. Require valid-user
  73. RewriteEngine On
  74. RewriteCond %{LA-U:REMOTE_USER} (.+)
  75. RewriteRule . - [E=RU:%1]
  76. RequestHeader set Remote-User "%{RU}e" env=RU
  77. </Location>
  78. RequestHeader unset Remote-User early
  79. ProxyPass / http://127.0.0.1:8069/ retry=10
  80. ProxyPassReverse / http://127.0.0.1:8069/
  81. ProxyPreserveHost On
  82. </VirtualHost>
  83. .. important:: The *RequestHeader* directive is used to add the *Remote-User*
  84. field in the http headers. By default an *'Http-'* prefix is added to the
  85. field name.
  86. In Odoo, header's fields name are normalized. As result of this
  87. normalization, the 'Http-Remote-User' is available as 'HTTP_REMOTE_USER'.
  88. If you don't know how your specified field is seen by Odoo, run your
  89. server in debug mode once the module is activated and look for an entry
  90. like: ::
  91. DEBUG openerp1 openerp.addons.auth_from_http_remote_user.controllers.
  92. session:
  93. Field 'HTTP_MY_REMOTE_USER' not found in http headers
  94. {'HTTP_AUTHORIZATION': 'Basic YWRtaW46YWRtaW4=', ...,
  95. 'HTTP_REMOTE_USER': 'demo')
  96. Enable the required apache modules: ::
  97. $ sudo a2enmod headers
  98. $ sudo a2enmod proxy
  99. $ sudo a2enmod rewrite
  100. $ sudo a2enmod proxy_http
  101. Enable your new vhost: ::
  102. $ sudo a2ensite MY_VHOST.com
  103. Create the *htpassword* file used by the configured basic authentication: ::
  104. $ sudo htpasswd -cb /etc/apache2/MY_VHOST.htpasswd admin admin
  105. $ sudo htpasswd -b /etc/apache2/MY_VHOST.htpasswd demo demo
  106. For local test, add the *MY_VHOST.com* in your /etc/vhosts file.
  107. Finally reload the configuration: ::
  108. $ sudo service apache2 reload
  109. Open your browser and go to MY_VHOST.com. If everything is well configured, you
  110. are prompted for a login and password outside Odoo and are automatically
  111. logged in the system.
  112. .. [#] Shibolleth, Tivoli access manager, ..
  113. .. [#] Based on a ubuntu 12.04 env
  114. """,
  115. 'author': 'Acsone SA/NV',
  116. 'maintainer': 'ACSONE SA/NV',
  117. 'website': 'http://www.acsone.eu',
  118. 'depends': ['base', 'web', 'base_setup'],
  119. "license": "AGPL-3",
  120. 'data': [],
  121. "demo": [],
  122. "test": [],
  123. "active": False,
  124. "license": "AGPL-3",
  125. "installable": True,
  126. "auto_install": False,
  127. "application": False,
  128. }