index.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. .. _security_tutorials_cert:
  2. Configuring X.509 Certificate Authentication
  3. ============================================
  4. Certificate authentication involves the usage of public/private keys to identify oneself. This represents a much more secure alternative to basic username and password schemes.
  5. `X.509 <http://en.wikipedia.org/wiki/X.509>`_ is a well defined standard for the format of public key certificates. This tutorial walks through the process of setting up X.509 certificate authentication.
  6. Prerequisites
  7. -------------
  8. This tutorial assumes the following:
  9. * A web browser that supports the usage of client certificates for authentication, also referred to as "two-way SSL". This tutorial uses **Firefox**.
  10. * An SSL-capable servlet container. This tutorial uses **Tomcat**.
  11. * GeoServer is deployed in Tomcat.
  12. Configure the user/group service
  13. --------------------------------
  14. Users authenticated via a X.509 certificate must be configured in GeoServer. For this a new user/group service will be added.
  15. #. Login to the web admin interface as the ``admin`` user.
  16. #. Click the ``Users, Groups, and Roles`` link located under the ``Security`` section of
  17. the navigation sidebar.
  18. .. figure:: images/cert1.jpg
  19. #. Scroll down to the ``User Group Services`` panel and click the ``Add new`` link.
  20. #. Create a new user/group service named :kbd:`cert-ugs` and fill out the settings form as follows:
  21. * Set :guilabel:`Password encryption` to :kbd:`Empty` since users will not authenticate via password.
  22. * Set :guilabel:`Password policy` to :kbd:`default`.
  23. .. figure:: images/cert2.jpg
  24. #. Click :guilabel:`Save`.
  25. #. Back on the ``Users, Groups, and Roles`` page, click the :guilabel:`cert-ugs` link.
  26. .. figure:: images/cert3.jpg
  27. #. Select the :guilabel:`Users` tab and click the :guilabel:`Add new user` link.
  28. .. figure:: images/cert4.jpg
  29. #. Add a new user named :kbd:`rod` the and assign the ``ADMIN`` role.
  30. .. figure:: images/cert5.jpg
  31. #. Click :guilabel:`Save`.
  32. #. Click the :guilabel:`Authentication` link located under the :guilabel:`Security` section of the navigation sidebar.
  33. .. figure:: images/cert6.jpg
  34. #. Scroll down to the :guilabel:`Authentication Filters` panel and click the :guilabel:`Add new` link.
  35. .. figure:: images/cert7.jpg
  36. #. Click the :guilabel:`X.509` link and fill out form as follows:
  37. * Set :guilabel:`Name` to "cert"
  38. * Set :guilabel:`Role source` to :kbd:`User group service` and set the associated drop-down to :kbd:`cert-ugs`
  39. .. figure:: images/cert8.jpg
  40. #. Click :guilabel:`Save`.
  41. #. Back on the authentication page, scroll down to the :guilabel:`Filter Chains` panel.
  42. #. Click :guilabel:`web` in the :guilabel:`Name` column.
  43. #. Select the :guilabel:`cert` filter and position it after the :guilabel:`rememberme` filter.
  44. .. figure:: images/cert9.jpg
  45. #. Click :guilabel:`Close`.
  46. #. You will be returned to the previous page. Click :guilabel:`Save`.
  47. .. warning::
  48. This last change requires both :guilabel:`Close` and then :guilabel:`Save` to be clicked. You may wish to return to the :guilabel:`web` dialog to verify that the change was made.
  49. Download sample certificate files
  50. ---------------------------------
  51. Rather than demonstrate how to create or obtain valid certificates, which is beyond the scope of this tutorial, sample files available as part of the spring security `sample applications <https://github.com/SpringSource/spring-security/tree/master/samples/certificates>`_ will be used.
  52. Download and unpack the :download:`sample certificate files <sample_certs.zip>`. This archive contains the following files:
  53. * :file:`ca.pem` is the certificate authority (CA) certificate issued by the "Spring Security Test CA" certificate authority. This file is used to sign the server and client certificates.
  54. * :file:`server.jks` is the Java keystore containing the server certificate and private key used by Tomcat and presented to the user during the setup of the SSL connection.
  55. * :file:`rod.p12` contains the client certificate / key combination used to perform client authentication via the web browser.
  56. Configure Tomcat for SSL
  57. ------------------------
  58. #. Copy the :file:`server.jks` file into the :file:`conf` directory under the root of the Tomcat installation.
  59. #. Edit the Tomcat :file:`conf/server.xml` and add an SSL connector:
  60. .. code-block:: xml
  61. <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" scheme="https" secure="true"
  62. clientAuth="true" sslProtocol="TLS"
  63. keystoreFile="${catalina.home}/conf/server.jks"
  64. keystoreType="JKS" keystorePass="password"
  65. truststoreFile="${catalina.home}/conf/server.jks"
  66. truststoreType="JKS" truststorePass="password" />
  67. This enables SSL on port 8443.
  68. #. By default, Tomcat has APR enabled. To disable it so the above configuration can work, remove or comment out the following line in the server.xml configuration file
  69. .. code-block:: xml
  70. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  71. #. Restart Tomcat.
  72. Install the client certificate
  73. ------------------------------
  74. #. In Firefox, select :guilabel:`Preferences` (or :menuselection:`Tools --> Options`) and navigate to the :guilabel:`Advanced` panel.
  75. #. Select the :guilabel:`Encryption` tab (or the :guilabel:`Certificates` tab, depending on your version) and click the :guilabel:`View Certificates` button.
  76. .. figure:: images/cert10.jpg
  77. #. On the :guilabel:`Your Certificates` panel click the :guilabel:`Import` button and select the :file:`rod.p12` file.
  78. #. When prompted enter in the password :kbd:`password`.
  79. .. figure:: images/cert11.jpg
  80. #. Click :guilabel:`OK` and close the Firefox Preferences.
  81. Test certificate login
  82. ----------------------
  83. #. Navigate to the GeoServer admin on port "8443" using HTTPS: https://localhost:8443/geoserver/web
  84. #. You will be prompted for a certificate. Select the :guilabel:`rod` certificate for identification.
  85. .. figure:: images/cert12.jpg
  86. #. When warned about the self-signed server certificate, click :guilabel:`Add Exception` to add a security exception.
  87. .. figure:: images/cert13.jpg
  88. The result is that the user ``rod`` is now logged into the GeoServer admin interface.
  89. .. figure:: images/cert14.jpg
  90. .. note::
  91. Starting with version 31, Firefox implements a new mechanism for using certificates, which will cause a *Issuer certificate is invalid error (sec_error_ca_cert_invalid)* error when trying to use a self-signed repository such as the one proposed. To avoid that, you can disable this mechanism by browsing to **about:config** and setting the **security.use_mozillapkix_verification** parameter to **false**.
  92. .. figure:: images/mozilla_pki.jpg