index.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .. _security_tutorials_credentialsfromheaders:
  2. Configuring Apache HTTPD Session Integration
  3. ============================================
  4. Introduction
  5. ------------
  6. When using Apache HTTPD as a proxy frontend for GeoServer, it is possible to share
  7. authentication with a proper configuration of both.
  8. This requires enabling Session for the GeoServer location in Apache HTTPD and adding
  9. a custom Request Header with the session content, so that the GeoServer security system
  10. can receive user credentials and use them to authenticate the user with its internal
  11. filters.
  12. To properly parse the received credentials we need to use the `Credentials From Request Headers`
  13. Authentication Filter.
  14. Please note that the header containing the password is not sent back and forth to the
  15. user browser, but only from Apache HTTPD to GeoServer, so the password is not sent in
  16. clear through the public network.
  17. This tutorial shows how to configure GeoServer to read user credentials
  18. from the Apache HTTPD Session and use them for authentication purposes.
  19. Prerequisites
  20. -------------
  21. This tutorial uses the `curl <http://curl.haxx.se/>`_ utility to issue HTTP
  22. request that test authentication. Install curl before proceeding.
  23. Configure the Credentials From Request Headers filter
  24. -----------------------------------------------------
  25. #. Start GeoServer and login to the web admin interface as the ``admin`` user.
  26. #. Click the ``Authentication`` link located under the ``Security`` section of
  27. the navigation sidebar.
  28. .. figure:: images/digest1.jpg
  29. :align: center
  30. #. Scroll down to the ``Authentication Filters`` panel and click the ``Add new`` link.
  31. .. figure:: images/digest2.jpg
  32. :align: center
  33. #. Click the ``Credentials From Headers`` link.
  34. .. figure:: images/digest3.jpg
  35. :align: center
  36. #. Fill in the fields of the settings form as follows:
  37. * Set ``Name`` to "apachessesion"
  38. * Set ``Username Header`` to "X-Credentials"
  39. * Set ``Regular Expression for Username`` to "private-user=([^&]*)"
  40. * Set ``Password Header`` to "X-Credentials"
  41. * Set ``Regular Expression for Password`` to "private-pw=([^&]*)"
  42. .. figure:: images/digest4.jpg
  43. :align: center
  44. #. Save.
  45. #. Back on the authentication page scroll down to the ``Filter Chains`` panel.
  46. #. Click on "default" in the chain grid.
  47. #. Scroll down and remove all filters from the ``Selected`` list and add the ``apachessesion`` filter.
  48. .. figure:: images/digest5.jpg
  49. :align: center
  50. #. Close.
  51. #. Save.
  52. Test a login
  53. ------------------
  54. #. Execute the following curl command (with a wrong password)::
  55. curl -v -H "X-Credentials: private-user=admin&private-pw=wrong" "http://localhost:8080/geoserver/wms?service=WMS&version=1.1.1&request=GetCapabilities"
  56. The result should be a 403 response signaling that access is denied. The output
  57. should look something like the following::
  58. * About to connect() to localhost port 8080 (#0)
  59. * Trying ::1... connected
  60. > GET /geoserver/wfs?request=getcapabilities HTTP/1.1
  61. > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
  62. > Host: localhost:8080
  63. > Accept: */*
  64. >
  65. < HTTP/1.1 403 Access Denied
  66. < Content-Type: text/html; charset=iso-8859-1
  67. < Content-Length: 1407
  68. < Server: Jetty(6.1.8)
  69. <
  70. <html>
  71. <head>
  72. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
  73. <title>Error 403 Access Denied</title>
  74. </head>
  75. ...
  76. #. Execute the same command but specify the right password.::
  77. curl -v -H "X-Credentials: private-user=admin&private-pw=geoserver" "http://localhost:8080/geoserver/wms?service=WMS&version=1.1.1&request=GetCapabilities"
  78. The result should be a successful authentication and contain the normal WMS capabilities response.
  79. Configure Apache HTTPD to forward an Header with authentication credentials
  80. ---------------------------------------------------------------------------
  81. This can be done with an HTTPD configuration that looks like the following:
  82. .. code-block:: apacheconf
  83. <Location /geoserver>
  84. Session On
  85. SessionEnv On
  86. SessionHeader X-Replace-Session
  87. SessionCookieName session path=/
  88. SessionCryptoPassphrase secret
  89. RequestHeader set X-Credentials "%{HTTP_SESSION}e"
  90. </Location>
  91. This configuration adds a new `X-Credentials` Request Header to each GeoServer request.
  92. The request header will contain the HTTPD Session information in a special format.
  93. An example of the Session content is the following:
  94. X-Credentials: private-user=admin&private-pw=geoserver
  95. As you can see it contains both the username and password of the user, so the data can
  96. be used to authenticate the user in GeoServer.