Closed mietzen closed 1 year ago
You would implement a plugin like this: https://caddyserver.com/docs/extending-caddy
Take a look at the SimpleHTTP module: https://github.com/mholt/caddy-dynamicdns/blob/master/ipsource.go
Your plugin would look almost the same as SimpleHTTP except have a different module name.
To clarify, I don't think that support for this would be a fit for this project, it makes more sense as a separate package/repo. It's a very niche usecase (i.e. only if you own a specific piece of hardware from a specific provider).
How would you feel about a option to obtain IPs from a external program, with e.g. exec.Command
This would be a more generalist approach, which would cover all niche use cases.
Yeah, that could be interesting. WDYT @mholt
My concern with exec.Command
generally is that it would allow a bad actor to escalate access (or just do bad things in general) if they manage to change your Caddy config. It is a bit of a paranoid concern, but it is a theoretical risk that wouldn't otherwise exist if the plugin didn't have support for running arbitrary commands.
Yes of course, but wouldn't one have to have write access to either your caddy config (script path) or the script already? If we only give root write access to the script and the caddy user only read + execute permissions, I would say this should be "fine". Or am I missing something?
Edit: but yes if your caddy process runs as root and you do stupid stuff in your script, bad things will happen 😉
Since Caddy's admin API is accessible at localhost:2019
by default, "all that's needed" is the ability to make arbitrary HTTP requests from the server to itself (POST with a payload to update the config, GET with output to potentially get secrets from the config), then the config can be changed to escalate. Also root isn't necessary to do bad things, e.g. an attacker could exfiltrate your cert's private key to impersonate your domain.
Either way, yes this is paranoid and it does require other things to go wrong before it's a real problem, but it's still a vector for escalation that users need to be aware of.
I tried my best to Implement it, but I only played a little bit with a over a year ago (Hence the draft PR). How do build and test this again.
xcaddy build --with github.com/mholt/caddy-dynamicdns=github.com/mietzen/caddy-dynamicdns@master
Thanks for opening an issue!
I think a module to get the IP address from a command is a decent idea, but until we get a sense of how secure people's environments are I think I still want to keep it an external/separate plugin.
I made a separate module: https://github.com/mietzen/caddy-dynamicdns-cmd-source
Awesome. Thanks for understanding -- we look forward to it being used!
Feel free to add it to the Caddy website if you haven't already (just log in to your account and register the package).
Hi,
I have a similiar Issue as https://github.com/mholt/caddy-dynamicdns/issues/31.
My setup looks like this: Fritz!Box -> VPN-GW -> Clients
To obtain the "ISP-IP" and not the "VPN-IP" I use DDClient with the following script: https://github.com/ddclient/ddclient/blob/master/sample-get-ip-from-fritzbox
Now I would like to do the same with caddy.
I generated some working go code with ChatGPT, but I'm not sure how to integrate it.