agent.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2017;" >
  5. ]>
  6. <chapter id="kea-ctrl-agent">
  7. <title>Kea Control Agent</title>
  8. <section id="agent-overview">
  9. <title>Overview</title>
  10. <para>Kea Control Agent (CA) is a daemon, first included in Kea 1.2, which
  11. exposes a RESTful control interface for managing Kea servers. The daemon
  12. can receive control commands over HTTP and either forward these commands
  13. to the respective Kea servers or handle these commands on its own. The
  14. determination whether the command should be handled by the CA or forwarded
  15. is made by checking the value of the 'service' parameter which may be
  16. included in the command from the controlling client. The details of the
  17. supported commands as well as their structures are provided in
  18. <xref linkend="ctrl-channel"/>.</para>
  19. <para>Hook libraries can be attached to the CA to provide support for
  20. additional commands or custom behavior of existing commands. Such hook
  21. libraries must implement callouts for 'control_command_receive' hook point.
  22. Details about creating new hook libraries and supported hook points can be
  23. found in
  24. <ulink url="https://jenkins.isc.org/job/Kea_doc/doxygen/">Kea Developer's Guide</ulink>.
  25. </para>
  26. <para>
  27. The CA processes received commands according to the following algorithm:
  28. <itemizedlist>
  29. <listitem>
  30. <simpara>
  31. Pass command into any installed hooks (regardless of service value(s)).
  32. If the command is handled by a hook, return the response.
  33. </simpara>
  34. </listitem>
  35. <listitem>
  36. <simpara>
  37. If the service specifies one more or services, the CA will forward the
  38. command to specified services and return the accumulated responses.
  39. </simpara>
  40. </listitem>
  41. <listitem>
  42. <simpara>
  43. If service is not specified or is an empty list, the CA will handle
  44. the command if it supports it.
  45. </simpara>
  46. </listitem>
  47. </itemizedlist>
  48. </para>
  49. </section>
  50. <section id="agent-configuration">
  51. <title>Configuration</title>
  52. <para>The following example demonstrates the basic CA configuration.</para>
  53. <para>
  54. <screen>
  55. {
  56. "Control-agent": {
  57. "http-host": "10.20.30.40",
  58. "http-port": 8080,
  59. "control-sockets": {
  60. "dhcp4": {
  61. "socket-type": "unix",
  62. "socket-name": "/path/to/the/unix/socket-v4"
  63. },
  64. "dhcp6": {
  65. "socket-type": "unix",
  66. "socket-name": "/path/to/the/unix/socket-v4"
  67. }
  68. },
  69. "hooks-libraries": [
  70. {
  71. "library": "/opt/local/control-agent-commands.so",
  72. "parameters": {
  73. "param1": "foo"
  74. }
  75. } ]
  76. },
  77. "Logging": {
  78. "loggers": [ {
  79. "name": "kea-ctrl-agent",
  80. "severity": "INFO"
  81. } ]
  82. }
  83. }</screen>
  84. </para>
  85. <warning>
  86. <simpara>
  87. In the Kea 1.2 release the Control Agent configuration can't be
  88. specified within the same configuration file as DHCPv4, DHCPv6 and D2
  89. configuration. The default configuration file for the CA is installed
  90. in the <filename>etc/kea/kea-ca.conf</filename>. In the Kea 1.2 final
  91. release the CA configuration will be merged into the default
  92. <filename>etc/kea/kea.conf.</filename>
  93. </simpara>
  94. </warning>
  95. <para>
  96. The <command>http-host</command> and <command>http-port</command>
  97. specify an IP address and port to which HTTP service will be bound.
  98. In case of the example configuration provided above, the RESTful
  99. service will be available under the URL of
  100. <command>http://10.20.30.40:8080/</command>. If these parameters
  101. are not specified, the default URL is http://127.0.0.1:8000/
  102. </para>
  103. <para>
  104. It has been mentioned in the <xref linkend="agent-overview"/> that
  105. CA can forward received commands to the specific Kea servers for
  106. processing. For example, <command>config-get</command> is sent to
  107. retrieve configuration of one of the Kea services. When CA receives
  108. this command, including a <command>service</command> parameter
  109. indicating that the client desires to retrieve configuration of
  110. the DHCPv4 server, the CA will forward this command to this server
  111. and then pass the received response back to the client. More about
  112. the <command>service</command> parameter and general structure of
  113. the commands can be found in <xref linkend="ctrl-channel"/>.
  114. </para>
  115. <para>
  116. The CA uses unix domain sockets to forward control commands and receive
  117. responses from other Kea services. The <command>dhcp4</command>,
  118. <command>dhcp6</command> and <command>d2</command> maps
  119. specify the files to which unix domain sockets are bound. In case
  120. of the configuration above, the CA will connect to the DHCPv4 server
  121. via <filename>/path/to/the/unix/socket-v4</filename> to forward the
  122. commands to it. Obviously, the DHCPv4 server must be configured to
  123. listen to connections via this same socket. In other words, the command
  124. socket configuration for the DHCPv4 server and CA (for this server)
  125. must match. Consult the <xref linkend="dhcp4-ctrl-channel"/> and the
  126. <xref linkend="dhcp6-ctrl-channel"/> to learn how the socket
  127. configuration is specified for the DHCPv4 and DHCPv6 services.
  128. </para>
  129. <warning>
  130. <simpara>
  131. We have renamed "dhcp4-server", "dhcp6-server" and "d2-server"
  132. to "dhcp4", "dhcp6" and "d2" respectively after release of Kea 1.2.
  133. If you are migrating from Kea 1.2 you need to tweak your CA config
  134. to use this new naming convention. We have made this incompatible
  135. change to facilitate future use cases where it will be possible to
  136. specify additional values of the "service" parameter to point to
  137. the particular instances of the Kea servers, e.g. "dhcp4/3"
  138. pointing to the 3rd instance of the DHCPv4 server in the
  139. multi-processed configuration. This is not yet supported but the
  140. current renaming lays the ground for it.
  141. </simpara>
  142. </warning>
  143. <para>
  144. Hooks libraries can be attached to the Control Agent just like to
  145. DHCPv4 and DHCPv6 servers. It currently supports one hook point
  146. 'control_command_receive' which makes it possible to delegate
  147. processing of some commands to the hooks library. The
  148. <command>hooks-libraries</command> list contains the list of hooks
  149. libraries that should be loaded by the CA, along with their configuration
  150. information specified with <command>parameters</command>.
  151. </para>
  152. <para>
  153. Please consult <xref linkend="logging"/> for the details how to
  154. configure logging. The CA's root logger's name is
  155. <command>kea-ctrl-agent</command> as given in the example above.
  156. </para>
  157. </section>
  158. <section id="agent-secure-connection">
  159. <title>Secure Connections</title>
  160. <para>
  161. Control Agent doesn't natively support secure HTTP connections like
  162. SSL or TLS. In order to setup secure connection please use one
  163. of the available third party HTTP servers and configure it to run
  164. as a reverse proxy to the Control Agent. Kea has been tested with
  165. two major HTTP server implentations working as a reverse proxy:
  166. Apache2 and nginx. Example configurations including extensive
  167. comments are provided in the <filename>doc/examples/https/</filename>
  168. directory.
  169. </para>
  170. <para>
  171. The reverse proxy forwards HTTP requests received over secure
  172. connection to the Control Agent using (not secured) HTTP. Typically,
  173. the reverse proxy and the Control Agent are running on the same machine,
  174. but it is possible to configure them to run on separate machines as
  175. well. In this case, security depends on the protection of the
  176. communications between the reverse proxy and the Control Agent.
  177. </para>
  178. <para>Apart from providing the encryption layer for the control channel,
  179. a reverse proxy server is also often used for authentication of the
  180. controlling clients. In this case, the client must present a valid
  181. certificate when it connects via reverse proxy. The proxy server
  182. authenticates the client by checking if the presented certifcate is
  183. signed by the certificate authority used by the server.</para>
  184. <para>To illustrate this, we provide a sample configuration for the
  185. nginx server running as a reverse proxy to the Kea Control Agent.
  186. The server enables authentication of the clients using
  187. certificates.</para>
  188. <screen>
  189. # The server certificate and key can be generated as follows:
  190. #
  191. # openssl genrsa -des3 -out kea-proxy.key 4096
  192. # openssl req -new -x509 -days 365 -key kea-proxy.key -out kea-proxy.crt
  193. #
  194. # The CA certificate and key can be generated as follows:
  195. #
  196. # openssl genrsa -des3 -out ca.key 4096
  197. # openssl req -new -x509 -days 365 -key ca.key -out ca.crt
  198. #
  199. #
  200. # The client certificate needs to be generated and signed:
  201. #
  202. # openssl genrsa -des3 -out kea-client.key 4096
  203. # openssl req -new -key kea-client.key -out kea-client.csr
  204. # openssl x509 -req -days 365 -in kea-client.csr -CA ca.crt \
  205. # -CAkey ca.key -set_serial 01 -out kea-client.crt
  206. #
  207. # Note that the 'common name' value used when generating the client
  208. # and the server certificates must differ from the value used
  209. # for the CA certificate.
  210. #
  211. # The client certificate must be deployed on the client system.
  212. # In order to test the proxy configuration with 'curl' run
  213. # command similar to the following:
  214. #
  215. # curl -k --key kea-client.key --cert kea-client.crt -X POST \
  216. # -H Content-Type:application/json -d '{ "command": "list-commands" }' \
  217. # https://kea.example.org/kea
  218. #
  219. #
  220. #
  221. # nginx configuration starts here.
  222. events {
  223. }
  224. http {
  225. # HTTPS server
  226. server {
  227. # Use default HTTPS port.
  228. listen 443 ssl;
  229. # Set server name.
  230. server_name kea.example.org;
  231. # Server certificate and key.
  232. ssl_certificate /path/to/kea-proxy.crt;
  233. ssl_certificate_key /path/to/kea-proxy.key;
  234. # Certificate Authority. Client certificate must be signed by the CA.
  235. ssl_client_certificate /path/to/ca.crt;
  236. # Enable verification of the client certificate.
  237. ssl_verify_client on;
  238. # For URLs such as https://kea.example.org/kea, forward the
  239. # requests to http://127.0.0.1:8080.
  240. location /kea {
  241. proxy_pass http://127.0.0.1:8080;
  242. }
  243. }
  244. }
  245. </screen>
  246. <note>
  247. <simpara>Note that the configuration snippet provided above is for testing
  248. purposes only. Consult security policies and best practices of your
  249. organization which apply to this setup.</simpara>
  250. </note>
  251. </section>
  252. <section id="agent-limitations">
  253. <title>Control Agent Limitations</title>
  254. <para>
  255. Control Agent is a new component, first released in Kea 1.2. In
  256. this release it comes with two notable limitations:
  257. <itemizedlist>
  258. <listitem>
  259. <simpara>
  260. CA configuration must be specified in a separate configuration file
  261. from the configurations of other components. The default confirguation
  262. file for CA is located in <filename>etc/kea/kea-ca.conf</filename>.
  263. </simpara>
  264. </listitem>
  265. <listitem>
  266. <simpara>
  267. keactrl hasn't been updated to manage the Control Agent (start, stop
  268. reload). As a result, the CA must be started directly as described in
  269. <xref linkend="agent-launch"/>
  270. </simpara>
  271. </listitem>
  272. </itemizedlist>
  273. </para>
  274. </section>
  275. <section id="agent-launch">
  276. <title>Starting Control Agent</title>
  277. <para>
  278. The CA is started by running its binary and specifying the configuration file
  279. it should use. For example:
  280. <screen>
  281. $ ./kea-ctrl-agent -c /usr/local/etc/kea/kea-ca.conf
  282. </screen>
  283. </para>
  284. </section>
  285. <section id="agent-clients">
  286. <title>Connecting to the Control Agent</title>
  287. <para>For an example of tool that can take advantage of the
  288. RESTful API, see <xref linkend="kea-shell"/>.</para>
  289. </section>
  290. </chapter>