database_backends.dox 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. /**
  15. @page dhcpDatabaseBackends DHCP Database Back-Ends
  16. All DHCP lease data is stored in some form of database, the interface
  17. to this being through the Lease Manager.
  18. All backend classes such as isc::dhcp::MySqlLeaseMgr are derived from
  19. the abstract isc::dhcp::LeaseMgr class. This provides methods to
  20. create, retrieve, modify and delete leases in the database.
  21. There are currently three available Lease Managers, Memfile, MySQL and
  22. PostgreSQL:
  23. - Memfile is an in-memory lease database which can be configured to persist
  24. its content to disk in a flat-file. Support for the Memfile database
  25. backend is built into Kea DHCP.
  26. - The MySQL lease manager uses the freely available MySQL as its backend
  27. database. This is not included in Kea DHCP by default:
  28. the \--with-dhcp-mysql switch must be supplied to "configure" for support
  29. to be compiled into the software.
  30. - The PostgreSQL lease manager uses the freely available PostgreSQL as its
  31. backend database. This is not included in Kea DHCP by default:
  32. the \--with-dhcp-pgsql switch must be supplied to "configure" for
  33. support to be compiled into the software.
  34. @section dhcpdb-instantiation Instantiation of Lease Managers
  35. A lease manager is instantiated through the LeaseMgrFactory class. This
  36. has three methods:
  37. - isc::dhcp::LeaseMgrFactory::create - Creates a singleton Lease
  38. Manager of the appropriate type.
  39. - isc::dhcp::LeaseMgrFactory::instance - Returns a reference to the
  40. the instance of the Lease Manager.
  41. - isc::dhcp::LeaseMgrFactory::destroy - Destroys the singleton lease manager.
  42. The selection of the Lease Manager (and thus the backend database) is
  43. controlled by the connection string passed to
  44. isc::dhcp::LeaseMgrFactory::create. This is a set of "keyword=value" pairs
  45. (no embedded spaces), each pair separated by a space from the others, e.g.
  46. \code
  47. type=mysql user=keatest password=keatest name=keatest host=localhost
  48. \endcode
  49. The following keywords are used for all backends:
  50. - <b>type</b> - specifies the type of database backend. The following values
  51. for the type keyword are supported:
  52. - <B>memfile</b> - In-memory database. Nothing is written to any
  53. external storage, so this should not be used in production.
  54. - <b>mysql</b> - Use MySQL as the database
  55. The following sections list the database-specific keywords:
  56. @subsection dhcpdb-keywords-mysql MySQL connection string keywords
  57. - <b>host</b> - host on which the selected database is running. If not
  58. supplied, "localhost" is assumed.
  59. - <b>name</b> - name of the MySQL database to access. There is no default -
  60. this must always be supplied.
  61. - <b>password</b> - password for the selected user ID (see below). If not
  62. specified, no password is used.
  63. - <b>user</b> - database user ID under which the database is accessed. If not
  64. specified, no user ID is used - the database is assumed to be open.
  65. @subsection dhcpdb-keywords-pgsql PostgreSQL connection string keywords
  66. - <b>host</b> - host on which the selected database is running. If not
  67. supplied, "localhost" is assumed.
  68. - <b>name</b> - name of the PostgreSQL database to access. There is no
  69. default - this must always be supplied.
  70. - <b>password</b> - password for the selected user ID (see below). If not
  71. specified, no password is used.
  72. - <b>user</b> - database user ID under which the database is accessed. If not
  73. specified, no user ID is used - the database is assumed to be open.
  74. @section dhcp-backend-unittest Running Unit Tests
  75. With the use of databases requiring separate authorisation, there are
  76. certain database-specific pre-requisites for successfully running the unit
  77. tests. These are listed in the following sections.
  78. @subsection dhcp-mysql-unittest MySQL Unit Tests
  79. A database called <i>keatest</i> must be created. A database user, also called
  80. <i>keatest</i> (and with a password <i>keatest</i>) must also be created and
  81. be given full privileges in that database. The unit tests create the schema
  82. in the database before each test and delete it afterwards.
  83. In detail, the steps to create the database and user are:
  84. -# Log into MySQL as root:
  85. @verbatim
  86. % mysql -u root -p
  87. Enter password:
  88. :
  89. mysql>@endverbatim\n
  90. -# Create the test database. This must be called "keatest":
  91. @verbatim
  92. mysql> CREATE DATABASE keatest;
  93. mysql>@endverbatim\n
  94. -# Create the user under which the test client will connect to the database
  95. (the apostrophes around the words <i>keatest</i> and <i>localhost</i> are
  96. required):
  97. @verbatim
  98. mysql> CREATE USER 'keatest'@'localhost' IDENTIFIED BY 'keatest';
  99. mysql>@endverbatim\n
  100. -# Grant the created user permissions to access the <i>keatest</i> database
  101. (again, the apostrophes around the words <i>keatest</i> and <i>localhost</i>
  102. are required):
  103. @verbatim
  104. mysql> GRANT ALL ON keatest.* TO 'keatest'@'localhost';
  105. mysql>@endverbatim\n
  106. -# Exit MySQL:
  107. @verbatim
  108. mysql> quit
  109. Bye
  110. %@endverbatim
  111. The unit tests are run automatically when "make check" is executed (providing
  112. that BIND 10 has been build with the \--with-dhcp-mysql switch (see the installation
  113. section in the <a href="http://bind10.isc.org/docs/bind10-guide.html">BIND 10 Guide</a>).
  114. @subsection dhcp-pgsql-unittest PostgreSQL Unit Tests
  115. Conceptually, the steps required to run PostgreSQL unit-tests are the same as
  116. in MySQL. First, a database called <i>keatest</i> must be created. A database
  117. user, also called <i>keatest</i> (that will be allowed to log in using password
  118. <i>keatest</i>) must be created and given full privileges in that database. The
  119. unit tests create the schema in the database before each test and delete it
  120. afterwards.
  121. PostgreSQL set up differs from system to system. Please consult your OS-specific
  122. PostgreSQL documentation. The remainder of that section uses Ubuntu 13.10 x64 as
  123. example. On Ubuntu, after installing PostgreSQL (with <tt>sudo apt-get install
  124. postgresql</tt>), it is installed as user <i>postgres</i>. To create new databases
  125. or add new users, initial commands must be issued as user postgres:
  126. @verbatim
  127. $ sudo -u postgres psql postgres
  128. [sudo] password for thomson:
  129. psql (9.1.12)
  130. Type "help" for help.
  131. postgres=# CREATE USER keatest WITH PASSWORD 'keatest';
  132. CREATE ROLE
  133. postgres=# CREATE DATABASE keatest;
  134. CREATE DATABASE
  135. postgres=# GRANT ALL PRIVILEGES ON DATABASE keatest TO keatest;
  136. GRANT
  137. postgres=# \q
  138. @endverbatim
  139. Now we are back to our regular, unprivileged user. Try to log into the newly
  140. created database using keatest credentials:
  141. @verbatim
  142. $ psql -d keatest -U keatest
  143. Password for user keatest:
  144. psql (9.1.12)
  145. Type "help" for help.
  146. keatest=>
  147. @endverbatim
  148. If instead of seeing keatest=> prompt, your login will be refused with error
  149. code about failed peer or indent authentication, it means that PostgreSQL is
  150. configured to check unix username and reject login attepts if PostgreSQL names
  151. are different. To alter that, PostgreSQL configuration must be changed.
  152. Alternatively, you may set up your environment, so the tests would be run from
  153. unix account keatest. <tt>/etc/postgresql/9.1/main/pg_hba.conf</tt> config file
  154. had to betweaked. It may be in a different location in your system. The following
  155. lines:
  156. @verbatim
  157. local all all peer
  158. host all all 127.0.0.1/32 md5
  159. host all all ::1/128 md5
  160. @endverbatim
  161. were replaced with:
  162. @verbatim
  163. local all all password
  164. host all all 127.0.0.1/32 password
  165. host all all ::1/128 password
  166. @endverbatim
  167. Please consult your PostgreSQL user manual before applying those changes as
  168. those changes may expose your other databases that you run on the same system.
  169. In general case, it is a poor idea to run anything of value on a system
  170. that runs tests. Use caution!
  171. The unit tests are run automatically when "make check" is executed (providing
  172. that BIND 10 has been build with the \--with-dhcp-pgsql switch (see the installation
  173. section in the <a href="http://bind10.isc.org/docs/bind10-guide.html">BIND10 Guide</a>).
  174. */