octodns / octodns-cloudflare

Cloudflare DNS provider for octoDNS
MIT License
24 stars 17 forks source link

API calls not working for IDNA domains #42

Closed sc0ttbeardsley closed 1 year ago

sc0ttbeardsley commented 1 year ago

For internationalized domains the api calls seem to be failing. I specify the IDNA domain name in configs (eg xn--trumezimmer-m8a.ch) but the Cloudflare provider doesn't recognize it during the dry-run and wants to recreate it. When I try to apply the API throws an error:

2023-03-17T22:29:42  [139770275735360] INFO  CloudflareProvider[cloudflare] apply: making 7 changes to träumezimmer.ch.
Traceback (most recent call last):
  File "/home/sbeardsley/.virtualenvs/dns/bin/octodns-sync", line 8, in <module>
    sys.exit(main())
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns/cmds/sync.py", line 62, in main
    force=args.force,
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns/manager.py", line 653, in sync
    total_changes += target.apply(plan)
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns/provider/base.py", line 245, in apply
    self._apply(plan)
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns_cloudflare/__init__.py", line 787, in _apply
    resp = self._try_request('POST', '/zones', data=data)
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns_cloudflare/__init__.py", line 84, in _try_request
    return self._request(*args, **kwargs)
  File "/home/sbeardsley/.virtualenvs/dns/lib/python3.6/site-packages/octodns_cloudflare/__init__.py", line 103, in _request
    raise CloudflareError(resp.json())
octodns_cloudflare.CloudflareError: xn--trumezimmer-m8a.ch already exists

When I create the zone via the zone API manually it works:

curl --request POST \
     --url https://api.cloudflare.com/client/v4/zones \
     --header 'Content-Type: application/json' \
     --header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
     --header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
     --data '{ "account": { "id": "'$CLOUDFLARE_ACCOUNT_ID'"}, "name": "xn--trumezimmer-m8a.ch", "type": "full"}'

Looks like the API returns the UTF response even when the input is IDNA format:

$ curl -s --request GET   --url https://api.cloudflare.com/client/v4/zones?name=xn--trumezimmer-m8a.ch. --header 'Content-Type: application/json'   --header "X-Auth-Email: $CLOUDFLARE_EMAIL"   --header "X-Auth-Key: $CLOUDFLARE_API_KEY"|jq .result[0].name
"träumezimmer.ch"

Perhaps the comparison needs to account for this?

Using:

octodns==0.9.21
octodns-cloudflare==0.0.1
ross commented 1 year ago

eg xn--trumezimmer-m8a.ch

As of v0.9.20 octoDNS supports UTF-8/IDNA encoding automatically.

https://github.com/octodns/octodns/blob/main/CHANGELOG.md#v0920---2022-10-05---international-friendly

Have you tried putting the utf-8 version of the domain name in the config?

Regardless that should be more of a work-around and it should ideally handle the case or at the very least warn you that it should be there as utf-8. I haven't tried IDNA specifically with CloudFlare so it's possible that something else is going awry. Will have to dig into it when I get a chance.