agent.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. <para>
  86. The <command>http-host</command> and <command>http-port</command>
  87. specify an IP address and port to which HTTP service will be bound.
  88. In case of the example configuration provided above, the RESTful
  89. service will be available under the URL of
  90. <command>http://10.20.30.40:8080/</command>. If these parameters
  91. are not specified, the default URL is http://127.0.0.1:8000/
  92. </para>
  93. <para>
  94. It has been mentioned in the <xref linkend="agent-overview"/> that
  95. CA can forward received commands to the specific Kea servers for
  96. processing. For example, <command>config-get</command> is sent to
  97. retrieve configuration of one of the Kea services. When CA receives
  98. this command, including a <command>service</command> parameter
  99. indicating that the client desires to retrieve configuration of
  100. the DHCPv4 server, the CA will forward this command to this server
  101. and then pass the received response back to the client. More about
  102. the <command>service</command> parameter and general structure of
  103. the commands can be found in <xref linkend="ctrl-channel"/>.
  104. </para>
  105. <para>
  106. The CA uses unix domain sockets to forward control commands and receive
  107. responses from other Kea services. The <command>dhcp4</command>,
  108. <command>dhcp6</command> and <command>d2</command> maps
  109. specify the files to which unix domain sockets are bound. In case
  110. of the configuration above, the CA will connect to the DHCPv4 server
  111. via <filename>/path/to/the/unix/socket-v4</filename> to forward the
  112. commands to it. Obviously, the DHCPv4 server must be configured to
  113. listen to connections via this same socket. In other words, the command
  114. socket configuration for the DHCPv4 server and CA (for this server)
  115. must match. Consult the <xref linkend="dhcp4-ctrl-channel"/> and the
  116. <xref linkend="dhcp6-ctrl-channel"/> to learn how the socket
  117. configuration is specified for the DHCPv4 and DHCPv6 services.
  118. </para>
  119. <warning>
  120. <simpara>
  121. We have renamed "dhcp4-server", "dhcp6-server" and "d2-server"
  122. to "dhcp4", "dhcp6" and "d2" respectively after release of Kea 1.2.
  123. If you are migrating from Kea 1.2 you need to tweak your CA config
  124. to use this new naming convention. We have made this incompatible
  125. change to facilitate future use cases where it will be possible to
  126. specify additional values of the "service" parameter to point to
  127. the particular instances of the Kea servers, e.g. "dhcp4/3"
  128. pointing to the 3rd instance of the DHCPv4 server in the
  129. multi-processed configuration. This is not yet supported but the
  130. current renaming lays the ground for it.
  131. </simpara>
  132. </warning>
  133. <para>
  134. Hooks libraries can be attached to the Control Agent just like to
  135. DHCPv4 and DHCPv6 servers. It currently supports one hook point
  136. 'control_command_receive' which makes it possible to delegate
  137. processing of some commands to the hooks library. The
  138. <command>hooks-libraries</command> list contains the list of hooks
  139. libraries that should be loaded by the CA, along with their configuration
  140. information specified with <command>parameters</command>.
  141. </para>
  142. <para>
  143. Please consult <xref linkend="logging"/> for the details how to
  144. configure logging. The CA's root logger's name is
  145. <command>kea-ctrl-agent</command> as given in the example above.
  146. </para>
  147. </section>
  148. <section id="agent-secure-connection">
  149. <title>Secure Connections</title>
  150. <para>
  151. Control Agent doesn't natively support secure HTTP connections like
  152. SSL or TLS. In order to setup secure connection please use one
  153. of the available third party HTTP servers and configure it to run
  154. as a reverse proxy to the Control Agent. Kea has been tested with
  155. two major HTTP server implentations working as a reverse proxy:
  156. Apache2 and nginx. Example configurations including extensive
  157. comments are provided in the <filename>doc/examples/https/</filename>
  158. directory.
  159. </para>
  160. <para>
  161. The reverse proxy forwards HTTP requests received over secure
  162. connection to the Control Agent using (not secured) HTTP. Typically,
  163. the reverse proxy and the Control Agent are running on the same machine,
  164. but it is possible to configure them to run on separate machines as
  165. well. In this case, security depends on the protection of the
  166. communications between the reverse proxy and the Control Agent.
  167. </para>
  168. <para>Apart from providing the encryption layer for the control channel,
  169. a reverse proxy server is also often used for authentication of the
  170. controlling clients. In this case, the client must present a valid
  171. certificate when it connects via reverse proxy. The proxy server
  172. authenticates the client by checking if the presented certificate is
  173. signed by the certificate authority used by the server.</para>
  174. <para>To illustrate this, we provide a sample configuration for the
  175. nginx server running as a reverse proxy to the Kea Control Agent.
  176. The server enables authentication of the clients using
  177. certificates.</para>
  178. <screen>
  179. # The server certificate and key can be generated as follows:
  180. #
  181. # openssl genrsa -des3 -out kea-proxy.key 4096
  182. # openssl req -new -x509 -days 365 -key kea-proxy.key -out kea-proxy.crt
  183. #
  184. # The CA certificate and key can be generated as follows:
  185. #
  186. # openssl genrsa -des3 -out ca.key 4096
  187. # openssl req -new -x509 -days 365 -key ca.key -out ca.crt
  188. #
  189. #
  190. # The client certificate needs to be generated and signed:
  191. #
  192. # openssl genrsa -des3 -out kea-client.key 4096
  193. # openssl req -new -key kea-client.key -out kea-client.csr
  194. # openssl x509 -req -days 365 -in kea-client.csr -CA ca.crt \
  195. # -CAkey ca.key -set_serial 01 -out kea-client.crt
  196. #
  197. # Note that the 'common name' value used when generating the client
  198. # and the server certificates must differ from the value used
  199. # for the CA certificate.
  200. #
  201. # The client certificate must be deployed on the client system.
  202. # In order to test the proxy configuration with 'curl' run
  203. # command similar to the following:
  204. #
  205. # curl -k --key kea-client.key --cert kea-client.crt -X POST \
  206. # -H Content-Type:application/json -d '{ "command": "list-commands" }' \
  207. # https://kea.example.org/kea
  208. #
  209. #
  210. #
  211. # nginx configuration starts here.
  212. events {
  213. }
  214. http {
  215. # HTTPS server
  216. server {
  217. # Use default HTTPS port.
  218. listen 443 ssl;
  219. # Set server name.
  220. server_name kea.example.org;
  221. # Server certificate and key.
  222. ssl_certificate /path/to/kea-proxy.crt;
  223. ssl_certificate_key /path/to/kea-proxy.key;
  224. # Certificate Authority. Client certificate must be signed by the CA.
  225. ssl_client_certificate /path/to/ca.crt;
  226. # Enable verification of the client certificate.
  227. ssl_verify_client on;
  228. # For URLs such as https://kea.example.org/kea, forward the
  229. # requests to http://127.0.0.1:8080.
  230. location /kea {
  231. proxy_pass http://127.0.0.1:8080;
  232. }
  233. }
  234. }
  235. </screen>
  236. <note>
  237. <simpara>Note that the configuration snippet provided above is for testing
  238. purposes only. Consult security policies and best practices of your
  239. organization which apply to this setup.</simpara>
  240. </note>
  241. <para>When you use an HTTP client without TLS support as <command>
  242. kea-shell</command> you can use an HTTP/HTTPS translator such as stunnel
  243. in client mode. A sample configuration is provided in the
  244. <filename>doc/examples/https/shell/</filename> directory</para>
  245. </section>
  246. <section id="agent-limitations">
  247. <title>Control Agent Limitations</title>
  248. <para>
  249. Control Agent is a new component, first released in Kea 1.2. In
  250. this release it comes with one notable limitation:
  251. <itemizedlist>
  252. <listitem>
  253. <simpara>
  254. keactrl hasn't been updated to manage the Control Agent (start, stop
  255. reload). As a result, the CA must be started directly as described in
  256. <xref linkend="agent-launch"/>
  257. </simpara>
  258. </listitem>
  259. </itemizedlist>
  260. </para>
  261. </section>
  262. <section id="agent-launch">
  263. <title>Starting Control Agent</title>
  264. <para>
  265. The CA is started by running its binary and specifying the configuration file
  266. it should use. For example:
  267. <screen>
  268. $ ./kea-ctrl-agent -c /usr/local/etc/kea/kea-ctrl-agent.conf
  269. </screen>
  270. </para>
  271. </section>
  272. <section id="agent-clients">
  273. <title>Connecting to the Control Agent</title>
  274. <para>For an example of tool that can take advantage of the
  275. RESTful API, see <xref linkend="kea-shell"/>.</para>
  276. </section>
  277. </chapter>