I would like to re-use this list to restrict by remote_ip, something like:
@blocked_ip not remote_ip LIST_OF_TRUSTED_PROXIES
abort @blocked_ip
I can’t seem to figure out a way to not define the list twice. I understand there is a caddy module to get cloudflare IPs, but I don’t really want to use that. I’m just wondering if there is a generic way to re-use a list of addresses. The only thing I can think of is defining an environment variable with the list.
Following up here because I wanted to double check the env var handling; the problem isn’t with Caddy, the problem is with how the env vars are defined.
I’m not sure what mechanism you used. If you’re using Docker, how are you setting the env vars?
If you use Docker Compose, you can use yaml syntax like this:
Using | says “preserve newlines” (not that you have any) and - means “drop the trailing newline”.
If you’re using a .env file, it depends on the implementation of the env parser whether it preserves or drops the " (it should drop them for it to work properly as a list of args for Caddy). I think you have to omit the ", I think the .env parsing will keep reading the value until it reaches a non-escaped newline, including spaces. If you use quotes, I think it’s included in the actual value.