Skip to content

feat(client): support SOA DNS query type - #1903

Open
sarankumar1325 wants to merge 2 commits into
TwiN:masterfrom
sarankumar1325:feat/dns-soa-query
Open

sarankumar1325 wants to merge 2 commits into
TwiN:masterfrom
sarankumar1325:feat/dns-soa-query

Conversation

@sarankumar1325

Copy link
Copy Markdown

Summary

Fixes #1902

query-type: SOA passes config validation (it is in dns.StringToType), but QueryDNS has no case for it, so the body is always query type is not supported yet.

This adds a dns.TypeSOA case that renders the record in zone file order:

<mname> <rname> <serial> <refresh> <retry> <expire> <minimum>

e.g. ns1.example.com. hostmaster.example.com. 2026103101 7200 3600 1209600 300, so it works with pat(...) conditions such as [BODY] == pat(ns1.example.com.*). The README DNS section now mentions the format.

Tests

  • New TestQueryDNS_SOA runs a local miekg/dns UDP server on 127.0.0.1 and checks the body (fails on master with the "not supported yet" body, passes with this change). It doesn't need internet access, unlike TestQueryDNS.
  • go vet ./client/, go test ./config/... (only the network-dependent domain-expiration/ICMP tests fail in my sandbox, same as on master).

I used an AI assistant to help with this change and reviewed it myself.

SOA was accepted by the config validation but QueryDNS fell through to
the default case and returned "query type is not supported yet" as the
body. Render the SOA record in zone file order so it can be used in
[BODY] conditions.

Fixes TwiN#1902
@github-actions github-actions Bot added the feature New feature or request label Oct 30, 2026

@wahajahmed010 wahajahmed010 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated connectivity probe — retracted, apologies for the noise. (no substantive review)

@wahajahmed010 wahajahmed010 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed against master (client/client.go, config/endpoint/dns/dns.go) and miekg/dns v1.1.72. The implementation itself is correct: the field order <mname> <rname> <serial> <refresh> <retry> <expire> <minimum> matches RFC 1035's SOA zone-file layout, dns.StringToType does contain SOA so query-type: SOA passes Config.ValidateAndSetDefault(), and dns.Name implements fmt.Stringer with a value receiver, so %s on soa.Ns/soa.Mbox renders the names as expected. The local UDP-server test is a good addition, since it avoids the network dependency that makes the existing TestQueryDNS unsuitable for CI.

A few things worth considering before this lands.

1. The body is only populated for the zone apex, but the README does not say so

QueryDNS iterates over r.Answer only. When a SOA query is sent for a name that is not the zone apex, the authoritative server returns no answer records and puts the SOA in the AUTHORITY section instead, so body stays empty rather than containing the record. The [BODY] placeholder then resolves to an empty string and the endpoint goes red with no explanation of why.

This is exactly the canary use case from #1902, so it is worth stating explicitly in the README that a SOA query must target the zone apex (for example query-name: example.com for the example.com zone) for [BODY] to be populated. If it is cheap to do, reading r.Ns as a fallback would also make sub-domain SOA queries usable.

2. The serial is the field that actually changes, and it is hard to isolate in a condition

The purpose of a SOA canary, as described in #1902, is to notice when the zone serial changes. With the current format the serial is the third whitespace-separated token, so a condition can only match it with a wildcard prefix, for example [BODY] == pat(*. 2026103101 *). That works, but it also matches on a different record's mname/rname in the same position.

Two options that would make this less awkward, if you want to keep the zone-file format as the primary body:

  • Document the pat(...) form in the README alongside the existing DNS example, so users know a wildcard prefix is required.
  • Expose the serial separately, for example through an additional placeholder, so a condition can target it directly.

3. The default branch still produces a non-explanatory failure for the other accepted types

This PR renders SOA, but the runtime still supports only 9 of the 87 types that dns.StringToType accepts, and the fallback body is the bare string query type is not supported yet. A user who configures query-type: CAA or TLSA gets an endpoint failure whose message does not say which type was unsupported, even though the config validator explicitly accepted it.

Naming the type in the fallback, for example fmt.Sprintf("query type %s is not supported yet", dns.TypeToString[rr.Header().Rrtype]), is a one-line change that makes those failures self-explanatory, and optionally rejecting unsupported types at startup with a dedicated error would surface the problem before the first check instead of during it.

I would treat that as a separate follow-up rather than a blocker for this PR, since this one is scoped to making SOA work. But since the same issue covers both, it may be worth keeping them together.

Minor

The case dns.TypeSOA block is placed between dns.TypePTR and dns.TypeSRV. The existing cases are not alphabetical, so this is only a style note, but keeping the type cases in one consistent order would make the list easier to scan as it grows.

The change itself is well tested, does not affect existing query types, and introduces no dependency or configuration changes.

Non-apex SOA queries return no Answer and put the SOA in the Authority
section. Fall back to r.Ns so [BODY] is populated, document apex vs
non-apex behavior and serial pat(...) matching, and cover it with a
local UDP-server test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DNS query type SOA

2 participants