Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top