2

I'm testing google cloud dns, and tried to create TXT record using gcloud command. However, created record is unexpectedly escaped.

This is what I did:

% gcloud dns records --zone="myzonename" edit

In "additions" section, I added TXT record like this:

{
    "kind": "dns#resourceRecordSet",
    "name": "example.com.",
    "rrdatas": [
        "v=spf1 include:_spf.google.com ~all",
    ],
    "ttl": 84600,
    "type": "TXT"
},

gcloud command exited with no error, and TXT record was created in my zone. However, the created record looks like this:

{
    "kind": "dns#resourceRecordSet",
    "name": "example.com.",
    "rrdatas": [
        "\"v=spf1\" \"include:_spf.google.com\" \"~all\"",
    ],
    "ttl": 84600,
    "type": "TXT"
},

As you can see, double quotes are kept in data. I verified that response from DNS server also includes double quote and spaces.

% nslookup -type=TXT example.com. ns-cloud-e1.googledomains.com.
Server:     ns-cloud-e1.googledomains.com.
Address:    216.239.32.110#53

example.com text = "v=spf1" "include:_spf.google.com" "~all"

Expected output is example.com text = "v=spf1 include:_spf.google.com ~all"

How can I stop this unnecessary escaping?

Alyssa Pittman
  • 208
  • 1
  • 3

2 Answers2

3

A DNS TXT record consists of a list of "character strings", each one less than 255 octets (see RFC 1035). In zone file format, you express this as a sequence of whitespace separated strings. Each string can be quoted or unquoted. If one of your character strings contains embedded white space you'll need to use the quoted form.

The system is interpreting your input as a list of three character strings but it sounds like you are trying to create a TXT record with a single character string. Try:

{
   "kind": "dns#resourceRecordSet",
   "name": "example.com.",
   "rrdatas": [
       "\"v=spf1 include:_spf.google.com ~all\"",
   ],
   "ttl": 84600,
   "type": "TXT"
},

The outer quotation marks are for the JSON string. The inner escaped-for-JSON ones are part of the zone file format. Hope this helps.

John Asmuth
  • 1,052
  • 5
  • 7
  • 1
    Thanks for the suggestion, and also back story. I succeeded to create a dns record as I had expected. – user3509567 Apr 11 '14 at 03:58
  • +1 This is also true if you use the Developer Console UI for same. Had to enclose the whole string in quotes (spf, domain keys, etc.) to prevent it from being interpreted as a "list of strings". Thnx! – EdSF Sep 16 '15 at 15:49
0

Same issue here...

It seems to be a bug with the gcloud SDK.

I worked around it by escaping the spaces:

{
  "kind": "dns#resourceRecordSet",
  "name": "example.com.",
  "rrdatas": [ "v=spf1\\ mx\\ include:_spf.google.com\\ ~all" ],
  "ttl": 21600,
  "type": "TXT"
}

You have to escape the spaces with two backward slashes.

All the best!

Sveon
  • 1