nrdxp / cfdyndns

CloudFlare Dynamic DNS Client
MIT License
12 stars 15 forks source link

cfdyndns fails when a `CAA` record (or any other unknown RR type) exists in the zone #54

Closed fadenb closed 5 months ago

fadenb commented 8 months ago

Hey :wave:,

I have been using cfdyndns for a while on my NixOS systems and it worked without any issues :+1:. Recently, I added a CAA record to my zone using the CloudFlare WebUI. Since I added this record of type CAA cfdyndns fails with an error:

Feb 22 14:25:00 MY-HOSTNAME cfdyndns-start[1661398]:  INFO  cfdyndns::ip > 93.XXX.XXX.XXX
Feb 22 14:25:00 MY-HOSTNAME cfdyndns-start[1661398]:  INFO  cfdyndns::ip > 2001:a61:YYYY:YYYY:YYYY:YYYY:YYYY:YYYY
Feb 22 14:25:03 MY-HOSTNAME cfdyndns-start[1661398]: Error: error decoding response body: unknown variant `CAA`, expected one of `A`, `AAAA`, `CNAME`, `NS`, `MX`, `TXT`, `SRV` at line 1 column 3357
Feb 22 14:25:03 MY-HOSTNAME systemd[1]: cfdyndns.service: Main process exited, code=exited, status=1/FAILURE

I redacted some fields for privacy reasons.

A quick search on the source code lead me to https://github.com/nrdxp/cfdyndns/blob/bd02dd0b8f6689f3bb7a48095bf4fabb50094b5f/src/dns.rs#L72-L83 I assume extending this would suffice to address this issue. Given sufficient time I might contribute a fix myself though for now I can not tell when that might be the case.

diogotcorreia commented 8 months ago

I've literally just encountered this problem myself (after my IP changed and the DNS did not update; I found that the cfdyndns service had failed).

After some digging, it seems like it's a problem in the cloudflare crate (of which I could not find any GitHub link of): https://docs.rs/crate/cloudflare/latest/source/src/endpoints/dns.rs The enum DnsContent does not have a CAA record, which causes the parsing of the API response to fail. I'm really not sure how to fix it, I think we are dependent on upstream fixing the issue (not sure how to report it either; I could not find an issue tracker).

diogotcorreia commented 8 months ago

Upon some further inspection, I think it should be possible to go around this problem by adding some parameters to the fetch request: https://github.com/nrdxp/cfdyndns/blob/bd02dd0b8f6689f3bb7a48095bf4fabb50094b5f/src/dns.rs#L178 https://docs.rs/cloudflare/latest/cloudflare/endpoints/dns/struct.ListDnsRecordsParams.html

Feel free to make a PR fixing this if you can, otherwise I should be able to submit one a few days from now.

diogotcorreia commented 8 months ago

@fadenb I've submitted a PR to fix this issue, but until it has been accepted you can apply the patch manually as such: https://github.com/diogotcorreia/dotfiles/commit/431e8bc14fec0181ae24e936e5b737da468ae5d7

Let me know if it works for you :)

fadenb commented 8 months ago

@diogotcorreia the patch works perfectly. Thank you :)