keycloak_role_service.rst 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. .. _security_tutorials_keycloak_role_service:
  2. Keycloak Role Service
  3. =====================
  4. This tutorial walks through how to set up Keycloak as a role service for GeoServer.
  5. .. note:: In this example the Keycloak service runs on port `8080` while GeoServer runs on port `8181`.
  6. The Keycloak Role Service uses the Keycloak REST api in order to retrieve the roles for its various operations. By default it will retrieve roles with ``realm`` scope.
  7. However it can be configured to retrieve roles with a client scope in a specific realm.
  8. Keycloak Client Configuration
  9. -----------------------------
  10. Follow the `Authentication with Keycloak <https://docs.geoserver.org/latest/en/user/community/keycloak/index.html>`_
  11. guide to configure GeoServer to allow logging in via Keycloak. The Keycloak Role Service needs a client to be configured on Keycloak side having ``Access Type`` set to ``confidential``.
  12. If for your Keycloak Authentication Filter you have used a different ``Access Type`` i.e. ``barer-only``, a separate client will have then to be configured for the Keycloak Role Service.
  13. For the client, ensure that:
  14. * Standard flow, implicit flow, and direct access grants are enabled
  15. * The base URL is set to ``http://localhost:8181/geoserver/web``
  16. * The following redirect URIs are enabled:
  17. * ``http://localhost:8181/geoserver*``
  18. * ``http://localhost:8080/auth/realms/master/broker/keycloak-oidc/endpoint*``
  19. * The ``Access Type`` is set to **confidential** and the ``Service Accounts Enabled`` option is enabled.
  20. .. figure:: images/role_service/access_type_confidential.png
  21. :align: center
  22. * Under the ``Service Account Roles`` tab, ensure that the realm-admin, from the realm-management client role is addedd to the ``Assigned roles``.
  23. .. figure:: images/role_service/service_account_roles.png
  24. :align: center
  25. To assign a user a role:
  26. #. Under the users section in Keycloak, click the user's ID (if there are missing users, click "View all users").
  27. #. In the role mappings tab, select the GeoStore client from the client roles dropdown.
  28. #. Select the role from the available roles, and click add selected.
  29. .. figure:: images/role_service/keycloak_client002.png
  30. :align: center
  31. *An example set of role mappings for a user.*
  32. When creating custom roles, ensure they begin with ``ROLE_`` e.g. ROLE_STAFF.
  33. GeoServer Configuration for Role Syncing
  34. ----------------------------------------
  35. Role syncing with Keycloak will be tied to the confidential client.
  36. #. In GeoServer as an admin, on the 'Users, Groups, Roles' page, add a new role service.
  37. #. Select Keycloak from the list of provided options. All fillable fields are required, excluding the ``Comma separated list of ID of client (not client-id)``.
  38. * ``Base URL for Keycloak`` is the keycloak host name eg. http://localhost:8080.
  39. * The ``Realm Name`` is the realm from which the roles should be retrieved eg. master.
  40. * The ``Client ID`` can be retrieved from the ``Settings`` tab of the client configuration on Keycloak.
  41. * The ``Client secret`` can be retrieved from the ``Credentials`` tab of the client configuration on Keycloak.
  42. * The ``Comma separated list of ID of client (not client-id)`` is meant to allow the Role Service to retrieve also roles with client scope. By default indeed the Keycloak Role Service will retrieve realm roles only. The id of a client can be retrieved from the URL when viewing the client configuration page in Keycloak. URL format: eg. ``/auth/admin/master/console/#/realms/master/clients/{ID of client}``
  43. ``Administrator Role`` and ``Group administator`` role dropdown should be empty at the beginning. They can be filled once saved the role service with the Keycloak role that we want to map to the GeoServer ADMIN and GROUP ADMIN.
  44. #. Ensure you click save to create the Keycloak role service.
  45. #. Once the Role Service has been created and configured to have it active:
  46. * it can be assigned as a RoleSource to the Keycloak Filter,
  47. * it can be set as the ``Active Role Service`` in the ``Security Settings`` page.
  48. .. figure:: images/role_service/keycloak_role_service001.png
  49. :align: center
  50. *An example of a fully configured Keycloak role service.*
  51. GeoServer Configuration for Keycloak Authentication Filters
  52. -----------------------------------------------------------
  53. Under the Authentication section of GeoServer:
  54. * Add the Keycloak authentication filter to the top of the web and default filter chains.
  55. * Add keycloak to the selected provider chains, and place it above the default.