jlentink / go-transip-dyndns

Easy update your hostname hosted with TransIP to your dynamic address.
MIT License
36 stars 3 forks source link

Updating DNS entry with mismatched TTL fails #20

Open mmakaay opened 8 months ago

mmakaay commented 8 months ago

Update: the original title of the issue reported issues with updating the @ entery in DNS, but I changed it after finding out the actual issue at hand. See this message for the TL;DR

I have setup transip-dyndns (latest version) and a configuration file with these records to update:

[[record]]
hostname = "makaay.nl"
entry = "here-is"
ttl = 60
type = "A"

[[record]]
hostname = "makaay.nl"
entry = "@"
ttl = 60
type = "A"

When the target records already contain the correct IP addresses as content, things are peachy:

DEBUG - Log level set to debug...
DEBUG - Found IP address. (145.144.245.6)
DEBUG - DNS [A] record has not been changed.
2024-02-22 15:01:08 - πŸ‘  Record still up to date: here-is.makaay.nl [A]
2024-02-22 15:01:08 - πŸ‘  Record still up to date: @.makaay.nl [A]

However, when my IP address changes, updating the @ entry fails. Here is what happens if I update the @ record and then run the program (last line with added line break for readability):

DEBUG - Log level set to debug...
DEBUG - Found IP address. (145.144.245.6)
DEBUG - DNS [A] record has not been changed.
2024-02-22 15:06:13 - πŸ‘  Record still up to date: here-is.makaay.nl [A]
2024-02-22 15:06:13 - ❗  Could not update the record to update @.makaay.nl [A] -
                          Could not find match for DNS entry '@ 60 A'
mmakaay commented 8 months ago

Trying curl against the TransIP API shows me that I have the following record:

{"name":"@","expire":300,"type":"A","content":"192.87.156.100"}

Performing this query:

curl -X PATCH \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer ****" \    -d '
    {
      "dnsEntry": {
        "name": "@",
        "expire": 60,
        "type": "A",
        "content": "77.174.229.213"
      }
    }
    ' \
    "https://api.transip.nl/v6/domains/makaay.nl/dns"

Does result in the error that I see in the logs:

{"error":"Could not find match for DNS entry '@ 60 A'"}

I think this means that the issue is to be found at the TransIP API side of things here, and not directly in go-transip-dyndns.

mmakaay commented 8 months ago

Hmmm, interestingly enough, my curl-based patch request does work when the expire time matches the current expire time as defined in the TransIP DNS! I was able to update the DNS entry using the structure:

    {
      "dnsEntry": {
        "name": "@",
        "expire": 300,
        "type": "A",
        "content": "77.174.229.213"
      }
    }

Apparently, the expire time is included by the TransIP API in finding the record to update, which is a bit weird IYAM. By playing with the expiry time in the records that I defined, I am able to change the output of transip-dyndns:

DEBUG - Log level set to debug...
DEBUG - Found IP address. (145.144.245.6)
2024-02-22 15:27:34 - ❗  Could not update the record to update here-is.makaay.nl [A] - Could not find match for DNS entry 'here-is 300 A'
2024-02-22 15:27:34 - πŸ‘  Record updated @.makaay.nl [A] to 145.144.245.6

In this case, the @ record has a TTL that matches the active TTL and here-is.makaay.nl has a mismatching TTL. And when I make sure tat the TTL matches for both the records, then both get updated correctly.

mmakaay commented 8 months ago

TL;DR: when the active TTL from the TransIP DNS server differs from the ttl: field as defined in the TOML config, then updating the content for a DNS record through the TransIP API results in an error: "Could not find match for DNS entry '@ A" . When making sure the TTL matches the active one, updates do work correctly.

I think a good solution would be to:

And thanks for this project! Except for the little speed bump from above, it made it really simple to setup my own dyndns based on my TransIP domains πŸ‘