2019-06-06 18:25:46 +02:00
.. _config-backend:
Kea Configuration Backend
=========================
.. _cb-applicability:
Applicability
-------------
2021-12-14 21:14:41 +02:00
Kea Configuration Backend (CB or config backend) gives Kea servers the ability
2019-06-06 18:25:46 +02:00
to manage and fetch their configuration from one or more databases. In
2021-09-13 16:24:14 +00:00
this documentation, the term "Configuration Backend" may also refer to
2019-06-06 18:25:46 +02:00
the particular Kea module providing support to manage and fetch the
2022-02-22 10:30:35 -05:00
configuration information from the particular database type. For
2022-02-28 15:28:56 +02:00
example, the MySQL Configuration Backend is the logic implemented within the
2021-09-13 16:24:14 +00:00
`` mysql_cb `` hook library, which provides a complete set of functions to
2019-06-06 18:25:46 +02:00
manage and fetch the configuration information from the MySQL database.
2022-02-22 10:30:35 -05:00
The PostgreSQL Configuration Backend is the logic implemented within the
`` pgsql_cb `` hook library, which provides a complete set of functions to
manage and fetch the configuration information from the PostgreSQL database.
From herein, the term "database" is used to refer to either a MySQL or
PostgreSQL database.
2019-06-06 18:25:46 +02:00
In small deployments, e.g. those comprising a single DHCP server
instance with limited and infrequently changing number of subnets, it
may be impractical to use the CB as a configuration repository because
2019-06-17 17:20:36 -04:00
it requires additional third-party software to be installed and
2022-02-22 10:30:35 -05:00
configured - in particular the database server, client and libraries.
Once the number of DHCP servers and/or the number of managed subnets in the
2019-06-06 18:25:46 +02:00
network grows, the usefulness of the CB becomes obvious.
2021-09-13 16:24:14 +00:00
One use case for the CB is a pair of Kea DHCP servers that are configured
2019-06-06 18:25:46 +02:00
to support High Availability as described in
2022-05-11 22:05:43 +00:00
:ref: `hooks-high-availability` . The configurations of both servers
2019-08-12 13:48:21 +02:00
(including the value of the `` server-tag `` parameter)
2021-09-13 16:24:14 +00:00
are almost exactly the same: they may differ by the server identifier
and designation of the server as a primary or standby (or secondary), and/or
by their interfaces' configuration. Typically, the
subnets, shared networks, option definitions, and global parameters are the
2019-06-06 18:25:46 +02:00
same for both servers and can be sourced from a single database instance
to both Kea servers.
Using the database as a single source of configuration for subnets
and/or other configuration information supported by the CB has the
2019-06-17 17:20:36 -04:00
advantage that any modifications to the configuration in the database are
2019-06-06 18:25:46 +02:00
automatically applied to both servers.
2021-09-13 16:24:14 +00:00
Another case when the centralized configuration repository is useful is
2019-06-17 17:20:36 -04:00
in deployments including a large number of DHCP servers, possibly
using a common lease database to provide redundancy. New servers can
be added to the pool frequently to fulfill growing scalability
requirements. Adding a new server does not require replicating the
entire configuration to the new server when a common database is used.
2019-06-06 18:25:46 +02:00
Using the database as a configuration repository for Kea servers also
brings other benefits, such as:
2019-06-17 17:20:36 -04:00
- the ability to use database specific tools to access the configuration
2021-09-13 16:24:14 +00:00
information;
2019-06-06 18:25:46 +02:00
2019-06-17 17:20:36 -04:00
- the ability to create customized statistics based on the information
2021-09-13 16:24:14 +00:00
stored in the database; and
2019-06-06 18:25:46 +02:00
2019-06-17 17:20:36 -04:00
- the ability to backup the configuration information using the database's
built-in replication mechanisms.
2019-06-06 18:25:46 +02:00
.. _cb-limitations:
CB Capabilities and Limitations
-------------------------------
2021-09-13 16:24:14 +00:00
Currently, the Kea CB has the following limitations:
2019-06-06 18:25:46 +02:00
2022-02-22 10:30:35 -05:00
- It is only supported for MySQL and PostgreSQL databases.
2019-06-06 18:25:46 +02:00
2022-02-22 10:30:35 -05:00
- It is only supported for the DHCPv4 and DHCPv6 daemons; the Control Agent,
D2 daemon, and the NETCONF daemon cannot be configured from the database,
2021-09-13 16:24:14 +00:00
- Only certain DHCP configuration parameters can be set in the
2021-07-16 09:08:26 +02:00
database: global parameters, option definitions, global options, client
2021-09-13 16:24:14 +00:00
classes, shared networks, and subnets. Other configuration parameters
2021-07-16 09:08:26 +02:00
must be sourced from a JSON configuration file.
2019-06-06 18:25:46 +02:00
2022-02-22 10:30:35 -05:00
Kea CB stores data in a schema that is public. It is possible to
insert configuration data into the tables manually or automatically
2021-09-13 16:24:14 +00:00
using SQL scripts, but this requires SQL and schema knowledge.
The supported method for managing the data is through the `` cb-cmds `` hook library,
which provides management commands for config backends. It simplifies many
typical operations, such as listing, adding, retrieving, and deleting global
parameters, shared networks, subnets, pools, options, option definitions, and
client classes. In addition, it provides essential business logic that ensures
the logical integrity of the data. See commands starting with `` remote- `` in
Appendix A of this manual for a complete list.
2019-09-20 10:03:24 -04:00
2019-07-01 14:20:05 -04:00
.. note ::
2019-06-06 18:25:46 +02:00
2021-09-13 16:24:14 +00:00
The `` cb_cmds `` hook library is available only to ISC support subscribers.
For more information on subscription options, please complete the form
at https://www.isc.org/contact.
2022-02-22 10:30:35 -05:00
The schema creation scripts can be found at `dhcpdb_create.mysql <https://gitlab.isc.org/isc-projects/kea/blob/master/src/share/database/scripts/mysql/dhcpdb_create.mysql> `__ and
;
`dhcpdb_create.pgsql <https://gitlab.isc.org/isc-projects/kea/blob/master/src/share/database/scripts/pgsql/dhcpdb_create.pgsql> `__ and
;
2021-09-13 16:24:14 +00:00
other related design documents are stored in our GitLab: `CB Design <https://gitlab.isc.org/isc-projects/kea/wikis/designs/configuration-in-db-design> `__ and
`Client Classes in CB Design <https://gitlab.isc.org/isc-projects/kea/wikis/designs/client-classes-in-cb> `__ .
We strongly recommend against duplication of configuration information
in both the file and the database. For example, when specifying subnets
for the DHCP server, please store them in either the configuration backend
or in the configuration file, not both. Storing some subnets in the database
and others in the file may put users at risk of potential configuration
conflicts. Note that the configuration instructions from the database take
precedence over instructions from the file, so parts of the configuration
specified in the file may be overridden if contradicted by information in
the database.
Although it is not recommended, it is possible to specify certain parameter
types both in a configuration file and the database. For example, a subnet
can be specified in the configuration file and another subnet in the database;
in this case, the server will use both subnets. DHCP client classes, however,
must not be specified in both the configuration file and the database, even if
they do not overlap. If any client classes are specified in the database
for a particular DHCP server, this server will use these classes and ignore
all classes present in its configuration file. This behavior was introduced
to ensure that the server receives a consistent set of client classes
specified in an expected order with all inter-class dependencies fulfilled.
It is impossible to guarantee consistency when client classes are specified
in two independent configuration sources.
2019-06-06 18:25:46 +02:00
2021-07-22 20:30:03 +02:00
.. note ::
2021-09-13 16:24:14 +00:00
It is recommended that the `` subnet_cmds `` hook library not be used to
manage subnets when the configuration backend is used as a source
of information about the subnets. The `` subnet_cmds `` hook library
2019-06-17 17:20:36 -04:00
modifies the local subnets configuration in the server's memory,
2021-09-13 16:24:14 +00:00
not in the database. Use the `` cb_cmds `` hook library to manage the
2019-06-06 18:25:46 +02:00
subnets information in the database instead.
2021-09-22 07:59:51 +02:00
.. note ::
Using custom option formats requires creating definitions for these options.
Suppose a user wishes to set option data in the configuration backend. In
that case, we recommend specifying the definition for that option in the
configuration backend as well. It is essential when multiple servers are
managed via the configuration backend, and may differ in their
configurations. The option data parser can search for an option definition
appropriate for the server for which the option data is specified.
In a single-server deployment, or when all servers share the same
configuration file information, it is possible to specify option
definitions in the configuration files and option data in the configuration
backend. The server receiving a command to set option data must have a
valid definition in its configuration file, even when it sets option data
for another server.
It is not supported to specify option definitions in the configuration
backend and the corresponding option data in the server configuration files.
2019-06-06 18:25:46 +02:00
CB Components
-------------
2022-02-22 10:30:35 -05:00
To use a MySQL configuration backend you must compile the `` mysql_cb `` open
2022-02-28 15:28:56 +02:00
source hook library and configure the DHCP servers to load it. It is compiled when
the `` --with-mysql `` configuration switch is used during the Kea build. The MySQL
C client libraries must be installed, as explained in :ref: `dhcp-install-configure` .
2022-02-22 10:30:35 -05:00
To use a PostgreSQL configuration backend you must compile the `` pgsql_cb `` open
2022-02-28 15:28:56 +02:00
source hook library and configure the DHCP servers to load it. It is compiled when
2022-02-22 10:30:35 -05:00
the `` --with-pgsql `` configuration switch is used during the Kea build. The PostgreSQL
C client libraries must be installed, as explained in :ref: `dhcp-install-configure` .
2019-06-06 18:25:46 +02:00
2019-07-01 14:20:05 -04:00
.. note ::
2019-06-06 18:25:46 +02:00
2022-02-22 10:30:35 -05:00
An existing database schema must be upgraded to the latest schema
2019-06-17 17:20:36 -04:00
required by the particular Kea version using the `` kea-admin `` tool,
2019-07-16 12:36:06 -04:00
as described in :ref: `kea-admin` .
2019-06-06 18:25:46 +02:00
2021-09-13 16:24:14 +00:00
The `` cb_cmds `` premium hook library, which is available to ISC's paid support
2019-06-17 17:20:36 -04:00
customers, provides a complete set of commands to manage the
2019-06-06 18:25:46 +02:00
servers' configuration information within the database. This library can
2022-02-28 15:28:56 +02:00
be attached to both DHCPv4 and DHCPv6 server instances. While it is
2019-06-06 18:25:46 +02:00
possible to manage the configuration information without the `` cb_cmds ``
2021-09-13 16:24:14 +00:00
hook library with commonly available tools, such as MySQL Workbench or
2022-02-22 10:30:35 -05:00
the command-line MySQL client, or by directly working with the database;
these avenues are neither recommended nor supported.
2019-06-06 18:25:46 +02:00
2022-05-11 22:05:43 +00:00
Refer to :ref: `hooks-cb-cmds` for the details regarding the
2021-09-13 16:24:14 +00:00
`` cb_cmds `` hook library.
2019-06-06 18:25:46 +02:00
2019-06-17 17:20:36 -04:00
The DHCPv4 and DHCPv6 server-specific configurations of the CB, as well as
the list of supported configuration parameters, can be found in
2021-09-13 16:24:14 +00:00
:ref: `dhcp4-cb` and :ref: `dhcp6-cb` , respectively.
2019-07-19 16:26:08 +02:00
.. _cb-sharing:
Configuration Sharing and Server Tags
-------------------------------------
2021-09-13 16:24:14 +00:00
The configuration database is designed to store configuration information
2019-07-19 16:26:08 +02:00
for multiple Kea servers. Depending on the use case, the entire configuration
2021-09-13 16:24:14 +00:00
may be shared by all servers; parts of the configuration may be shared by
2019-07-19 16:26:08 +02:00
multiple servers and the rest of the configuration may be different for these
2021-09-13 16:24:14 +00:00
servers; or each server may have its own non-shared configuration.
2019-07-19 16:26:08 +02:00
The configuration elements in the database are associated with the servers
2021-09-13 16:24:14 +00:00
by "server tags." The server tag is an arbitrary string holding the name
2019-07-19 16:26:08 +02:00
of the Kea server instance. The tags of the DHCPv4 and DHCPv6 servers are
independent in the database, i.e. the same server tag can be created for
2021-09-13 16:24:14 +00:00
both the DHCPv4 and the DHCPv6 server. The value is configured
2021-06-08 09:47:22 +00:00
using the `` server-tag `` parameter in the Dhcp4 or Dhcp6 scope. The current
2021-09-13 16:24:14 +00:00
server tag can be checked with the `` server-tag-get `` command.
2019-07-19 16:26:08 +02:00
The server definition, which consists of the server tag and the server
description, must be stored in the configuration database prior to creating
the dedicated configuration for that server. In cases when all servers use
2021-09-13 16:24:14 +00:00
the same configuration, e.g. a pair of servers running as High Availability
2019-07-19 16:26:08 +02:00
peers, there is no need to configure the server tags for these
2021-09-13 19:55:32 +00:00
servers in the database.
Commands which contain the logical server `all` are applied to all servers
2021-09-13 16:24:14 +00:00
connecting to the database. The `all` server cannot be
deleted or modified, and it is not returned among other servers
2021-09-13 19:55:32 +00:00
as a result of the `` remote-server[46]-get-all `` command.
2019-07-19 16:26:08 +02:00
2021-09-13 19:55:32 +00:00
In most cases, there are no server tags defined in the configuration
database; all connecting servers get the same configuration
regardless of the server tag they use. The server tag that a
2019-07-19 16:26:08 +02:00
particular Kea instance presents to the database to fetch its configuration
is specified in the Kea configuration file, using the
`config-control` map (please refer to the :ref: `dhcp4-cb-json` and
2021-09-13 19:55:32 +00:00
:ref: `dhcp6-cb-json` for details). All Kea instances presenting the same
server tag to the configuration database
are given the same configuration.
2019-07-19 16:26:08 +02:00
2021-09-13 19:55:32 +00:00
It is the administrator's choice whether
multiple Kea instances use the same server tag or each Kea instance uses
a different server tag. There is no requirement that the instances
2019-07-19 16:26:08 +02:00
running on the same physical or virtual machine use the same server tag. It is
even possible to configure the Kea server without assigning it a server tag.
2021-09-13 19:55:32 +00:00
In such a case the server will be given the configuration specified for `all`
2019-07-19 16:26:08 +02:00
servers.
2021-09-13 19:55:32 +00:00
To differentiate between different Kea server configurations, a
list of the server tags used by the servers must be stored in the
2019-07-19 16:26:08 +02:00
database. For the DHCPv4 and DHCPv6 servers, it can be done using the
commands described in :ref: `command-remote-server4-set` and
2021-09-13 19:55:32 +00:00
:ref: `command-remote-server6-set` . The
server tags can then be used to associate the configuration information with
2019-07-19 16:26:08 +02:00
the servers. However, it is important to note that some DHCP
2021-09-13 19:55:32 +00:00
configuration elements may be associated with multiple server tags (known
as "shareable" elements), while
other configuration elements may be associated with only one
server tag ("non-shareable" elements). The :ref: `dhcp4-cb`
and :ref: `dhcp6-cb` sections list the DHCP-specific shareable and
non-shareable configuration elements; however, in this section we
briefly explain the differences between them.
A shareable configuration element is one which has some unique
property identifying it, and which may appear only once in
the database. An example of a shareable DHCP element is a subnet
instance: the subnet is a part of the network topology and we assume
that any particular subnet may have only one definition within this
network. Each subnet has two unique identifiers: the subnet identifier and the
2019-07-19 16:26:08 +02:00
subnet prefix. The subnet identifier is used in Kea to uniquely
2021-09-13 19:55:32 +00:00
identify the subnet within the network and to connect it with other configuration elements,
e.g. in host reservations. Some commands provided by the
`` cb_cmds `` hook library allow the subnet
information to be accessed by either subnet identifier or prefix, and explicitly prohibit
using the server tag to access the subnet. This is because, in
general, the subnet definition is associated with multiple servers
2020-11-12 12:38:08 +00:00
rather than a single server. In fact, it may even be associated
2019-07-19 16:26:08 +02:00
with no servers (unassigned). Still, the unassigned subnet has an
identifier and prefix which can be used to access the subnet.
A shareable configuration element may be associated with multiple
2021-09-13 19:55:32 +00:00
servers, one server, or no servers. Deletion of the server which is
2019-07-19 16:26:08 +02:00
associated with the shareable element does not cause the deletion of
the shareable element. It merely deletes the association of the
deleted server with the element.
2021-09-13 19:55:32 +00:00
Unlike a shareable element, a non-shareable element must not be
2019-07-19 16:26:08 +02:00
explicitly associated with more than one server and must not exist
2021-09-13 19:55:32 +00:00
after the server is deleted (must not remain unassigned). A
2019-07-19 16:26:08 +02:00
non-shareable element only exists within the context of the server.
2021-09-13 19:55:32 +00:00
An example of a non-shareable element in DHCP is a global
2019-07-19 16:26:08 +02:00
parameter, e.g. `renew-timer` . The renew timer
2021-09-13 19:55:32 +00:00
is the value to be used by a particular server and only this
2019-07-19 16:26:08 +02:00
server. Other servers may have their respective renew timers
2021-09-13 19:55:32 +00:00
set to the same or different values. The renew timer
parameter has no unique identifier by which it could be
accessed, modified, or otherwise used. Global parameters like
2019-07-19 16:26:08 +02:00
the renew timer can be accessed by the parameter name and the
tag of the server for which they are configured. For example:
2021-09-13 19:55:32 +00:00
the commands described in :ref: `command-remote-global-parameter4-get` allow
the value of the global parameter to be fetched by the parameter name and
2019-07-19 16:26:08 +02:00
the server name. Getting the global parameter only by its name (without
2021-09-13 19:55:32 +00:00
specifying the server tag) is not possible, because there may be many
global parameters with a given name in the database.
2019-07-19 16:26:08 +02:00
When the server associated with a non-shareable configuration element
is deleted, the configuration element is automatically deleted from
the database along with the server because the non-shareable element
2021-09-13 19:55:32 +00:00
must be always assigned to a server (or the logical server `all` ).
The terms "shareable" and "non-shareable" only apply to associations
with user-defined servers; all configuration elements associated with
the logical server `all` are by definition shareable. For example: the
`renew-timer` associated with `all` servers is used
by all servers connecting to the database which do not have their specific
renew timers defined. In a special case, when none of the configuration
elements are associated with user-defined servers, the entire
2019-07-19 16:26:08 +02:00
configuration in the database is shareable because all its pieces
2021-09-13 19:55:32 +00:00
belong to `all` servers.
2019-07-19 16:26:08 +02:00
.. note ::
2021-07-16 09:08:26 +02:00
2021-09-13 19:55:32 +00:00
Be very careful when associating configuration elements with
different server tags. The configuration backend does not protect
2019-07-19 16:26:08 +02:00
against some possible misconfigurations that may arise from the
2021-09-13 16:24:14 +00:00
wrong server tags' assignments. For example: if a shared
network is assigned to one server and the subnets belonging to this shared network
2019-07-19 16:26:08 +02:00
to another server, the servers will fail upon trying to fetch and
use this configuration. The server fetching the subnets will be
2021-09-13 19:55:32 +00:00
aware that the subnets are associated with the shared network, but
the shared network will not be found by this server since it doesn't
2020-11-12 12:38:08 +00:00
belong to it. In such a case, both the shared network and the subnets
2019-07-19 16:26:08 +02:00
should be assigned to the same set of servers.