azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Azure DNS zone export missing trailing "." on MX, NS, PTR, SRV record targets

Open nkindberg opened this issue 6 years ago • 7 comments

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 -n az network dns record-set mx add-record -e contoso.com -p 0 -n mxtest -g -z az network dns record-set ns add-record -d ns.contoso.com -n nstest -g -z az network dns record-set ptr add-record -d "ptr.contoso.com" -n ptrtest -g -z az network dns record-set srv add-record -r 443 -p 0 -t srv.contoso.com -w 0 -n srvtest -g -z az network dns zone export -g -n

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.

nkindberg avatar Jul 17 '20 22:07 nkindberg

add to S174

yonzhan avatar Jul 18 '20 01:07 yonzhan

@nkindberg Thanks for raising this issue. Let me reproduce this issue and find the root cause.

mmyyrroonn avatar Jul 20 '20 01:07 mmyyrroonn

@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?

mmyyrroonn avatar Aug 07 '20 08:08 mmyyrroonn

@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 avatar Aug 07 '20 16:08 nkindberg

@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.

  1. Using az network dns record-set ptr add-record -d "contoso.com" -n ptrtest -g -z to create a ptr record. image
  2. Using az network dns zone export to save this zone.
  3. Using az network dns zone import to import this zone back. image

There will be a trailing "." after contoso.com. Is that correct behavior?

mmyyrroonn avatar Aug 10 '20 03:08 mmyyrroonn

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.

nkindberg avatar Aug 10 '20 23:08 nkindberg

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.

mmyyrroonn avatar Aug 11 '20 01:08 mmyyrroonn