Package: netbox-kea-dhcp
netbox-kea-dhcpEnable use ofNetBoxas a subnet
configuration source forISC Kea DHCP server.netbox-kea-dhcpis a one-way sync daemon that exports NetBox prefixes, IP
ranges and IP addresses to respectively DHCP subnets, pools
and host reservations. It listens for NetBox webhook events, and each time a
change occured, it queries NetBox for the full changed data and update Kea
throught its API.The program has two modes of operation:Full sync at program startup: overwrite current DHCP subnets with new ones
exported from NetBox.Continuous event-driven sync: listen for NetBox webhook events and update
DHCP configuration accordingly.Key featuresAutomatic sync from Netbox to Kea DHCP with virtualy no delay.Update Kea configuration throught its control agent API: no direct
configuration file overwrites, let’s the control agent manage the runtime
and permanent configuration.Only use open source Kea API commands (no ISC paid subscription required).Submit new exported configuration to Kea check before applying it to runtime
configuration.Query NetBox only for the objects concerned by the event (incremental
sync).Get all NetBox data throught the well maintainedpynetboxlibrary: unique
interface, loose dependency with NetBox internals (only with its API),
reduced code to maintain.Customizable NetBox query filters.Customizable mapping between Netbox object attributes and DHCP settings.RequirementsPython: >= 3.8 (tested on 3.10 but may works down to 3.8).Netbox: validated on API version 3.4.ISC Kea DHCP: validated on version 2.2.0.InstallWith pipnetbox-kea-dhcpis available onPyPiand can be installed
withpip install netbox-kea-dhcp.With pipxA convenient way is to usepipxto install the
application in an isolated environnement.Installpipx(below is for Linux, seepipx homepagefor other systems):python3-mpipinstall--userpipx
python3-mpipxensurepathInstallnetbox-kea-dhcpfrom PyPi in a isolated environnement:pipxinstallnetbox-kea-dhcpRun:netbox-kea-dhcp --helpQuick startSync at startup then listen for netbox events:netbox-kea-dhcp--netbox-urlhttp://netbox-host\--netbox-token0123456789ABCDEF\--kea-urlhttp://kea-api-host--sync-now--listen-vThe default mapping between netbox and Kea is:prefixes are exported to subnets.IP ranges are exported to pools.IP Addresses are exported to reservations. Hardware address is mapped with IP
address custom fielddhcp_reservation_hw_addressif it exists and is non
null, otherwise it is mapped with the MAC address of the assigned object.At least one Netbox webhook needs to be configured for event listening. It has
to notify all actions on DHCP-relevant objects:Content types:IPAM:Prefix,IP Range,IP addresse.DCIM:Interface,Device.Virtualization:Interface,Virtual Machine.Events:Creations,Updates,Deletions.HTTP Request:URL:http://{netbox-connector-host}:{port}/event/{free-text}/HTTP Method:POST.The fieldfree-textis necessary to define several webhooks with same events.
The connector only uses it in logs.More help withnetbox-kea-dhcp --helpand in the configuration file example
underexamples/(or under~/.local/pipx/venvs/netbox-kea-dhcp/lib/python3.10/site-packages/examples/if
app was installed with pipx).Recommended Netbox webhooksSysadmins should set several webhooks with conditions and restricted body
template, in order to filter events and avoid unecessary network and CPU load.Below is a recommended webhook set-up. It assumes that DHCP hardware addresses
are apped with netbox interface MAC addresses. If interfaces are not used
(i.e. hardware addresses are only mapped with a custom field defined in netbox
IP addresses), webhooks on (vm) interfaces, (virtual) devices are not needed.Common to all webhooks:HTTP Request:URL:http://{netbox-connector-host}:{port}/event/{optional-free-text}/HTTP Method:POST.Body template:{"event":"{{ event }}","model":"{{ model }}","data":{"id":{{data["id"]}}}}Webhook 1:Content types:IPAM > Prefix,IPAM > IP Range,IPAM > IP Address,DCIM > Device,DCIM > Interface,Virtualization > Virtual Machine,Virtualization > Interface.Events:UpdatesConditions: noneWebhook 2:Content types:IPAM > IP AddressEvents:Creations,DeletionsConditions:{"and":[{"attr":"status.value","value":"dhcp"}]}Webhook 3:Content types:IPAM > IP RangeEvents:Creations,DeletionsConditions (note: you may have to customize status values to adddhcp):{"and":[{"attr":"status.value","value":"dhcp"}]}Webhook 4:Content types:IPAM > PrefixEvents:Creations,DeletionsConditions: none, or a custom field{"and":[{"attr":"custom_fields.dhcp_enabled","value":true}]}It’s also recommended to set a TLS-enabled reverse proxy in front ofnetbox-kea-dhcp.LimitationsWhen a change occured, the whole DHCP configuration is gotten from Kea,
modified, and sent back. It may put some stress on the DHCP server in case of
frequent changes. This is a limitation of Kea open source commands. A better
update granularity would require an ISC paid subscription.Kea internal subnetidkeys are not preserved, as they induce conflicts
when configuration is pushed back to the DHCP server. This may have drawbacks
in case subnets are frequently added/removed, as some Kea configuration
elements (like leases…) are attached to the identifier. Subnets identifiers
could be preserved by using Kea paid hooks.When Kea URI is of the formfile:///path/to/kea-config, config is written
to the file in an unsafe manner: if the write fails, the file will be
inconsistent. This is because the file feature is intended for tests.