configuration.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. .. _community_jwtheaders_config:
  2. JWT Headers configuration
  3. =========================
  4. The JWT Headers module covers three main use cases:
  5. #. Simple Text, JSON, or JWT headers for the username
  6. #. Verification of JWT Access Tokens
  7. #. Getting roles from a JSON header or an attached JWT Access Token claim
  8. Configuration Options
  9. ---------------------
  10. User Name Options
  11. ^^^^^^^^^^^^^^^^^
  12. .. list-table:: User Name Options
  13. :header-rows: 1
  14. * - Config Option
  15. - Meaning
  16. * - Request header attribute for User Name
  17. - The name of the HTTP header item that contains the user name.
  18. * - Format the Header value is in
  19. - Format that the user name is in:
  20. * Simple String - user name is the header's value.
  21. * JSON - The header is a JSON string. Use "JSON path" for where the user name is in the JSON.
  22. * JWT - The header is a JWT (base64) string. Use "JSON path" for where the user name is in the JWT claims.
  23. * - JSON path for the User Name
  24. - If the user name is in JSON or JWT format, this is the JSON path to the user's name.
  25. If you are using `Apache's mod_auth_openidc <https://github.com/OpenIDC/mod_auth_openidc>`_, then Apache will typically add:
  26. * an `OIDC_id_token_payload` header item (containing a JSON string of the ID token claims)
  27. * an `OIDC_access_token` header item (containing a base64 JWT Access Token)
  28. * optionally, a simple header item with individual claim values (i.e. `OIDC_access_token`)
  29. Here are some example values;
  30. .. code-block::
  31. OIDC_id_token_payload: {"exp":1708555947,"iat":1708555647,"auth_time":1708555288,"jti":"42ee833e-89d3-4779-bd9d-06b979329c9f","iss":"http://localhost:7777/realms/dave-test2","aud":"live-key2","sub":"98cfe060-f980-4a05-8612-6c609219ffe9","typ":"ID","azp":"live-key2","nonce":"4PhqmZSJ355KBtJPbAP_PdwqiLnc7B1lA2SGpB0zXr4","session_state":"7712b364-339a-4053-ae0c-7d3adfca9005","at_hash":"2Tyw8q4ZMewuYrD38alCug","acr":"0","sid":"7712b364-339a-4053-ae0c-7d3adfca9005","upn":"david.blasby@geocat.net","resource_access":{"live-key2":{"roles":["GeonetworkAdministrator","GeoserverAdministrator"]}},"email_verified":false,"address":{},"name":"david blasby","groups":["default-roles-dave-test2","offline_access","uma_authorization"],"preferred_username":"david.blasby@geocat.net","given_name":"david","family_name":"blasby","email":"david.blasby@geocat.net"}
  32. .. code-block::
  33. OIDC_access_token: eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICItb0QyZXphcjF3ZHBUUmZCS0NqMFY4cm5ZVkJGQmxJLW5ldzFEREJCNTJrIn0.eyJleHAiOjE3MDg1NTU5NDcsImlhdCI6MTcwODU1NTY0NywiYXV0aF90aW1lIjoxNzA4NTU1Mjg4LCJqdGkiOiI0M2UyYjUwZS1hYjJkLTQ2OWQtYWJjOC01Nzc1YTY0MTMwNTkiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0Ojc3NzcvcmVhbG1zL2RhdmUtdGVzdDIiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiOThjZmUwNjAtZjk4MC00YTA1LTg2MTItNmM2MDkyMTlmZmU5IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibGl2ZS1rZXkyIiwibm9uY2UiOiI0UGhxbVpTSjM1NUtCdEpQYkFQX1Bkd3FpTG5jN0IxbEEyU0dwQjB6WHI0Iiwic2Vzc2lvbl9zdGF0ZSI6Ijc3MTJiMzY0LTMzOWEtNDA1My1hZTBjLTdkM2FkZmNhOTAwNSIsImFjciI6IjAiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiZGVmYXVsdC1yb2xlcy1kYXZlLXRlc3QyIiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImxpdmUta2V5MiI6eyJ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mQ917Ep0g
  34. .. code-block::
  35. OIDC_preferred_username: david.blasby@geocat.net
  36. It is recommended to either use the `OIDC_id_token_payload` (JSON) or `OIDC_access_token` (JWT) header.
  37. For `OIDC_id_token_payload`:
  38. * Request header attribute for User Name: `OIDC_id_token_payload`
  39. * Format the Header value is in: `JSON`
  40. * JSON path for the User Name: `preferred_username`
  41. For `OIDC_access_token`:
  42. * Request header attribute for User Name: `OIDC_access_token`
  43. * Format the Header value is in: `JWT`
  44. * JSON path for the User Name: `preferred_username`
  45. New Role Source Options
  46. ^^^^^^^^^^^^^^^^^^^^^^^
  47. You can use the standard role source options in GeoServer (`Request Header`, `User Group Service`, or `Role Service`). The JWT Headers module adds two more role sources - `Header Containing JSON String` and `Header containing JWT`.
  48. .. list-table:: New Role Source Options
  49. :header-rows: 1
  50. * - Config Option
  51. - Meaning
  52. * - Role Source
  53. - Which Role Source to use:
  54. * Header containing JSON String - Header contains a JSON claims object
  55. * Header Containing JWT - Header contains a Base64 JWT Access Token
  56. * - Request Header attribute for Roles
  57. - Name of the header item the JSON or JWT is contained in
  58. * - JSON Path
  59. - Path in the JSON object or JWT claims that contains the roles. This should either be a simple string (single role) or a list of strings.
  60. Using the example `OIDC_id_token_payload` (JSON) or `OIDC_access_token` (JWT) shown above, the claims are:
  61. .. code-block:: json
  62. {
  63. "exp": 1708555947,
  64. "iat": 1708555647,
  65. "auth_time": 1708555288,
  66. "jti": "42ee833e-89d3-4779-bd9d-06b979329c9f",
  67. "iss": "http://localhost:7777/realms/dave-test2",
  68. "aud": "live-key2",
  69. "sub": "98cfe060-f980-4a05-8612-6c609219ffe9",
  70. "typ": "ID",
  71. "azp": "live-key2",
  72. "nonce": "4PhqmZSJ355KBtJPbAP_PdwqiLnc7B1lA2SGpB0zXr4",
  73. "session_state": "7712b364-339a-4053-ae0c-7d3adfca9005",
  74. "at_hash": "2Tyw8q4ZMewuYrD38alCug",
  75. "acr": "0",
  76. "sid": "7712b364-339a-4053-ae0c-7d3adfca9005",
  77. "upn": "david.blasby@geocat.net",
  78. "resource_access":
  79. {
  80. "live-key2":
  81. {
  82. "roles":
  83. [
  84. "GeonetworkAdministrator",
  85. "GeoserverAdministrator"
  86. ]
  87. }
  88. },
  89. "email_verified": false,
  90. "address": { },
  91. "name": "david blasby",
  92. "groups": ["default-roles-dave-test2", "offline_access", "uma_authorization"],
  93. "preferred_username": "david.blasby@geocat.net",
  94. "given_name": "david",
  95. "family_name": "blasby",
  96. "email": "david.blasby@geocat.net"
  97. }
  98. In this JSON set of claims (mirrored in the JWT claims of the Access Token), and the two roles from the IDP are "GeonetworkAdministrator", and "GeoserverAdministrator". The JSON path to the roles is `resource_access.live-key2.roles`.
  99. Role Conversion
  100. """""""""""""""
  101. The JWT Headers module also allows for converting roles (from the external IDP) to the GeoServer internal role names.
  102. .. list-table:: Role Converter Options
  103. :header-rows: 1
  104. * - Config Option
  105. - Meaning
  106. * - Role Converter Map from External Roles to Geoserver Roles
  107. - This is a ";" delimited map in the form of `ExternalRole1=GeoServerRole1;ExternalRole2=GeoServerRole2`
  108. * - Only allow External Roles that are explicitly named above
  109. - If checked, external roles that are not mentioned in the conversion map will be ignored. If unchecked, those external roles will be turned into GeoServer roles of the same name.
  110. For example, a conversion map like `GeoserverAdministrator=ROLE_ADMINISTRATOR` will convert our IDP "GeoserverAdministrator" role to GeoServer's "ROLE_ADMINISTRATOR".
  111. In our example, the user has two roles "GeoserverAdministrator" and "GeonetworkAdministrator". If the "Only allow External Roles that are explicitly named above" is checked, then GeoServer will only see the "ROLE_ADMINISTRATOR" role. If unchecked, it will see "ROLE_ADMINISTRATOR" and "GeonetworkAdministrator". In neither case will it see the converted "GeoserverAdministrator" roles.
  112. You can also have multiple GeoServer roles from one external (OIDC) role. For example, this role conversion:
  113. `GeoserverAdministrator=ROLE_ADMINISTRATOR;GeoserverAdministrator=ADMIN`
  114. Will give users with the OIDC role `GeoserverAdministrator` two GeoServer roles - `ROLE_ADMINISTRATOR` and `ADMIN`.
  115. JWT Validation
  116. ^^^^^^^^^^^^^^
  117. If you are using Apache's `mod_auth_openidc` module, then you do *not* have to do JWT validation - Apache will ensure they are valid when it attaches the headers to the request.
  118. However, if you are using robot access to GeoServer, you can attach an Access Token to the request header for access.
  119. .. code-block::
  120. Authentication: Bearer `base64 JWT Access Token`
  121. OR
  122. .. code-block::
  123. Authentication: `base64 JWT Access Token`
  124. You would then setup the user name to come from a JWT token in the `Authentication` header with a JSON path like `preferred_username`.
  125. You can also extract roles from the Access Token in a similar manner - make sure your IDP imbeds roles inside the Access Token.
  126. .. list-table:: JWT Validation Options
  127. :header-rows: 1
  128. * - Config Option
  129. - Meaning
  130. * - Validate JWT (Access Token)
  131. - If unchecked, do not do any validation.
  132. * - Validate Token Expiry
  133. - If checked, validate the `exp` claim in the JWT and ensure it is in the future. This should always be checked so you do not allow expired tokens.
  134. * - Validate JWT (Access Token) Signature
  135. - If checked, validate the Token's Signature
  136. * - JSON Web Key Set URL (jwks_uri)
  137. - URL for a JWK Set. This is typically called `jwks_uri` in the OIDC metadata configuration. This will be downloaded and used to check the JWT's signature. This should always be checked to ensure that the JWT has not been modified.
  138. * - Validate JWT (Access Token) Against Endpoint
  139. - If checked, validate the access token against an IDP's token verification URL.
  140. * - URL (userinfo_endpoint)
  141. - IDP's token validation URL. This URL will be retrieved by adding the Access Token to the `Authentiation: Bearer <access token>` header. It should return a HTTP 200 status code if the token is valid. This is recommened by the OIDC specification.
  142. * - Also validate Subject
  143. - If checked, the `sub` claim of the Access Token and the "userinfo_endpoint" `sub` claim will be checked to ensure they are equal. This is recommened by the OIDC specification.
  144. * - Validate JWT (Access Token) Audience
  145. - If checked, the audience of the Access Token is checked. This is recommened by the OIDC specification since this verifies that the Access Token is meant for us.
  146. * - Claim Name
  147. - The name of the claim the audience is in (`aud`, `azp`, or `appid` claim) the Access Token.
  148. * - Required Claim Value
  149. - The value this claim must be (if the claim is a list of string, then it must contain this value).