Azure DNS zone export missing trailing "." on MX, NS, PTR, SRV record targets
Describe the bug When exporting a DNS zone from Azure DNS, MX/NS/PTR/SRV record type targets don't get a trailing "." appended which means the zone file is incorrect.
To Reproduce
az network dns zone create -g
The output of the export of those records will look as follows:
mxtest 3600 IN MX 0 contoso.com nstest 3600 IN NS ns.contoso.com ptrtest 3600 IN PTR ptr.contoso.com srvtest 3600 IN SRV 0 0 443 srv.contoso.com
Expected behavior The output should have a trailing "." on those 4 records as below to make them FQDNs instead of relative names. Azure DNS treats all targets in these record types as FQDNs so the CLI export should treat them as such. Without this trailing "." it will cause these record type values to be incorrect when loading this export into another DNS server such as BIND or even when re-importing using "az network dns zone import" by wrongly appending the zone name.
mxtest 3600 IN MX 0 contoso.com. nstest 3600 IN NS ns.contoso.com. ptrtest 3600 IN PTR ptr.contoso.com. srvtest 3600 IN SRV 0 0 443 srv.contoso.com.
Environment summary
Windows-10-10.0.19041-SP0 Python 3.6.6 Installer: MSI
azure-cli 2.9.1
Additional context The CNAME and SOA record types seem to behave correctly already. Please make MX, NS, PTR, SRV target values behave as those. Do note there should only be exactly 1 trailing "." at the end. If the existing record contains one already, then we should not append another.
add to S174
@nkindberg Thanks for raising this issue. Let me reproduce this issue and find the root cause.
@nkindberg Hi. I want to confirm this behavior with you. Do you mean this command az network dns record-set ptr add-record -d "ptr.contoso.com" -n ptrtest -g -z is invalid? Azure should append . or the correct command should be az network dns record-set ptr add-record -d "ptr.contoso.com." -n ptrtest -g -z?
@MyronFanQiu the command az network dns record-set ptr add-record -d "ptr.contoso.com" -n ptrtest -g -z is correct. The problem is with az network dns zone export -g -n. During the export the CLI needs to write this record as ptrtest 3600 IN PTR ptr.contoso.com. with the trailing '.'
The problem as far as I can tell lies in this function: https://github.com/Azure/azure-cli/blob/3dbb10f930db761a73f116988ee59000a4e4d15e/src/azure-cli/azure/cli/command_modules/network/custom.py#L1942
In the linked line you can see for CNAME we process the record as record.cname.rstrip('.') + '.' which appends the '.' to the record even if it doesn't already have one. We need to do this exact same thing for other record types I mentioned in this issue.
By the way, I am from Azure DNS product group. I am reporting this issue on behalf of a customer who filed a support ticket with us.
@nkindberg Yeah. The code is not complicated and I have fnished. But the behavior is a little bit weird for me and I want to confirm this change. Let me give a brief example.
- Using
az network dns record-set ptr add-record -d "contoso.com" -n ptrtest -g -zto create a ptr record.
- Using
az network dns zone exportto save this zone. - Using
az network dns zone importto import this zone back.
There will be a trailing "." after contoso.com. Is that correct behavior?
Yes @MyronFanQiu that behavior is fine. In Azure DNS "contoso.com" and "contoso.com." mean the same thing. Azure DNS always assumes the value of the PTR record is a FQDN (fully-qualified domain name).
Traditionally in a zone file "contoso.com" will mean relative name aka "contoso.com.zonename" while "contoso.com." will be considered a fully-qualified name. Since in the Azure DNS case we always treat everything as a fully-qualified name even without the trailing '.' the exported zone file should result in "contoso.com." since what we really mean is the FQDN.
Yes @MyronFanQiu that behavior is fine. In Azure DNS "contoso.com" and "contoso.com." mean the same thing. Azure DNS always assumes the value of the PTR record is a FQDN (fully-qualified domain name).
Traditionally in a zone file "contoso.com" will mean relative name aka "contoso.com.zonename" while "contoso.com." will be considered a fully-qualified name. Since in the Azure DNS case we always treat everything as a fully-qualified name even without the trailing '.' the exported zone file should result in "contoso.com." since what we really mean is the FQDN.
Got it. Thanks for the explanation. Will open the PR soon.