README.mapping.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  5. <title></title>
  6. <meta name="generator" content="LibreOffice 6.3.4.2.0 (Linux)"/>
  7. <meta name="author" content="irina "/>
  8. <meta name="created" content="2014-03-25T00:00:00.010305100"/>
  9. <meta name="changed" content="2020-04-13T14:19:46.849216419"/>
  10. <style type="text/css">
  11. @page { margin: 2.01cm }
  12. p { margin-bottom: 0.2cm }
  13. a:link { so-language: zxx }
  14. </style>
  15. </head>
  16. <body lang="ru-RU" dir="ltr"><p lang="en-US" style="margin-bottom: 0cm">
  17. <font size="4" style="font-size: 14pt">SQL Language Extension:
  18. CREATE/ALTER/CREATE_OR_ALTER/DROP MAPPING</font></p>
  19. <p style="margin-bottom: 0cm"><br/>
  20. </p>
  21. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Implements
  22. capability to control mapping of security objects to and between
  23. databases.</font></p>
  24. <p style="margin-bottom: 0cm"><br/>
  25. </p>
  26. <p style="margin-bottom: 0cm"><br/>
  27. </p>
  28. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Author:</font></p>
  29. <p style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt"><span lang="en-US">Alex
  30. Peshkoff &lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</span></font></p>
  31. <p style="margin-bottom: 0cm"><br/>
  32. </p>
  33. <p style="margin-bottom: 0cm"><br/>
  34. </p>
  35. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Preamble:</font></p>
  36. <p style="margin-bottom: 0cm"><br/>
  37. </p>
  38. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Firebird
  39. 3 supports multiple security databases. This is great feature, but it
  40. raises some problems, missing in systems with single security
  41. database. Clusters of databases, using same security database, are
  42. efficiently separated and this is what we typically want to achieve
  43. using different security databases. But in some cases we need
  44. controlled limited interaction between such clusters. As an examples
  45. can be provided EXECUTE STATEMENT ON EXTERNAL DATA SOURCE when some
  46. data exchange between clusters is required and letting server-wide
  47. SYSDBA access databases from other clusters using services. More or
  48. less similar problems were already known in windows version of
  49. firebird since v. 2.1 due to presence of trusted windows
  50. authentication – we had 2 separate lists of users (in security
  51. database and OS) and sometimes it was needed to make them be related.
  52. For example it appears to be good idea to automatically assign to
  53. windows users from some group appropriate firebird role.</font></p>
  54. <p style="margin-bottom: 0cm"><br/>
  55. </p>
  56. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Single
  57. solution for all this problems is MAPPING login information, assigned
  58. to user when it connected to firebird server, to internal security
  59. objects in database – current_user and current_role. Mapping rule
  60. contains 4 parts of information: </font>
  61. </p>
  62. <ul>
  63. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">mapping
  64. scope (is mapping local for current database or affects all
  65. databases in cluster, including security database),</font></p>
  66. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">mapping
  67. name (mappings are named like all the other objects in database), </font>
  68. </p>
  69. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">from
  70. what we map </font>
  71. </p>
  72. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">to
  73. what we map.</font></p>
  74. </ul>
  75. <p style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Here
  76. it's necessary to mention that all versions of firebird had one
  77. hardcoded global default rule – users authenticated in security
  78. database are always mapped into any database one-to-one. This rule is
  79. safe - if we have some security database it makes no use not to trust
  80. itself. Therefore (and due to backward compatibility) this rule is
  81. kept as is in firebird 3. What about mapping windows users to
  82. current_user (which was enabled by default in 2.1 &amp; 2.5 when
  83. trusted authentication enabled) in firebird 3 it must be done
  84. explicitly. This is required for systems with multiple security
  85. databases - not all of them need/use windows trusted authentication.</font></p>
  86. <p style="margin-bottom: 0cm"><br/>
  87. </p>
  88. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">'From'
  89. part of mapping has 4 items:</font></p>
  90. <ul>
  91. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">authentication
  92. source (plugin name or result of mapping in other database or use of
  93. serverwide authentication or any method),</font></p>
  94. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">name
  95. of database where authentication succeeded, </font>
  96. </p>
  97. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">name
  98. from which mapping is performed,</font></p>
  99. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">type
  100. of that name (username, role, OS group – this depends upon plugin
  101. which added that name during authentication).</font></p>
  102. </ul>
  103. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Each
  104. item may be ignored (any item is accepted) except type – it's
  105. definitely bad idea to mix different types of security objects.</font></p>
  106. <p style="margin-bottom: 0cm"><br/>
  107. </p>
  108. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">'To'
  109. part has 2 items:</font></p>
  110. <ul>
  111. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">name
  112. to which mapping is performed,</font></p>
  113. <li><p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">type
  114. of that name (only USER/ROLE are accepted here).</font></p>
  115. </ul>
  116. <p style="margin-bottom: 0cm"><br/>
  117. </p>
  118. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Mappings
  119. are defined using SQL (DDL) commands.</font></p>
  120. <p style="margin-bottom: 0cm"><br/>
  121. </p>
  122. <p style="margin-bottom: 0cm"><br/>
  123. </p>
  124. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Syntax:</font></p>
  125. <p style="margin-bottom: 0cm"><br/>
  126. </p>
  127. <p lang="en-US" style="margin-left: 1.17cm; margin-bottom: 0cm; page-break-before: auto; page-break-after: auto">
  128. <font size="4" style="font-size: 14pt">{CREATE | ALTER | CREATE OR
  129. ALTER} [GLOBAL] MAPPING name</font></p>
  130. <p lang="en-US" style="margin-left: 2.18cm; margin-bottom: 0cm; page-break-before: auto; page-break-after: auto">
  131. <font size="4" style="font-size: 14pt">USING {PLUGIN name [IN
  132. database] | </font>
  133. </p>
  134. <p lang="en-US" style="margin-left: 4.06cm; margin-bottom: 0cm; page-break-before: auto; page-break-after: auto">
  135. <font size="4" style="font-size: 14pt">ANY PLUGIN [IN database |
  136. SERVERWIDE] | </font>
  137. </p>
  138. <p lang="en-US" style="margin-left: 4.06cm; margin-bottom: 0cm"><font size="4" style="font-size: 14pt">MAPPING
  139. [IN database] | </font>
  140. </p>
  141. <p lang="en-US" style="margin-left: 4.06cm; margin-bottom: 0cm"><font size="4" style="font-size: 14pt">'*'
  142. [IN database]}</font></p>
  143. <p lang="en-US" style="margin-left: 2.23cm; margin-bottom: 0cm; page-break-before: auto; page-break-after: auto">
  144. <font size="4" style="font-size: 14pt">FROM {ANY type | type name}</font></p>
  145. <p lang="en-US" style="margin-left: 2.23cm; margin-bottom: 0cm"><font size="4" style="font-size: 14pt">TO
  146. {USER | ROLE} [name]</font></p>
  147. <p style="margin-left: 1.17cm; margin-bottom: 0cm"><br/>
  148. </p>
  149. <p lang="en-US" style="margin-left: 1.17cm; margin-bottom: 0cm"><font size="4" style="font-size: 14pt">DROP
  150. [GLOBAL] MAPPING name</font></p>
  151. <p style="margin-bottom: 0cm"><br/>
  152. </p>
  153. <p style="margin-bottom: 0cm"><br/>
  154. </p>
  155. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Description:</font></p>
  156. <p style="margin-bottom: 0cm"><br/>
  157. </p>
  158. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Each
  159. mapping may be tagged as GLOBAL. Pay attention that global and local
  160. maps with same name may exist and they are different objects!</font></p>
  161. <p style="margin-bottom: 0cm"><br/>
  162. </p>
  163. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Create,
  164. alter and create or alter commands use same set of options. Name of
  165. mapping is used to identify it in former DDL commands. USING clause
  166. has a most complicated set of options. One can provide explicit
  167. plugin name, making it work only for given plugin, or make it use any
  168. plugin (but not a result of previous mappings), or make it work only
  169. with server-wide plugins, or make it work only with previous mapping
  170. results, or let it use any method using asterisk. In almost all cases
  171. (except server-wide authentication which is not related with
  172. databases) one can also provide name of database in which name from
  173. which mapping is performed was “born”. FROM clause must set
  174. required parameter – type of name from which mapping is done. When
  175. mapping names from plugins type is defined by plugin, when previous
  176. mapping results - type can be only user or role. One can provide
  177. explicit name which will be taken into an account by this mapping or
  178. use ANY keyword to work with any name of given type. In TO clause
  179. USER or ROLE (to what mapping is done) must be specified, name is
  180. optional - when it is not provided original name (from what mapping
  181. is done) is used.</font></p>
  182. <p style="margin-bottom: 0cm"><br/>
  183. </p>
  184. <p style="margin-bottom: 0cm"><br/>
  185. </p>
  186. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Samples:</font></p>
  187. <p style="margin-bottom: 0cm"><br/>
  188. </p>
  189. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">All
  190. sample are provided for CREATE command, use of ALTER is exactly the
  191. same, use of DROP is obvious.</font></p>
  192. <p style="margin-bottom: 0cm"><br/>
  193. </p>
  194. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Enable
  195. use of windows trusted authentication in all databases that use
  196. current security database:</font></p>
  197. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  198. GLOBAL MAPPING TRUSTED_AUTH USING PLUGIN WIN_SSPI FROM ANY USER TO
  199. USER;</font></p>
  200. <p style="margin-bottom: 0cm"><br/>
  201. </p>
  202. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Enable
  203. SYSDBA-like access for windows admins in current database:</font></p>
  204. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  205. MAPPING WIN_ADMINS USING PLUGIN WIN_SSPI FROM Predefined_Group
  206. DOMAIN_ANY_RID_ADMINS TO ROLE RDB$ADMIN;</font></p>
  207. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">(there
  208. is no group DOMAIN_ANY_RID_ADMINS in windows, but such name is added
  209. by win_sspi plugin to provide exact backwards compatibility)</font></p>
  210. <p style="margin-bottom: 0cm"><br/>
  211. </p>
  212. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Enable
  213. particular user from other database access current database with
  214. other name:</font></p>
  215. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  216. MAPPING FROM_RT USING PLUGIN SRP IN &quot;rt&quot; FROM USER U1 TO
  217. USER U2;</font></p>
  218. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">(providing
  219. database names/aliases in double quotes is important for operating
  220. systems that have case-sensitive file names)</font></p>
  221. <p style="margin-bottom: 0cm"><br/>
  222. </p>
  223. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Enable
  224. server's SYSDBA (from main security database) access current database
  225. (assuming it has non-default security database):</font></p>
  226. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  227. MAPPING DEF_SYSDBA USING PLUGIN SRP IN &quot;security.db&quot; FROM
  228. USER SYSDBA TO USER;</font></p>
  229. <p style="margin-bottom: 0cm"><br/>
  230. </p>
  231. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Force
  232. people who logged in using legacy authentication plugin have not too
  233. much rights:</font></p>
  234. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  235. MAPPING LEGACY_2_GUEST USING PLUGIN legacy_auth FROM ANY USER TO USER
  236. GUEST;</font></p>
  237. <p style="margin-bottom: 0cm"><br/>
  238. </p>
  239. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Map
  240. windows group to trusted firebird role:</font></p>
  241. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  242. MAPPING WINGROUP1 USING PLUGIN WIN_SSPI FROM GROUP GROUP_NAME TO ROLE
  243. ROLE_NAME;</font></p>
  244. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Here
  245. we expect that some windows users may belong to group GROUP_NAME. If
  246. needed name of the group may be given in long form, i.e.
  247. DOMAIN\GROUP.</font></p>
  248. <p style="margin-bottom: 0cm"><br/>
  249. </p>
  250. <p style="margin-bottom: 0cm"><br/>
  251. </p>
  252. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Notice:</font></p>
  253. <p style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt"><span lang="en-US">-
  254. Global mapping works best if firebird 3 or higher version database is
  255. used as security database. If you plan to use other database as
  256. security one (using for example your own provider) please create in
  257. it table RDB$AUTH_MAPPING with structure repeating one in firebird 3
  258. database, public read access and SYSDBA-only write access.</span></font></p>
  259. <p style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt"><span lang="en-US">-
  260. </span></font><font size="4" style="font-size: 14pt"><span lang="en-US">Mappings
  261. work only with information, coming from authentication plugins or
  262. previously done mapping. Information present in DPB (particular SQL
  263. role name) is not affected by mappings and can not be changed using
  264. them.</span></font></p>
  265. <p style="margin-bottom: 0cm"><br/>
  266. </p>
  267. <p style="margin-bottom: 0cm"><br/>
  268. </p>
  269. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">Tip:</font></p>
  270. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">It’s
  271. relatively easy to accidentally make a database remotely inaccessible
  272. using CREATE MAPPING statement. For example: </font>
  273. </p>
  274. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  275. MAPPING BREAK_DB_1 USING * FROM ANY USER TO ROLE ROLE1;</font></p>
  276. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">CREATE
  277. MAPPING BREAK_DB_2 USING * FROM ANY USER TO ROLE ROLE2;</font></p>
  278. <p lang="en-US" style="margin-bottom: 0cm"><font size="4" style="font-size: 14pt">This
  279. will disallow any user (including SYSDBA) to connect. Luckily
  280. mappings are not processed when database is used in embedded mode,
  281. i.e. in such a case one should attach to database using embedded
  282. access and fix bad mappings.</font></p>
  283. <p style="margin-bottom: 0cm"><br/>
  284. </p>
  285. <p style="margin-bottom: 0cm"><br/>
  286. </p>
  287. </body>
  288. </html>