mholt / caddy-dynamicdns

Caddy app that keeps your DNS records (A/AAAA) pointed at itself.
Apache License 2.0
250 stars 25 forks source link

Add ability to update additional A records. #3

Closed MagnuM2K closed 3 years ago

MagnuM2K commented 3 years ago

Below is possible example.. Ideally, you can point to the primary domain with a CNAME, but you usually have the default root domain and then www.


{
    dynamic_dns {
        domain example.com
        record_list www,@,sub
    provider gandi {env.GANDI_API_TOKEN}
    check_interval 5m
    }
}
mholt commented 3 years ago

Ah yeah, this is on my list... need to revisit this repo again soon.

mholt commented 3 years ago

Okay, done in https://github.com/mholt/caddy-dynamicdns/commit/aa9c8162558596bd1b32421838ffb842351b560b! Hope it works. :laughing:

MagnuM2K commented 3 years ago

This is great!! Just tested and it worked.. But..

It created duplicate A records for both @ and www.

How I tested, I kept existing A records, but changed the IP. Stopped Caddy/container.. Rebuilt container.. Just to make sure it was grabbing new dynamic_dns code. Checked records on Gandi and saw that duplicate A records were in table/list.

If you need additional info or logs, let me know.

Thanks

mholt commented 3 years ago

@MagnuM2K What is your config?

MagnuM2K commented 3 years ago

Here it is.. There is more than this and obviously site.com is not my domain.. but I only included the Global options. If you need the full config.. I'll post it, if needed.

{
        dynamic_dns {
                provider gandi <APIKEY>
                domains {
                        site.com @ www
                }
                check_interval 5m
        }
        debug
        acme_dns gandi <APIKEY>
        cert_issuer zerossl
        cert_issuer acme
        email webmaster@site.com
}
mholt commented 3 years ago

@MagnuM2K Thanks -- I tried it with Cloudflare since I don't have a gandi account. I am unable to reproduce the behavior: existing A records are replaced with the new values, instead of duplicating them.

I would ask the maintainer of the gandi implementation for assistance: https://github.com/libdns/gandi

MagnuM2K commented 3 years ago

Ok. This is weird. I tried it again with the latest caddy commit, just in case I was missing some piece of code.

Then before I stopped/rebuilt/started container. I updated DNS records to a TTL 600..

Then when I started container and checked DNS records. The 2 original A records (@, www) that I changed to 600 TTL were updated to 300. But 2 new A records, matching the @ and www that I wanted to update were created with a 300 TTL.

In fact I think you are right, I was looking at gandi and libdns go code and was thinking that maybe the issue is with gandi module not invoking the Record.Setter code and maybe using Record.Appender?? (I'm not an expert.. so don't take what I'm saying as fact).

mholt commented 3 years ago

The TTL of 300 comes from check_interval, since it makes sense that the record shouldn't be cached longer than the possibility of the value changing.

This module uses SetRecords(), so if there is a bug or difference with how gandi is handling that, it could theoretically result in duplicate records.

tiagosimao commented 11 months ago

Hi there.

Bumped into the same "bug" in the Gandi libdns, got no feedback so developed a different provider.

Just leaving this info here for future reference. Cheers.