plugins icon indicating copy to clipboard operation
plugins copied to clipboard

os-ddclient Cloudflare API Key

Open sachinwadhwa opened this issue 3 years ago • 35 comments

Important notices Before you add a new report, we ask you kindly to acknowledge the following:

  • [x] I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
  • [x] I have searched the existing issues, open and closed, and I'm convinced that mine is new.
  • [x] The title contains the plugin to which this issue belongs

Describe the bug With latest update 22.1.1_1, Cloudflare DNS update only works with Global API key but it fails to work with an API token with DNS edit for the zone. Older plugin (DynDNS) I can create API token with specific DNS zone edit access and it used to works fine. Current method of using Global API key is very unsafe and might lead to security issues as Global API key have full admin access to your Cloudflare account.

Tip: to validate your setup was working with the previous version, use opnsense-revert (https://docs.opnsense.org/manual/opnsense_tools.html#opnsense-revert)

To Reproduce Steps to reproduce the behavior: As specified above

Expected behavior DNS update should work with specific API token/key and not with Global API key

Screenshots None

Relevant log files None

Additional context None

Environment 22.1.1_1

sachinwadhwa avatar Feb 17 '22 13:02 sachinwadhwa

Commenting to show interest. I also am still using the legacy os-dyndns plugin since I cannot use Cloudflare api tokens with this new plugin.

thafer30 avatar Mar 09 '22 02:03 thafer30

here is the part necessary for this change from the Cloudflare API documentation

API Key | X-Auth-Key | API key generated on the "My Account" page
Email | X-Auth-Email | Email address associated with your account
User Service Key | X-Auth-User-Service-Key | A special Cloudflare API key good for a restricted set of endpoints. Always begins with "v1.0-", may vary in length.

chiwou avatar Mar 09 '22 19:03 chiwou

This appears to be an issue regarding ddclient more than OPNSense. It seems like we don't know when the next release will be coming (https://github.com/ddclient/ddclient/issues/272)

Version bump request on ddclient (https://github.com/ddclient/ddclient/issues/361)

It is marked as fixed in the next release, so maybe we can get a new ddclient built from the current src?

Tetricz avatar Mar 11 '22 05:03 Tetricz

Just chiming in that I am experiencing the same issue. I will transition back to the legacy client for now.

jrm523 avatar Mar 17 '22 02:03 jrm523

bumping and subscribing. Though it really is a matter for ddclient to release its next release.

asche77 avatar Mar 23 '22 21:03 asche77

Seem to be running into this issue as well.

JHarding86 avatar Apr 01 '22 03:04 JHarding86

Same issue here. I just uninstalled the os-ddclient plugin as, unfortunately, it's useless to me without this feature.

bskinner avatar Apr 01 '22 14:04 bskinner

I also need a solution for this....

CodeAndWeb avatar Apr 13 '22 10:04 CodeAndWeb

This is a shame. I decided to make the leap from pfsense and was stopped dead in my tracks due to this. I had to revert. I love the interface of opnsense, but it's nothing if it doesn't work with the packages that I need. 🙃

JHarding86 avatar Apr 14 '22 02:04 JHarding86

you can still use the old plugin, even both at the same time, just wait until the new plugin has all the features of the old one

chiwou avatar Apr 15 '22 11:04 chiwou

This is very necessary for me, as I'm pretty sure even if I wanted to use username/password 2FA would get in the way of that.

Nolij avatar Apr 25 '22 21:04 Nolij

Looking at the code of ddclient, it seems like if you use token as the username and your Cloudflare API token as the password, it uses the Authentication: Bearer header as opposed to the X-Auth- headers to talk to the Cloudflare API. I've not tried it yet, but plan to.

https://github.com/ddclient/ddclient/blob/11a583b003920f8e15591813598b70061d1a4654/ddclient.in#L4764-L4766

rupertbenbrook avatar Apr 26 '22 14:04 rupertbenbrook

Looking at the code of ddclient, it seems like if you use token as the username and your Cloudflare API token as the password, it uses the Authentication: Bearer header as opposed to the X-Auth- headers to talk to the Cloudflare API. I've not tried it yet, but plan to.

https://github.com/ddclient/ddclient/blob/11a583b003920f8e15591813598b70061d1a4654/ddclient.in#L4764-L4766

It should, its been in the code for 2+ years. Perhaps a checkbox which makes this more user friendly can still be implemented? This is a "solution" but 10 of the 11 participants of this issue didn't find it until you posted that, and if this issue is closed it will likely be harder to find this issue as a method of finding that.

Nolij avatar Apr 26 '22 14:04 Nolij

https://github.com/ddclient/ddclient/issues/361

AdSchellevis avatar Apr 26 '22 14:04 AdSchellevis

Ah, I see. ddclient hasn't had a release since 3.9.1 and the Cloudflare API token support was added just after that release. So, that begs the question why opnsense are switching to ddclient as it's not been released for over 2 years, and regresses the existing functionality? How are other projects doing this? Are they pulling direct from the ddclient repo and not relying on releases?

rupertbenbrook avatar Apr 26 '22 14:04 rupertbenbrook

Ah, I see. ddclient hasn't had a release since 3.9.1 and the Cloudflare API token support was added just after that release. So, that begs the question why opnsense are switching to ddclient as it's not been released for over 2 years, and regresses the existing functionality? How are other projects doing this? Are they pulling direct from the ddclient repo and not relying on releases?

Come again? Please tell me dyndns is even more out of date...

Nolij avatar Apr 26 '22 14:04 Nolij

Yep, dyndns is much, MUCH more out of date! 2014 I think it the last code change.

https://git.savannah.nongnu.org/cgit/perl-dyndns.git

rupertbenbrook avatar Apr 26 '22 14:04 rupertbenbrook

Yep, dyndns is much, MUCH more out of date! 2014 I think it the last code change.

https://git.savannah.nongnu.org/cgit/perl-dyndns.git

Alright that's much better. Still though should probably be swapping to something that's still receiving updates instead of replacing a horse and buggy with a crank-start car

Nolij avatar Apr 26 '22 15:04 Nolij

likely caused by people only complaining and not a lot of people working on these topics, in which case the lack of commercial interest doesn't help either.

AdSchellevis avatar Apr 26 '22 15:04 AdSchellevis

likely caused by people only complaining and not a lot of people working on these topics, in which case the lack of commercial interest doesn't help either.

Fair enough.

Nolij avatar Apr 26 '22 15:04 Nolij

I think ddclient is still getting updates and is being maintained, just no-one seems to be releasing the updates in versioned releases, so this isn't being picked up downstream by FreeBSD and OPNsense.

rupertbenbrook avatar Apr 26 '22 15:04 rupertbenbrook

Well my previous point still remains: a change to the UI to add a checkbox which just puts username as token (and hides it), and labels the password box API Token shouldn't be difficult to implement and would avoid much confusion and future complaining.

Nolij avatar Apr 26 '22 15:04 Nolij

I think ddclient is still getting updates and is being maintained, just no-one seems to be releasing the updates in versioned releases, so this isn't being picked up downstream by FreeBSD and OPNsense.

Developed, not being released https://github.com/ddclient/ddclient/tags hence the tickets asking for a release. 3.9.1 is the version most distro's ship

AdSchellevis avatar Apr 26 '22 15:04 AdSchellevis

This is the only situation where I need to use my global API key and also would like to see this fixed. Looking at the project of ddclient there is already an issue and fix but still open and not in a release yet. Does have label fixed in next release. Hope this gets released some time soon so opnsense can implement this.

https://github.com/ddclient/ddclient/issues/361

GitPullNow avatar Apr 27 '22 13:04 GitPullNow

This obviously isn't a long-term fix, but i modified my local ddclient script to work with the changes until the official version is updated. Starting at line 4566, my file now looks like this.

                my $headers = "X-Auth-Email: $config{$key}{'login'}\n";
                if ($config{$key}{'login'} eq 'token') {
                        $headers .= "Authorization: Bearer $config{$key}{'password'}\n";
                } else {
                        $headers .= "X-Auth-Key: $config{$key}{'password'}\n";
                }
                        $headers .= "Content-Type: application/json";

agreenbhm avatar May 23 '22 14:05 agreenbhm

This obviously isn't a long-term fix, but i modified my local ddclient script to work with the changes until the official version is updated. Starting at line 4566, my file now looks like this.

                my $headers = "X-Auth-Email: $config{$key}{'login'}\n";
                if ($config{$key}{'login'} eq 'token') {
                        $headers .= "Authorization: Bearer $config{$key}{'password'}\n";
                } else {
                        $headers .= "X-Auth-Key: $config{$key}{'password'}\n";
                }
                        $headers .= "Content-Type: application/json";

Thanks for this info! I just tried setting this up today for the first time, and was banging my head trying to switch from global API key, and this worked perfectly. I know it's a temporary fix, but still glad to have it!

janssenjones avatar May 23 '22 15:05 janssenjones

Modifying /usr/local/sbin/ddclient as above worked for me on OPNsense 22.1.10-amd64

ilium007 avatar Jul 12 '22 16:07 ilium007

@ilium007 I assume you have made changes in /usr/local/sbin/ddclient (and not in /usr/local/opnsense/version/ddclient), right?

viliusz avatar Jul 13 '22 17:07 viliusz

had to slightly modify the script (based on above suggestions) to make it work with API Token in opnsense

file: /usr/local/sbin/ddclient lines: 4566-4573

                my $headers = "";
                if ($config{$key}{'login'} eq 'token') {
                        $headers .= "Authorization: Bearer $config{$key}{'password'}\n";
                } else {
                        $headers .= "X-Auth-Email: $config{$key}{'login'}\n";
                        $headers .= "X-Auth-Key: $config{$key}{'password'}\n";
                }
                $headers .= "Content-Type: application/json";

ps. make sure DNS record is set before using ddclient, otherwise you'd get an error

FAILED: updating ip: No DNS record ID found.

viliusz avatar Jul 13 '22 18:07 viliusz

@ilium007 I assume you have made changes in /usr/local/sbin/ddclient (and not in /usr/local/opnsense/version/ddclient), right?

Yes, copy and paste error. I’ll edit above to avoid any confusion.

ilium007 avatar Jul 13 '22 22:07 ilium007