auroraresearchlab / netbox-dns

Netbox Dns is a netbox plugin for managing zone, nameserver and record inventory.
MIT License
207 stars 19 forks source link

Validate Names for NameServer, Zone and Record objects (and support IDNs) #269

Closed peteeckel closed 1 year ago

peteeckel commented 1 year ago

fixes #268

This PR provides validation of RR names according to the rules in RFC1035, Section 2.3.1, RFC2181, Section 11 and RFC5891, Section 4.2.3. Formerly, NetBox DNS accepted virtually anything as a record name, which could lead to zone files not being loadable by DNS servers such as BIND.

Note that host names in record values are not validated at the moment. Although this is desirable and may come as a further enhancement, it is a major effort as all RR values need to be parsed for validation and there are a large number of different RR types, many of them with alternative value formats that may or may not contain names that might need validation.

During implementation it became clear that validating names also requires correct handling of IDNs (International Domain Names) which can include Unicode characters. These characters need to be converted to host names in Punycode format, which satisfies the requirements in above RFCs and do not contain anything except alphanumerical characters, hyphens, optionally underscores and dots as label separators.

Therefore NetBox DNS was extended to convert names containing any Unicode characters to Punycode, which is used for storage in the database so the data can directly be processed by name servers. In the GUI, both the Punycode and the Unicode representation are displayed where applicable, and data entry can be done in both formats as required. In pre-populated edit forms, the Unicode representation is used for initial values, page titles etc.

There are three new plugin configuration variables affecting validation:

peteeckel commented 1 year ago

I still found some room for performance improvement and code cleanup. Won't take too long.