Skip to content

Conversation

@fmlshai
Copy link
Contributor

@fmlshai fmlshai commented Mar 23, 2022

Fixes: #8785

Added * to the DNSValidator regex to allow wildcard domains like *.example.com

Added * to the DNSValidator regex to allow wildcard domains like *.example.com
DNSValidator = RegexValidator(
regex='^[0-9A-Za-z._-]+$',
message='Only alphanumeric characters, hyphens, periods, and underscores are allowed in DNS names',
regex='^[0-9A-Za-z*._-]+$',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would allow any number of asterisks, anywhere within the string, which would not be valid. A wildcard must be defined as a single asterisk only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you're right. Didn't think about that case. I'll try to figure it out.

Copy link
Contributor

@hSaria hSaria Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures a wildcard can only be present at the beginning of a record '^(\\*\\.)?[0-9A-Za-z._-]+$'. With a raw string, it would be r'^(\*\.)?[0-9A-Za-z._-]+$'.

Also, it might be more accurate to change the RegEx to r'^(\*\.)?[0-9A-Za-z_-]+(\.[0-9A-Za-z_-]+)*$' to prevent a record with multiple consecutive ., like www..example..com.

Edit: Wildcards can be present in any level, so this works better. Also, a record can end in a ..

r'^([0-9A-Za-z_-]+|\*)(\.([0-9A-Za-z_-]+|\*))*\.?$'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcards can be present in any level

I'm pretty sure this is wrong. Wildcards must be leftmost in the DNS string.

https://datatracker.ietf.org/doc/html/rfc4592#section-2.1.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. Back to r'^([0-9A-Za-z_-]+|\*)(\.[0-9A-Za-z_-]+)*\.?$'

Copy link
Contributor

@kkthxbye-code kkthxbye-code Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean that wildcards can be at any level? The bind maintainer seems to think not https://www.mail-archive.com/[email protected]/msg23505.html - also wikipedia seems to think wildcards in the middle are invalid. Do you have a production example of a DNS server that respects wildcard domains in the middle?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bind9 accepts me adding the following record:
netbox-8945.*.demo.central-intelligence.agency. 300 IN TXT "https://github.com/netbox-community/netbox/pull/8945"
it does log the following warning:

warning: ownername 'netbox-8945.*.demo.central-intelligence.agency' contains a non-terminal wildcard

See also https://kb.isc.org/docs/what-is-an-empty-non-terminal, which suggests to avoid such records, but they do seem to be valid.

To note is however, that it seems that the use of an asterisk in these records does not turn them into wildcard records.
They seem to be used as literal asterisks in these cases.
That is also what the email you linked mentions.
It does not explicitly mention asterisks, but it mentions that only leading asterisk labels are treated as wildcard, without going into detail on asterisk labels in other places.

Try this:
dig txt "netbox-8945.*.demo.central-intelligence.agency"

https://datatracker.ietf.org/doc/html/rfc4592#section-2.2.1 specifically lists this type of record as non-wildcard:

   To illustrate what is meant by existence consider this complete zone:

      $ORIGIN example.
      example.                 3600 IN  SOA   <SOA RDATA>
      example.                 3600     NS    ns.example.com.
      example.                 3600     NS    ns.example.net.
      *.example.               3600     TXT   "this is a wildcard"
      *.example.               3600     MX    10 host1.example.
      sub.*.example.           3600     TXT   "this is not a wildcard"
      host1.example.           3600     A     192.0.2.1
      _ssh._tcp.host1.example. 3600     SRV   <SRV RDATA>
      _ssh._tcp.host2.example. 3600     SRV   <SRV RDATA>
      subdel.example.          3600     NS    ns.example.com.
      subdel.example.          3600     NS    ns.example.net.

For an A record, however, I can't create this with nsupdate:

nsupdate commands queued:
server localhost
zone central-intelligence.agency
update add    netbox-8945.*.demo.central-intelligence.agency. 300 IN A 127.0.0.1
send
answer

[S]end, [e]dit, send and edit [a]gain, [q]uit: [s]

check-names failed: bad owner 'netbox-8945.*.demo.central-intelligence.agency'
syntax error
nsupdate returned 1, press enter to edit again

So in the end it seems that this is at least not usable for IPs, therefore likely not useful in netbox.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spending the time doing such thorough digging. I guess we'll let Jeremy decide on the final outcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the FR does not specify a use case beyond e.g. *.example.com, let's keep it simple and just allow terminating wildcards.

@fmlshai are you still interested in making this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Thanks for all the effort you guys put into this. I'll update the PR as soon as I find the time for it.

Updated DNSValidator regex
@jeremystretch jeremystretch merged commit 0b44a59 into netbox-community:develop Mar 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using wildcards in DNS names

5 participants