opnsense / plugins

OPNsense plugin collection
https://opnsense.org/
BSD 2-Clause "Simplified" License
845 stars 640 forks source link

www/caddy: Add option to compile only the needed DNS Provider #3867

Closed Monviech closed 7 months ago

Monviech commented 7 months ago

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

Is your feature request related to a problem? Please describe.

The problem is, that the current caddy build is unmaintainable, because the DNS Provider modules are creating incompatibilities between each other. This can happen at any time, because of the dependency structure of golang. Also, this kind of build is not recommended by the developers, only the DNS module that is used, should also be compiled in. https://caddy.community/t/having-trouble-with-reproducable-builds-with-caddy-dns-providers/23238

Describe the solution you'd like

Describe alternatives you've considered

Additional context

All in all, this is the biggest issue my plugin is facing right now, and whichever solution is chosen will have ups and downs. There is no perfect solution right now.

Short term solution

Monviech commented 7 months ago

Example of a successful module addition:

root@OPNsense:/usr/local/bin # caddy add-package github.com/caddy-dns/cloudflare
2024/03/24 07:27:54.625 INFO    this executable will be replaced        {"path": "/usr/local/bin/caddy"}
2024/03/24 07:27:54.625 INFO    requesting build        {"os": "freebsd", "arch": "amd64", "packages": ["github.com/caddy-dns/cloudflare"]}
2024/03/24 07:27:55.178 INFO    build acquired; backing up current executable   {"current_path": "/usr/local/bin/caddy", "backup_path": "/usr/local/bin/caddy.tmp"}
2024/03/24 07:27:55.178 INFO    downloading binary      {"destination": "/usr/local/bin/caddy"}
2024/03/24 07:27:57.807 INFO    download successful; displaying new binary details      {"location": "/usr/local/bin/caddy"}

Module versions:

dns.providers.cloudflare v0.0.0-20231220181002-8789126791ed

  Non-standard modules: 1

  Unknown modules: 0

Version:
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

2024/03/24 07:27:57.894 INFO    upgrade successful; please restart any running Caddy instances  {"executable": "/usr/local/bin/caddy"}

Example of a successful module removal:

root@OPNsense:/usr/local/bin # caddy remove-package github.com/caddy-dns/cloudflare
2024/03/24 07:29:27.523 INFO    this executable will be replaced        {"path": "/usr/local/bin/caddy"}
2024/03/24 07:29:27.523 INFO    requesting build        {"os": "freebsd", "arch": "amd64", "packages": []}
2024/03/24 07:29:28.150 INFO    build acquired; backing up current executable   {"current_path": "/usr/local/bin/caddy", "backup_path": "/usr/local/bin/caddy.tmp"}
2024/03/24 07:29:28.150 INFO    downloading binary      {"destination": "/usr/local/bin/caddy"}
2024/03/24 07:29:30.674 INFO    download successful; displaying new binary details      {"location": "/usr/local/bin/caddy"}

Module versions:

  Non-standard modules: 0

  Unknown modules: 0

Version:
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

2024/03/24 07:29:30.755 INFO    upgrade successful; please restart any running Caddy instances  {"executable": "/usr/local/bin/caddy"}
fichtner commented 7 months ago

To be frank I'd advise against making a barely manageable dyndns subsystem more complex and I believe that loading binary files from a remote location is a security risk we do not want to be introducing in the public plugins repo. Let alone the work for code and the risk for regressions that cannot be traced.

Cheers, Franco

Monviech commented 7 months ago

@fichtner If that's the case I have to remove the whole DNS Provider feature. I haven't expected this to turn out like this when I implemented it.

Current state of the DNS Provider feature:

The way forward:

All in all, I leave this decision up to you, and I will follow what you suggest as the best way forward.

fichtner commented 7 months ago

Most of these problems appear to be inherent to DynDNS as we have seen over the years (individual hobby projects glued together not supported by enterprises at all) and the way caddy outsources them to avoid trouble in their own project.

My recommendation is to leave the current state as it is, only improve with actual user reports and confirmations and/or consider removal of actually broken integrations later on.

What do you think?

Monviech commented 7 months ago

We already can't leave it as it is anymore, since the libdns version of cloudflare was bumped, and that makes it collide with most other already compiled dns providers.

Next time you try to build caddy-custom it will fail. (Already checked that with opnsense tools)

If this current feature set should be retained, we have to fork the currently DNS Provider Plugins, and use the forked ones as build reference.

Or... -I have to check that-, specify the exact git commit hashes when compiling from their repos, so that it doesn't pull latest with all plugins, but the state we know that works.

But since those plugins are all community maintained (except cloudflare, which the caddy developers seem to have an eye on), this will break more and more in the future when version go even more out of sync between different plugins.

This seems to be supported by go, so I could freeze the current working build by including commit hashes to all additional modules: github.com/someone/some_module@af044c0995fe

EDIT: Example, currently testing.

https://github.com/Monviech/opnsense-tools/blob/f27010f538da62fa2c80560e40075097dbba3d8e/config/24.1/make.conf#L97

Monviech commented 7 months ago

@fichtner Yup, specifying the commit hash makes the build go through.

2024/03/24 09:56:13 [INFO] Build complete: ./caddy
2024/03/24 09:56:13 [INFO] Cleaning up temporary folder: /tmp/buildenv_2024-03-24-0954.3907689736
[20240324095613] ===> Staging for caddy-custom-2.7.6.3.0.3.5.3_15
[20240324095613] ===> Generating temporary packing list
install  -s -m 555 /usr/obj/usr/ports/www/caddy-custom/work/caddy-custom-2.7.6.3.0.3.5.3/caddy /usr/obj/usr/ports/www/caddy-custom/work/stage/usr/local/bin
[20240324095613] ====> Compressing man pages (compress-man)
[20240324095613] ===> Staging rc.d startup script(s)
[20240324095613] ===> Installing for caddy-custom-2.7.6.3.0.3.5.3_15
[20240324095613] ===> Checking if caddy-custom is already installed
[20240324095613] ===> Registering installation for caddy-custom-2.7.6.3.0.3.5.3_15
Installing caddy-custom-2.7.6.3.0.3.5.3_15...
Creating package for bash-5.2.26_1
bash-5.2.26_1 already packaged, skipping...
Creating package for caddy-custom-2.7.6.3.0.3.5.3_15

So I will put the commit hashes behind each of the plugins I use. And if a plugin breaks in the future we will remove it.

fichtner commented 7 months ago

Sounds like a plan. I haven’t noticed it breaking yet but I can confirm that nightly didn’t build caddy-custom after checking the log.

Monviech commented 7 months ago

https://github.com/opnsense/ports/pull/190 https://github.com/opnsense/tools/pull/400

Ran the build a few times, always works, always takes the same sources. I think it might be fixed for a while now.

Monviech commented 7 months ago

The current build with the commit hashes is successful. I will keep an eye out for the state of these plugins. The current issues seem mitigated for now.

A DNS provider plugin will be removed if:

A DNS Provider plugin will be added if:

fichtner commented 7 months ago

@Monviech yep, good policy

Monviech commented 7 months ago

Adding a list about the current state of DNS Plugins:

https://github.com/opnsense/plugins/issues/3872