caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
55.53k stars 3.91k forks source link

CADDY_ADMIN cannot be used to disable the admin interface #6280

Closed jpluscplusm closed 2 months ago

jpluscplusm commented 2 months ago

Expectation

I expected that the CADDY_ADMIN environment variable, added in #5317, would be able to be used to disable the admin interface.

Reproducer

Setting the variable to the value off, as mentioned by https://caddyserver.com/docs/caddyfile/options#admin, results in the address http://off being used, preventing server startup (lookup off on 8.8.8.8:53: no such host).

$ cat Caddyfile.test
{
    http_port 8080
    auto_https off
    skip_install_trust
}

:8080 {
    respond 200 "Success"
}
$ CADDY_ADMIN=off caddy run --config Caddyfile.test  
2024/04/28 23:05:28.451 INFO    using provided configuration    {"config_file": "Caddyfile.test", "config_adapter": ""}
Error: loading initial config: loading new config: starting caddy administration endpoint: listen tcp: lookup off on 8.8.8.8:53: no such host

Impact

This is a minor security annoyance when deploying to a remote hosting environment on which the interface will never be accessed (except maliciously by an intruder) but needs not to be disabled by hardcoding admin off in the Caddyfile. e.g. if the Caddyfile needs to be promoted, unchanged, from a testing environment in which the admin interface is required.

Versions

$ caddy version; uname -smv
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=
Linux #1 SMP PREEMPT_DYNAMIC Sat, 17 Feb 2024 21:12:19 +0000 x86_64

Related

6281

francislavoie commented 2 months ago

The only reason this env var exists is to allow package managers to set a different default (e.g. unix socket file). The intent is not to make it cover the various options, including turning off admin.