authentication.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. .. _security_tutorials_keycloak:
  2. Authentication with Keycloak
  3. ============================
  4. This tutorial introduces GeoServer Keycloak support and walks through the process of
  5. setting up authentication against an Keycloak provider. It is recommended that the
  6. :ref:`security_auth_chain` section be read before proceeding.
  7. The GeoServer Keycloak-authn/authz plugin will allow you to use an instance of Keycloak to control access to resources within GeoServer.
  8. Configuration Instructions
  9. --------------------------
  10. **As the Keycloak Admin:**
  11. .. note:: In this example the Keycloak service runs on port `8080` while GeoServer runs on port `8181`
  12. 1. Create a `new client <http://www.keycloak.org/docs/3.3/authorization_services/topics/resource-server/create-client.html>`_ for GeoServer named `geoserver-client`.
  13. .. figure:: images/keycloak_client001.png
  14. :align: center
  15. 2. Make sure to add the base URL of GeoServer to the list of acceptable redirect paths, and add also the Keycloak OIDC endpoint base URI.
  16. eg:
  17. - http://localhost:8181/geoserver*
  18. - http://localhost:8080/auth/realms/demo/broker/keycloak-oidc/endpoint*
  19. .. figure:: images/keycloak_client002.png
  20. :align: center
  21. 3. Set the `access-type` of client as appropriate. If your GeoServer instance is depending on another service for authentication (eg: NGINX auth plugin) then you should probably select *bearer-only*.
  22. Otherwise, you should select *confidential*.
  23. .. figure:: images/keycloak_client003.png
  24. :align: center
  25. 4. Add the *ADMINISTRATOR* and *AUTHENTICATED* `client-role <http://www.keycloak.org/docs/2.5/server_admin/topics/roles/client-roles.html>`_ to the `geoserver-client` in Keycloak.
  26. .. figure:: images/keycloak_client004.png
  27. :align: center
  28. In this phase you will need to map GeoServer Roles to the `geoserver-client` ones in Keycloak.
  29. .. figure:: images/keycloak_client005.png
  30. :align: center
  31. Use the *AUTHENTICATED* one for generic users. Assign this role *ADMINISTRATOR* to the users/groups who should have administrative access to GeoServer.
  32. .. figure:: images/keycloak_client006.png
  33. :align: center
  34. 5. Obtain the `installation-configuration <http://www.keycloak.org/docs/3.2/server_admin/topics/clients/installation.html>`_ for the `geoserver-client` in JSON, and provide this to the GeoServer Admin for the next steps.
  35. .. figure:: images/keycloak_client007.png
  36. :align: center
  37. **As the GeoServer Admin:**
  38. .. note:: In this example the Keycloak service runs on port `8080` while GeoServer runs on port `8181`
  39. 1. Under the Authentication UI, add a new `authentication-filter`. Select `Keycloak` from the list of provided options, and name your new filter *keycloak_adapter*.
  40. Paste the installation-configuration from the Keycloak-server in the text area provided.
  41. If not present, be sure to add the following options before clicking `Save`:
  42. .. code::
  43. "use-resource-role-mappings": true
  44. .. figure:: images/keycloak_adapter001.png
  45. :align: center
  46. The :guilabel:`Enable redirect to Keycloak Login page` checkbox should be checked if the desired behaviour is to authenticate on the web ui only through keycloak. Note that in this case the keycloak filter should be the only one available in the ``/web`` filter chain.
  47. On the contrary if the keycloak filter needs to coexists with other filters on the filter chain and reach it must be unchecked.
  48. The :guilabel:`Role Source` drop down enable the selection of the desired role source for the user being authenticated through keycloak. If none is selected by default the ``Active Role Service`` will be used.
  49. 2. Add the `keycloak_adapter` to the *web* `filter-chain` if you want to protect the Admin GUI, as an instance. If you have checked :guilabel:`Enable redirect to Keycloak Login page` on the filter configuration to be redirected every time to Keycloak, then remove all of the others `chain filters` (basic, form, rememberme, anonymous).
  50. .. figure:: images/keycloak_adapter002.png
  51. :align: center
  52. 3. Once done navigate to the GeoServer UI.
  53. If at filter configuration time the checkbox ``Enable redirect to Keycloak Login page`` was kept unchecked and the keycloak filter cohexists on the /web chain with the form and anonymous filter you will see a keycloak login button that allows the user to reach the keycloak login page.
  54. .. figure:: images/keycloak_login.png
  55. :align: center
  56. Otherwise the user will be directly redirected to the Keycloak `login-page`, and after logging-in redirected back to the actual GeoServer UI page.
  57. .. figure:: images/keycloak_adapter003.png
  58. :align: center
  59. You should verify that the message `logged in as <USERNAME>` is posted in the top right corner before continuing.
  60. .. figure:: images/keycloak_adapter004.png
  61. :align: center
  62. .. warning:: Workaround in the event of a 403 unauthorized response after logging-in.
  63. Enforce the algorithm RS256 in the keycloak client.
  64. .. figure:: images/keycloak_client008.png
  65. :align: center
  66. Copy the public key for the RS256 algorithm from the Realm Settings into the adapter config as:
  67. .. code::
  68. "realm-public-key": XXXXXXX
  69. .. figure:: images/keycloak_client009.png
  70. :align: center
  71. .. figure:: images/keycloak_adapter005.png
  72. :align: center