caddy icon indicating copy to clipboard operation
caddy copied to clipboard

core: add modular `network_proxy` support

Open mohammed90 opened this issue 1 year ago • 1 comments

The PR #5369 introduced support for the standard env vars HTTP_PROXY, HTTPS_PROXY, and NO_PROXY in the reverse_proxy handler. The ACME client in Caddy has always respected the vars. The issue #6111 shows a need for configurable forward-proxy outside the env vars due to the global state of env vars.

The post (https://caddy.community/t/routing-acme-requests-via-http-proxy/24363) in the Caddy forum shows a need for forward-proxy support for ACME (external requests) but not for reverse-proxy upstreams. Again, the global state nature of the env vars impedes any effort to separate those concerns.

To brainstorm the best solution, I'm introducing modular approach, where the proxy address can be explicitly configured via module and falls back to env var. Discussion and iteration on this PR is necessary to ensure a common satisfactory solution is reached. I haven't wired up the Caddyfile parts.

CC/ @ImpostorKeanu

Note if this approach is acceptable, the ForwardProxyURL field will be deprecated in favor of the "from": "url" module.

TODO:

  • [x] Caddyfile
  • [x] Tests

mohammed90 avatar Jun 14 '24 23:06 mohammed90

Slick! I support everything about this!

ImpostorKeanu avatar Jun 15 '24 09:06 ImpostorKeanu

I forgot about this PR. @mholt, @francislavoie, should we move it to 2.10? I'm fine either way.

mohammed90 avatar Dec 29 '24 09:12 mohammed90

Hm, yeah, that might be best. Thanks for updating and we'll get back to this soon!

mholt avatar Dec 30 '24 19:12 mholt

This chages seems to have broken the existing forward_proxy_url usage with panic:

panic: reflect: call of reflect.Value.Type on zero Value
goroutine 1 [running]:
reflect.Value.abiTypeSlow({0x0?, 0x0?, 0x0?})
	reflect/value.go:2400 +0xee
reflect.Value.typeSlow({0x0?, 0x0?, 0x8?})
	reflect/value.go:2388 +0x1d
reflect.Value.Type(...)
	reflect/value.go:2383
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:181 +0xee
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*HTTPTransport).NewTransport(0xc000441a40, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/httptransport.go:356 +0x80f
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*HTTPTransport).Provision(0xc000441a40, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/httptransport.go:181 +0xc5
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:410 +0x755
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:468 +0xf0
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:209 +0x426
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).Provision(0xc00077e960, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:241 +0x2b5

CzBiX avatar Apr 27 '25 02:04 CzBiX

This chages seems to have broken the existing forward_proxy_url usage with panic:

panic: reflect: call of reflect.Value.Type on zero Value
goroutine 1 [running]:
reflect.Value.abiTypeSlow({0x0?, 0x0?, 0x0?})
	reflect/value.go:2400 +0xee
reflect.Value.typeSlow({0x0?, 0x0?, 0x8?})
	reflect/value.go:2388 +0x1d
reflect.Value.Type(...)
	reflect/value.go:2383
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:181 +0xee
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*HTTPTransport).NewTransport(0xc000441a40, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/httptransport.go:356 +0x80f
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*HTTPTransport).Provision(0xc000441a40, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/httptransport.go:181 +0xc5
github.com/caddyserver/caddy/v2.Context.LoadModuleByID({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x4, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:410 +0x755
github.com/caddyserver/caddy/v2.Context.loadModuleInline({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:468 +0xf0
github.com/caddyserver/caddy/v2.Context.LoadModule({{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, 0x0}, ...}, ...)
	github.com/caddyserver/caddy/[email protected]/context.go:209 +0x426
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).Provision(0xc00077e960, {{0x1ed44f8, 0xc0002269c0}, 0xc0001fc690, 0xc0002073b0, {0xc000259b40, 0x3, 0x4}, {0x0, 0x0, ...}, ...})
	github.com/caddyserver/caddy/[email protected]/modules/caddyhttp/reverseproxy/reverseproxy.go:241 +0x2b5

Fixed in https://github.com/caddyserver/caddy/commit/737936c06be001a40c2d743d17d1e3df148408f0

mohammed90 avatar Apr 27 '25 06:04 mohammed90

Thanks @mohammed90 !

mholt avatar Apr 28 '25 15:04 mholt