blog

12021-07-28

SEAN K.H. LIAO

TXT

Sure DNS might be the distributed key-value store of choice, perhaps even something to base your next filesystem off of, but those TXT records sure can be finicky.

The format is define in RFC 1035 Section 3.3.14.

So you can have multiple TXT records, and within each record, you can have multiple strings up to 255 bytes each (+1 length byte). If you have a string longer than 255 bytes, you can break it up into shorter segments, and clients should be able to recombine them. Most(?) DNS hosts are smart enough to split it for you but some require you to do it manually cough Google Cloud DNS cough

Ex: gmail's current DKIM keys, note the value is returned as 2 quoted strings.

$ drill TXT 20161025._domainkey.gmail.com
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 54894
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; 20161025._domainkey.gmail.com.	IN	TXT

;; ANSWER SECTION:
20161025._domainkey.gmail.com.	299	IN	TXT	"k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAviPGBk4ZB64UfSqWyAicdR7lodhytae+EYRQVtKDhM+1mXjEqRtP/pDT3sBhazkmA48n2k5NJUyMEoO8nc2r6sUA+/Dom5jRBZp6qDKJOwjJ5R/OpHamlRG+YRJQqR" "tqEgSiJWG7h7efGYWmh4URhFM9k9+rmG/CwCgwx7Et+c8OMlngaLl04/bPmfpjdEyLWyNimk761CX6KymzYiRDNz1MOJOJ7OzFaS4PFbVLn0m5mf0HVNtBpPwWuCNvaFVflUYxEyblbB6h/oWOPGbzoSgtRA47SHV53SwZjIsVpbq4LxUW9IxAEwYzGcSgZ4n5Q8X8TndowsDUzoccPFGhdwIDAQAB"

;; AUTHORITY SECTION:

;; ADDITIONAL SECTION:

;; Query time: 9 msec
;; SERVER: 127.0.0.53
;; WHEN: Tue Jul 27 23:28:34 2021
;; MSG SIZE  rcvd: 462

Ex: my terraform config for DKIM in Google Cloud DNS, note it's a single record that's space separated (hence the need for quotes) split at less than 255:

locals {
  medea_dkim = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3R2wlknuJGSUG6St2MBKoD2/BlCt0yA1LpYBRy7rw+uaiePMJHEUM5LZPTsgM6uz0PaRN2u+wOg0ulPdpKhdn5LylX5mEtM+kGBIya2QTsBVDEzgoecOj+sdufVB43sPRXSEdzav+bMv4nvMYtMPbNX1hlk8GEvnMooHB85tDL7LipK26rdc/gIy39kiMqHJavPae3CsMIZiNG6D4oMtePFz9yPlQmm9LVVvCqPTqKvR6Rva3nFTLVBUrO7U4FlKWa+/4VdE89SNDzrZshkSTq6fJ75eA8TRzi0jwwT4silfNXpMnloy4hMC3NHibr9ftAncuRLm1zbWy4LLfFlbmQIDAQAB"
}

resource "google_dns_record_set" "TXT__default__domainkey_medea" {
  managed_zone = google_dns_managed_zone.medea.name
  name         = "default._domainkey.${google_dns_managed_zone.medea.dns_name}"
  type         = "TXT"
  rrdatas = [
    "\"${substr(local.medea_dkim, 0, 253)}\" \"${substr(local.medea_dkim, 253, -1)}\"",
  ]
  ttl = 1
}