layer.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. .. _security_layer:
  2. Layer security
  3. ==============
  4. GeoServer allows access to be determined on a per-layer basis.
  5. .. note:: Layer security and :ref:`security_service` cannot be combined. For example, it is not possible to specify access to a specific OWS service, only for one specific layer.
  6. Providing access to layers is linked to :ref:`roles <security_rolesystem_roles>`. Layers and roles are linked in a file called ``layers.properties``, which is located in the ``security`` directory in your GeoServer data directory. The file contains the rules that control access to workspaces and layers.
  7. .. note:: The default layers security configuration in GeoServer allows any anonymous user to read data from any layer but only allows admin users to edit data.
  8. Rules
  9. -----
  10. The syntax for a layer security rule can follow three different patterns (``[]`` denotes optional parameters)::
  11. globalLayerGroup.permission=role[,role2,...]
  12. workspace.layer.permission=role[,role2,...]
  13. workspace.workspaceLayerGroup.permission=role[,role2,...]
  14. The parameters include:
  15. * ``globalLayerGroup``— Name of a global layer group (one without workspace associated to it).
  16. * ``workspace``— Name of the workspace. The wildcard ``*`` is used to indicate all workspaces.
  17. * ``layer``— Name of a resource (featuretype/coverage/etc...). The wildcard ``*`` is used to indicate all layers.
  18. * ``workspaceLayerGroup``— Name of a workspace specific layer group.
  19. * ``permission``— Type of access permission/mode.
  20. * ``r``—Read access
  21. * ``w``—Write access
  22. * ``a``—Admin access
  23. See :ref:`access_mode` for more details.
  24. * ``role[,role2,...]`` is the name(s) of predefined roles. The wildcard ``*`` is used to indicate the permission is applied to all users, including anonymous users.
  25. .. note::
  26. If a workspace or layer name is supposed to contain dots, they can be escaped using double backslashes (``\\``). For example, if a layer is named ``layer.with.dots`` the following syntax for a rule may be used::
  27. topp.layer\\.with\\.dots.r=role[,role2,...]
  28. General rules for layer security:
  29. * Each entry must have a unique combination of workspace, layer, and permission values.
  30. * If a permission at the global level is not specified, global permissions are assumed to allow read/write access.
  31. * If a permission for a workspace is not specified, it inherits permissions from the global specification.
  32. * If a permission for a layer is not specified, it inherits permissions from its workspace specification in all protocols except WMS (where layer groups rules play a role, see below).
  33. * If a user belongs to multiple roles, the **least restrictive** permission they inherit will apply.
  34. For WMS, layers will be also secured by considering their containing layer groups. In particular:
  35. * Rules with *Single* layer groups only affect the group itself, but not its contents. *Single* mode is considered just an alias for a list of layers, with no containment.
  36. * Rules with other types of groups (*Named tree*, *Container tree*, *Earth Observation tree*) also affect contained layers and nested layer groups.
  37. If the group is not accessible, the layers and groups contained in that group will not be accessible either..
  38. The only exception is when another layer group which is accessible contains the same layer or nested group, in that case the layers they will show up under the allowed groups.
  39. * Workspace rules gets precedence over global layer group ones when it comes to allowing access to layers.
  40. * Layer rules get precedence over all layer group rules when it comes to allowing access to layers.
  41. The following tables summarizes the layer group behavior depending on whether they are used in a public or secured environment:
  42. +----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  43. | **Mode** | **Public behavior** | **Restricted behavior** |
  44. +======================+====================================================================================================================================================+==================================================================================================================================+
  45. | **Single** | Looks like a stand-alone layer, can be requested directly and acts as an alias for a layer list. Layers are also visible at root level | Does not control layer access at all |
  46. +----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  47. | **Opaque container** | Looks like a stand-alone layer, can be requested directly and acts as an alias for a layer list. Layers in it are not available for WMS requests | Same as public behavior |
  48. +----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  49. | **Named tree** | Contained layers are visible as children in the capabilities document, the name can be used as a shortcut to request all layers. | Restricting access to the group restricts also the contained layers, unless another "tree" group allows access to the same layer |
  50. +----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  51. | **Container tree** | Same as "named tree", but does not have a name published in the capabilities document and thus cannot be requested directly | Same as "named tree" |
  52. +----------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
  53. Catalog Mode
  54. ------------
  55. The ``layers.properties`` file may contain a further directive that specifies how GeoServer will advertise secured layers and behave when a secured layer is accessed without the necessary privileges. The parameter is ``mode`` and is commonly referred to as the "catalog mode".
  56. The syntax is::
  57. mode=option
  58. ``option`` may be one of three values:
  59. .. list-table::
  60. :widths: 20 80
  61. :header-rows: 1
  62. * - Option
  63. - Description
  64. * - ``hide``
  65. - *(Default)* Hides layers that the user does not have read access to, and behaves as if a layer is read only if the user does not have write permissions. The capabilities documents will not contain the layers the current user cannot access. This is the highest security mode. As a result, it may not work very well with clients such as uDig or Google Earth.
  66. * - ``challenge``
  67. - Allows free access to metadata, but any attempt at accessing actual data is met by a HTTP 401 code (which forces most clients to show an authentication dialog). The capabilities documents contain the full list of layers. DescribeFeatureType and DescribeCoverage operations work successfully. This mode works fine with clients such as uDig or Google Earth.
  68. * - ``mixed``
  69. - Hides the layers the user cannot read from the capabilities documents, but triggers authentication for any other attempt to access the data or the metadata. This option is useful if you don't want the world to see the existence of some of your data, but you still want selected people who have data access links to get the data after authentication.
  70. .. _access_mode:
  71. Access modes
  72. ------------
  73. The access mode defines what level of access should be granted on a specific workspace/layer to a particular role. There are three types of access mode:
  74. * ``r``—**Read mode** (read data from a workspace/layer)
  75. * ``w``—**Write mode** (write data to a workspace/layer)
  76. * ``a``—**Admin mode** (access and modify the configuration of a workspace/layer)
  77. Some notes on the above access modes:
  78. * Write does not imply Read, but Admin implies both Write *and* Read.
  79. * Read and Write apply to the data of a layer, while Admin applies to the configuration of a layer.
  80. * As Admin mode only refers to the configuration of the layer, it is not required for any OGC service request.
  81. .. note:: Currently, it is possible to assign Admin permission only to an entire workspace, and not to specific layers.
  82. Examples
  83. --------
  84. The following examples illustrate some possible layer restrictions and the corresponding rules.
  85. Protecting a single workspace and a single layer
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. The following example demonstrates how to configure GeoServer as a primarily a read-only server::
  88. *.*.r=*
  89. *.*.w=NO_ONE
  90. private.*.r=TRUSTED_ROLE
  91. private.*.w=TRUSTED_ROLE
  92. topp.congress_district.w=STATE_LEGISLATORS
  93. The mapping of roles to permissions is as follows:
  94. .. list-table::
  95. :widths: 20 20 20 20 20
  96. :header-rows: 1
  97. * - Role
  98. - private.*
  99. - topp.*
  100. - topp.congress_district
  101. - (all other workspaces)
  102. * - ``NO_ONE``
  103. - (none)
  104. - w
  105. - (none)
  106. - w
  107. * - ``TRUSTED_ROLE``
  108. - r/w
  109. - r
  110. - r
  111. - r
  112. * - ``STATE_LEGISLATORS``
  113. - (none)
  114. - r
  115. - r/w
  116. - r
  117. * - (All other users)
  118. - (none)
  119. - r
  120. - r
  121. - r
  122. .. note:: Specific workspace rule ``private.*.r=TRUSTED_ROLE`` will take precedence over the more generic rule ``*.*.r=*``. When a request is made to read a layer ``private:vulnerable_infrastructure`` the most specific rule available is used to control access. In this case the workspace rule ``private.*.r=TRUSTED_ROLE`` is the most specific and only users that have TRUSTED_ROLE will be granted ``r`` access and be able to read the ``private:vulnerable_infrastructure`` layer. Other users that do not have the TRUSTED_ROLE will not be granted ``r`` access and will be unable to access the ``private:vulnerable_infrastructure`` layer.
  123. Locking down GeoServer
  124. ~~~~~~~~~~~~~~~~~~~~~~
  125. The following example demonstrates how to lock down GeoServer::
  126. *.*.r=TRUSTED_ROLE
  127. *.*.w=TRUSTED_ROLE
  128. topp.*.r=*
  129. army.*.r=MILITARY_ROLE,TRUSTED_ROLE
  130. army.*.w=MILITARY_ROLE,TRUSTED_ROLE
  131. The mapping of roles to permissions is as follows:
  132. .. list-table::
  133. :widths: 25 25 25 25
  134. :header-rows: 1
  135. * - Role
  136. - topp.*
  137. - army.*
  138. - (All other workspaces)
  139. * - ``TRUSTED_ROLE``
  140. - r/w
  141. - r/w
  142. - r/w
  143. * - ``MILITARY_ROLE``
  144. - r
  145. - r/w
  146. - (none)
  147. * - (All other users)
  148. - r
  149. - (none)
  150. - (none)
  151. Providing restricted administrative access
  152. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  153. The following provides administrative access on a single workspace to a specific role, in additional to the full administrator role::
  154. *.*.a=ROLE_ADMINISTRATOR
  155. topp.*.a=ROLE_TOPP_ADMIN,ROLE_ADMINISTRATOR
  156. Managing multi-level permissions
  157. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158. The following example demonstrates how to configure GeoServer with global-, workspace--, and layer-level permissions::
  159. *.*.r=TRUSTED_ROLE
  160. *.*.w=NO_ONE
  161. topp.*.r=*
  162. topp.states.r=USA_CITIZEN_ROLE,LAND_MANAGER_ROLE,TRUSTED_ROLE
  163. topp.states.w=NO_ONE
  164. topp.poly_landmarks.w=LAND_MANAGER_ROLE
  165. topp.military_bases.r=MILITARY_ROLE
  166. topp.military_bases.w=MILITARY_ROLE
  167. The mapping of roles to permissions is as follows:
  168. .. list-table::
  169. :widths: 25 15 15 15 15 15
  170. :header-rows: 1
  171. * - Role
  172. - topp.states
  173. - topp.poly_landmarks
  174. - topp.military_bases
  175. - topp.(all other layers)
  176. - (All other workspaces)
  177. * - ``NO_ONE``
  178. - w
  179. - r
  180. - (none)
  181. - w
  182. - w
  183. * - ``TRUSTED_ROLE``
  184. - r
  185. - r
  186. - (none)
  187. - r
  188. - r
  189. * - ``MILITARY_ROLE``
  190. - (none)
  191. - r
  192. - r/w
  193. - r
  194. - (none)
  195. * - ``USA_CITIZEN_ROLE``
  196. - r
  197. - r
  198. - (none)
  199. - r
  200. - (none)
  201. * - ``LAND_MANAGER_ROLE``
  202. - r
  203. - r/w
  204. - (none)
  205. - r
  206. - (none)
  207. * - (All other users)
  208. - (none)
  209. - r
  210. - (none)
  211. - r
  212. - (none)
  213. .. note:: The entry ``topp.states.w=NO_ONE`` is not required because this permission would be inherited from the global level (the entry ``*.*.w=NO_ONE``).
  214. Invalid configuration
  215. ~~~~~~~~~~~~~~~~~~~~~
  216. The following examples are invalid because the workspace, layer, and permission combinations are not unique::
  217. topp.state.rw=ROLE1
  218. topp.state.rw=ROLE2,ROLE3
  219. Security by layer group in WMS
  220. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. To clarify, let's assume the following starting situation, in which all layers and groups are visible::
  222. root
  223. +- namedTreeGroupA
  224. | | ws1:layerA
  225. | └ ws2:layerB
  226. +- namedTreeGroupB
  227. | | ws2:layerB
  228. | └ ws1:layerC
  229. +- layerD
  230. +- singleGroupC (contains ws1:layerA and layerD when requested)
  231. Here are a few examples of how the structure changes based on different security rules.
  232. * Denying access to ``namedTreeGroupA`` by::
  233. namedTreeGroupA.r=ROLE_PRIVATE
  234. Will give the following capabilities tree to anonymous users::
  235. root
  236. +- namedTreeGroupB
  237. | | ws2:layerB
  238. | └ ws1:layerC
  239. +- layerD
  240. +- singleGroupC (contains only layerD when requested)
  241. * Denying access to ``namedTreeGroupB`` by ::
  242. namedTreeGroupB.r=ROLE_PRIVATE
  243. Will give the following capabilities tree to anonymous users::
  244. root
  245. +- namedTreeGroupA
  246. | | ws1:layerA
  247. | └ ws2:layerB
  248. +- layerD
  249. +- singleGroupC (contains ws1:layerA and layerD when requested)
  250. * Denying access to ``singleGroupC`` by::
  251. singleGroupC.r=ROLE_PRIVATE
  252. Will give the following capabilities tree to anonymous users::
  253. root
  254. +- namedTreeGroupA
  255. | | ws1:layerA
  256. | └ ws2:layerB
  257. +- namedTreeGroupB
  258. | | ws2:layerB
  259. | └ ws1:layerC
  260. +- layerD
  261. * Denying access to everything, but allowing explicit access to namedTreeGroupA by::
  262. nameTreeGroupA.r=*
  263. *.*.r=PRIVATE
  264. *.*.w=PRIVATE
  265. Will give the following capabilities tree to anonymous users::
  266. root
  267. +- namedTreeGroupA
  268. | ws1:layerA
  269. └ ws2:layerB
  270. * Denying access to ``nameTreeGroupA`` and ``namedTreeGroupB`` but explicitly allowing access to ``ws1:layerA``::
  271. namedTreeGroupA.r=ROLE_PRIVATE
  272. namedTreeGroupB.r=ROLE_PRIVATE
  273. ws1.layerA.r=*
  274. Will give the following capabilities tree to anonymous users (notice how ws1:layerA popped up to the root)::
  275. root
  276. +- ws1:layerA
  277. +- layerD
  278. * Denying access to ``nameTreeGroupA`` and ``namedTreeGroupB`` but explicitly allowing all layers in ws2
  279. (a workspace rule overrides global groups ones)::
  280. namedTreeGroupA.r=ROLE_PRIVATE
  281. namedTreeGroupB.r=ROLE_PRIVATE
  282. ws2.*.r=*
  283. Will give the following capabilities tree to anonymous users (notice how ws1:layerB popped up to the root)::
  284. root
  285. +- ws2:layerB
  286. +- layerD
  287. +- singleGroupC