I am writing an application to query the DNS SRV record to find out an internal service for a domain obtained from the email address. Is it correct to do the following.
- Lets say the email domain is test.example.com
- Query SRV record _service._tcp.test.example.com
- No SRV record is returned
- Now query SRV record _service._tcp.example.com
- A record is returned. Hence use this record to connect
Is the above approach right? Assuming its not, are there any RFCs or standards that prevents an application from doing it?
No, it is not. You should not "climb" to the root.
There is nothing explicitly telling you not to do that in RFCs and you will even find some specifications telling you to climb to the root, see
CAAspecifications (but they had to be changed over the year because of some unclarity exactly around the part about climbing to the root).Most of the time, such climbing creates more problems than solution, and it all come from "finding the administrative boundaries" which looks far more simple than what it is really.
If we go back to you example, you say, use
_service._tcp.test.example.comand then_service._tcp.example.comand then I suppose you stay there, because you "obviously" know that you shouldn't go to_service._tcp.comas next step, because you "know" thatexample.comandcomare not under the same administrative boundaries, so you shouldn't cross that limit.Ok, yes, in that specific example (and TLD) things seem simple. But imagine an arbitrary name, let us say
www.admin.santé.gouv.fr, how do you know where to stop climbing?It is a difficult problem in all generality. Attempts were made to solve it (see IETF DBOUND working group) and failed. You have only basically two venues if you need to pursue: either find delegations (zone cuts) by DNS calls (not all delegations are new administrative boundaries, but a change of administration should mean a delegation; and obviously there is not necessarily a delegation at each dot, so you can not find all of this by just looking at the string, you need to do live DNS queries) OR using Mozilla Public Suffix List, which has a lot of drawbacks.
This is all basically a rehash of what you can read in "§4. Zone Boundaries are Invisible to Applications" of RFC5507, quoting the core part here:
Note indeed also the example given for
MXbecause a naive view you apply the same algorithm there, but as the RFC says:There are various examples of people having tried to climb to the root... and creating a lot of problems:
wpad.dat: https://news.softpedia.com/news/wpad-protocol-bug-puts-windows-users-at-risk-504443.shtmlSo, in short, without a solid understanding of DNS, please do not create anything "climbing" to the root. Do note that RFC2782 about
SRVgives "Usage Rules" without a case of climbing to the root.You are not explaining fully why you are thinking about this. I suggest you have a look at the newest
HTTPS/SVCBDNS records (RFCs not published yet, but RR type codepoint assigned by IANA already, and in use by Apple, Cloudflare and Google already), as they may provide similar features set asSRVbut may be more relevant for your use case.