Closed wolfsilver closed 1 year ago
Can you provide more detailed information? Anyway, the naive fork of forwardproxy doesn't seems to build on CI (with Go 1.21, Caddy v2.7.3).
Can you provide more detailed information? Anyway, the naive fork of forwardproxy doesn't seems to build on CI (with Go 1.21, Caddy v2.7.3).
use this dockerfile: The build was successful, but the client could not connect to the server
FROM caddy:builder-alpine as base
ENV CADDY_VERSION v2.7.3
RUN set -eux; xcaddy build \
--with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive \
--with github.com/caddyserver/transform-encoder \
--with github.com/caddy-dns/cloudflare \
--with github.com/ueffel/caddy-brotli \
--output /usr/bin/caddy
FROM alpine:3.18
RUN apk add --no-cache \
ca-certificates \
libcap \
mailcap
RUN set -eux; \
mkdir -p \
/config/caddy \
/data/caddy \
/etc/caddy \
/usr/share/caddy \
; \
wget -O /etc/caddy/Caddyfile "https://github.com/caddyserver/dist/raw/master/config/Caddyfile"; \
wget -O /usr/share/caddy/index.html "https://github.com/caddyserver/dist/raw/master/welcome/index.html"
# https://github.com/caddyserver/caddy/releases
COPY --from=base /usr/bin/caddy /usr/bin/caddy
RUN set -eux; \
setcap cap_net_bind_service=+ep /usr/bin/caddy; \
chmod +x /usr/bin/caddy; \
caddy version
# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME /config
ENV XDG_DATA_HOME /data
WORKDIR /config/caddy
CMD ["caddy", "run", "--config", "/config/caddy/Caddyfile", "--adapter", "caddyfile"]
I'm not familiar with Docker so I ran your build command directly, and the build failed.
2023/08/13 09:36:06 [INFO] Temporary folder: /tmp/buildenv_2023-08-13-0936.3832038719
2023/08/13 09:36:06 [INFO] Writing main module: /tmp/buildenv_2023-08-13-0936.3832038719/main.go
package main
import (
caddycmd "github.com/caddyserver/caddy/v2/cmd"
// plug in Caddy modules here
_ "github.com/caddyserver/caddy/v2/modules/standard"
_ "github.com/caddyserver/forwardproxy"
_ "github.com/caddyserver/transform-encoder"
_ "github.com/caddy-dns/cloudflare"
_ "github.com/ueffel/caddy-brotli"
)
func main() {
caddycmd.Main()
}
2023/08/13 09:36:06 [INFO] Initializing Go module
2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod init caddy
go: creating new go.mod: module caddy
go: to add module requirements and sums:
go mod tidy
2023/08/13 09:36:06 [INFO] Replace github.com/caddyserver/forwardproxy => github.com/klzgrad/forwardproxy@naive
2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod edit -replace github.com/caddyserver/forwardproxy=github.com/klzgrad/forwardproxy@naive
2023/08/13 09:36:06 [INFO] Pinning versions
2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2
go: added github.com/beorn7/perks v1.0.1
go: added github.com/caddyserver/caddy/v2 v2.7.3
go: added github.com/caddyserver/certmagic v0.19.1
go: added github.com/cespare/xxhash/v2 v2.2.0
go: added github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
go: added github.com/golang/mock v1.6.0
go: added github.com/golang/protobuf v1.5.3
go: added github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1
go: added github.com/google/uuid v1.3.0
go: added github.com/klauspost/cpuid/v2 v2.2.5
go: added github.com/libdns/libdns v0.2.1
go: added github.com/matttproud/golang_protobuf_extensions v1.0.1
go: added github.com/mholt/acmez v1.2.0
go: added github.com/miekg/dns v1.1.55
go: added github.com/onsi/ginkgo/v2 v2.9.5
go: added github.com/prometheus/client_golang v1.14.0
go: added github.com/prometheus/client_model v0.3.0
go: added github.com/prometheus/common v0.37.0
go: added github.com/prometheus/procfs v0.8.0
go: added github.com/quic-go/qpack v0.4.0
go: added github.com/quic-go/qtls-go1-20 v0.3.1
go: added github.com/quic-go/quic-go v0.37.3
go: added github.com/zeebo/blake3 v0.2.3
go: added go.uber.org/multierr v1.11.0
go: added go.uber.org/zap v1.25.0
go: added golang.org/x/crypto v0.11.0
go: added golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0
go: added golang.org/x/mod v0.11.0
go: added golang.org/x/net v0.12.0
go: added golang.org/x/sys v0.10.0
go: added golang.org/x/term v0.10.0
go: added golang.org/x/text v0.11.0
go: added golang.org/x/tools v0.10.0
go: added google.golang.org/protobuf v1.31.0
2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddyserver/transform-encoder github.com/caddyserver/caddy/v2
go: added github.com/buger/jsonparser v1.1.1
go: added github.com/caddyserver/transform-encoder v0.0.0-20230707173452-ec0c4fcc953b
2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddy-dns/cloudflare github.com/caddyserver/caddy/v2
go: added github.com/caddy-dns/cloudflare v0.0.0-20230807034102-74f004e1c1ab
go: added github.com/libdns/cloudflare v0.1.0
2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/ueffel/caddy-brotli github.com/caddyserver/caddy/v2
go: added github.com/andybalholm/brotli v1.0.5
go: added github.com/ueffel/caddy-brotli v1.3.0
2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v
go: trying upgrade to github.com/caddyserver/forwardproxy@v0.0.0-20211013034647-8c6ef2bd4a8f
go: added github.com/caddyserver/forwardproxy v0.0.0-20211013034647-8c6ef2bd4a8f
2023/08/13 09:36:08 [INFO] Build environment ready
2023/08/13 09:36:08 [INFO] Building Caddy
2023/08/13 09:36:08 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod tidy -e
2023/08/13 09:36:08 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath
# github.com/quic-go/quic-go/internal/handshake
/go/pkg/mod/github.com/quic-go/quic-go@v0.37.3/internal/handshake/crypto_setup.go:362:37: cannot use h.allow0RTT (variable of type bool) as tls.QUICSessionTicketOptions value in argument to h.conn.SendSessionTicket
2023/08/13 09:36:09 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-08-13-0936.3832038719
2023/08/13 09:36:09 [FATAL] exit status 1
Looks like my build fails with quic-go v0.37.3. quic-go has a v0.37.4 release where they say contains a "last-minute breaking API change". I'm not sure why it doesn't upgrade quic-go to the latest.
I guess there might be inconsistency between dependency versions, which caused caddy to go wrong.
Can you provide your build log or something (to see if it did build successfully)?
And if your build did go successfully, can you also try building and executing it outside of the docker? Maybe it was something caused by the docker?
By the way I just test the v2.7.3 caddy with my custom fork of forwardproxy [^1] (not in docker, because I'm not familiar with it), and it works fine.
Since I noticed that you build the caddy with several other features, I tried your command again, but replaced the forwardproxy fork with mine, and it built successfully too.
[^1]: The custom fork does nothing more than add a UoT support from sing-box and go version & several dependency updates.
I used https://github.com/zedifen/build-naive-caddy/releases/tag/caddy-v2.7.3-with-UoT with config below, and got same error
:443 {
@foo {
not {
not method CONNECT
not host xxx.test.com
}
}
handle @foo {
route {
forward_proxy {
basic_auth xxx xxx
hide_ip
hide_via
probe_resistance
}
file_server {
root /usr/share/caddy
}
}
}
handle {
abort
}
}
xxx.test.com {
@foo {
not {
not method CONNECT
not host xxx.test.com
}
}
handle @foo {
route {
forward_proxy {
basic_auth xxx xxx
hide_ip
hide_via
probe_resistance
}
file_server {
root /usr/share/caddy
}
}
}
handle {
abort
}
}
{"level":"error","ts":1691920821.8227491,"logger":"http.log.access.log5","msg":"handled request","request":{"xxxxxxxxxxxxxxxxxxxxxxx","method":"CONNECT","host":"www.gstatic.com:80","uri":"www.gstatic.com:80","headers":{"User-Agent":["nghttp2/1.39.2"],"Padding":["$+}!(+]#!!!!!!!!~~~"],"Accept-Encoding":["identity"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"xxx.test.com"}},"bytes_read":0,"user_id":"","duration":0.000074871,"size":562,"status":500,"resp_headers":{"Server":["Caddy"],"Alt-Svc":["h3=\":443\"; ma=2592000"],"Content-Type":["text/html; charset=UTF-8"]}}
Looks like your config file is not quite right. 😥 Why is :443
separate from xxx.test.com
?
Also, issue #546 has some discussion about the config, with some advice.
Here's my config file, modified a little from the one provided in project README/Wiki, maybe you can also use it as a reference:
{
order forward_proxy before file_server
}
:443, aa.example.com {
tls me@example.com
forward_proxy {
basic_auth someuser pass123456789
hide_ip
hide_via
probe_resistance
}
file_server {
browse
root /var/lib/caddy/htmls
}
}
this config works well with caddy 2.7.2.
change to your config, still not work.....
Sorry to hear that 😥. How about your OS / server environment? My server OSs are Debian 11 and Arch Linux. And caddy seems to work fine on both.
Sorry to hear that 😥. How about your OS / server environment? My server OSs are Debian 11 and Arch Linux. And caddy seems to work fine on both.
Host is Debian 11 and the docker image is alpine. changing the image to Debian still doesn't work...
debug log:
{
"level": "debug",
"ts": 1692006007.7969418,
"logger": "http.log.error.log5",
"msg": "ResponseWriter doesn't implement http.Flusher",
"request": {
"remote_ip": "xx",
"remote_port": "49515",
"client_ip": "xx",
"proto": "HTTP/2.0",
"method": "CONNECT",
"host": "cp.cloudflare.com:80",
"uri": "cp.cloudflare.com:80",
"headers": {
"Padding": [
"';*&@<&*<\"*,;?(@XXXXXXX"
],
"Proxy-Authorization": [
"Basic xx"
]
},
"tls": {
"resumed": false,
"version": 772,
"cipher_suite": 4865,
"proto": "h2",
"server_name": "xx.com"
}
},
"duration": 0.0000587,
"status": 500,
"err_id": "yte01aej5",
"err_trace": "forwardproxy.(*Handler).ServeHTTP (forwardproxy.go:297)"
}
not method CONNECT
你自己配置造成的,我不明白为什么这么配置,但已经与本项目没什么关系了。
not { not method CONNECT not host xxx.test.com } 绑定的域名或者connect方法才走forward_proxy,其他的abort,全走proxy也是一样的错误
找到问题了,但是不知道为啥,配置里还加了log,以为没有影响就没有贴出来 加上log指令就会异常
{
order forward_proxy before file_server
}
:443, aa.example.com {
tls me@example.com
log {
output stdout
}
forward_proxy {
basic_auth someuser pass123456789
hide_ip
hide_via
probe_resistance
}
file_server {
browse
root /var/lib/caddy/htmls
}
}
So it looks like currently the forwardproxy's logging will cause error?
Hey I face the same issue like you, the Caddyfile work fine with caddy v2.6.2, but when apply to 2.7.3 it cant work anymore...
I didnt try to comment "log" part in Caddyfile, I just switch to the caddy v2.6.2 which was previously compiled on another machine with the same arch, and everything goes well....
My Caddyfile looks like this:
{
http_port 80
https_port 443
servers {
metrics
log_credentials
}
}
:443, ***:443 {
tls ***@gmail.com
log {
output file /var/log/caddy.log
format console
}
route {
forward_proxy {
basic_auth someuser pass123456789
hide_ip
hide_via
probe_resistance
}
reverse_proxy https://*** {
header_up Host {upstream_hostport}
header_up X-Forwarded-Host {host}
}
}
}
I format the logfile for the purpose to count the traffic for different user. If your @wolfsilver operation about "log" part can work, may this means that the new version caddy or forwardproxy is not compatible with the log syntax before @zedifen ?
I tried to comment "log" part, it looks normal now... Besides, I tried caddy v2.7.2 not compatible with log{} too, and perhaps the lasest compatible version is v2.6.4. Hope to follow up this issue cause logfile is the key to statistical traffic :(
it might be a log{} part problem. I have put a naiveproxy and a v2ray both behind a same Caddyfile (naive in 1st section and v2ray in 2nd section), both with log{} part of same grammar , but the v2ray part works fine ,while naive part fails to works. now I comment out the log part in naive section , but with the log{} part in v2ray unchanged ,now both of them works fine.
我对 Docker 不熟悉,所以我直接运行了你的构建命令,但构建失败了。
2023/08/13 09:36:06 [INFO] Temporary folder: /tmp/buildenv_2023-08-13-0936.3832038719 2023/08/13 09:36:06 [INFO] Writing main module: /tmp/buildenv_2023-08-13-0936.3832038719/main.go package main import ( caddycmd "github.com/caddyserver/caddy/v2/cmd" // plug in Caddy modules here _ "github.com/caddyserver/caddy/v2/modules/standard" _ "github.com/caddyserver/forwardproxy" _ "github.com/caddyserver/transform-encoder" _ "github.com/caddy-dns/cloudflare" _ "github.com/ueffel/caddy-brotli" ) func main() { caddycmd.Main() } 2023/08/13 09:36:06 [INFO] Initializing Go module 2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod init caddy go: creating new go.mod: module caddy go: to add module requirements and sums: go mod tidy 2023/08/13 09:36:06 [INFO] Replace github.com/caddyserver/forwardproxy => github.com/klzgrad/forwardproxy@naive 2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod edit -replace github.com/caddyserver/forwardproxy=github.com/klzgrad/forwardproxy@naive 2023/08/13 09:36:06 [INFO] Pinning versions 2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2 go: added github.com/beorn7/perks v1.0.1 go: added github.com/caddyserver/caddy/v2 v2.7.3 go: added github.com/caddyserver/certmagic v0.19.1 go: added github.com/cespare/xxhash/v2 v2.2.0 go: added github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 go: added github.com/golang/mock v1.6.0 go: added github.com/golang/protobuf v1.5.3 go: added github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 go: added github.com/google/uuid v1.3.0 go: added github.com/klauspost/cpuid/v2 v2.2.5 go: added github.com/libdns/libdns v0.2.1 go: added github.com/matttproud/golang_protobuf_extensions v1.0.1 go: added github.com/mholt/acmez v1.2.0 go: added github.com/miekg/dns v1.1.55 go: added github.com/onsi/ginkgo/v2 v2.9.5 go: added github.com/prometheus/client_golang v1.14.0 go: added github.com/prometheus/client_model v0.3.0 go: added github.com/prometheus/common v0.37.0 go: added github.com/prometheus/procfs v0.8.0 go: added github.com/quic-go/qpack v0.4.0 go: added github.com/quic-go/qtls-go1-20 v0.3.1 go: added github.com/quic-go/quic-go v0.37.3 go: added github.com/zeebo/blake3 v0.2.3 go: added go.uber.org/multierr v1.11.0 go: added go.uber.org/zap v1.25.0 go: added golang.org/x/crypto v0.11.0 go: added golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 go: added golang.org/x/mod v0.11.0 go: added golang.org/x/net v0.12.0 go: added golang.org/x/sys v0.10.0 go: added golang.org/x/term v0.10.0 go: added golang.org/x/text v0.11.0 go: added golang.org/x/tools v0.10.0 go: added google.golang.org/protobuf v1.31.0 2023/08/13 09:36:06 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddyserver/transform-encoder github.com/caddyserver/caddy/v2 go: added github.com/buger/jsonparser v1.1.1 go: added github.com/caddyserver/transform-encoder v0.0.0-20230707173452-ec0c4fcc953b 2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/caddy-dns/cloudflare github.com/caddyserver/caddy/v2 go: added github.com/caddy-dns/cloudflare v0.0.0-20230807034102-74f004e1c1ab go: added github.com/libdns/cloudflare v0.1.0 2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v github.com/ueffel/caddy-brotli github.com/caddyserver/caddy/v2 go: added github.com/andybalholm/brotli v1.0.5 go: added github.com/ueffel/caddy-brotli v1.3.0 2023/08/13 09:36:07 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go get -d -v go: trying upgrade to github.com/caddyserver/forwardproxy@v0.0.0-20211013034647-8c6ef2bd4a8f go: added github.com/caddyserver/forwardproxy v0.0.0-20211013034647-8c6ef2bd4a8f 2023/08/13 09:36:08 [INFO] Build environment ready 2023/08/13 09:36:08 [INFO] Building Caddy 2023/08/13 09:36:08 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go mod tidy -e 2023/08/13 09:36:08 [INFO] exec (timeout=-2562047h47m16.854775808s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath # github.com/quic-go/quic-go/internal/handshake /go/pkg/mod/github.com/quic-go/quic-go@v0.37.3/internal/handshake/crypto_setup.go:362:37: cannot use h.allow0RTT (variable of type bool) as tls.QUICSessionTicketOptions value in argument to h.conn.SendSessionTicket 2023/08/13 09:36:09 [INFO] Cleaning up temporary folder: /tmp/buildenv_2023-08-13-0936.3832038719 2023/08/13 09:36:09 [FATAL] exit status 1
看来我的 quic-go v0.37.3 构建失败了。quic-go 有一个v0.37.4版本,他们说其中包含“最后一刻的重大 API 更改”。我不确定为什么它不将 quic-go 升级到最新版本。
我猜测可能是依赖版本不一致,导致caddy出错。
您能否提供您的构建日志或其他内容(以查看它是否构建成功)?
如果您的构建确实成功,您是否也可以尝试在 docker 之外构建并执行它?也许是docker造成的?
Ubuntu 22 构建可以通过
After updating caddy
to the latest version 2.7.4
, I also encountered a similar issue.
If add the log
directive to the site block
in Caddyfile
:
{
admin off
order forward_proxy before file_server
log {
output file /var/log/caddy/caddy.log
level INFO
}
auto_https off
servers :443 {
protocols h1 h2 h2c h3
}
}
# Common
(common) {
encode gzip zstd
root * /var/www/html
file_server
handle_errors {
abort
}
}
# Header
(header) {
header {
# enable HSTS
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}
# Forward proxy
(forward_naive_proxy) {
forward_proxy {
basic_auth user password
hide_ip
hide_via
probe_resistance
}
}
# HTTP
:80 {
redir https://{host}{uri} permanent
}
# HTTPS
:443, *.example.com {
tls /etc/ssl/caddy/fullchain.cer /etc/ssl/caddy/private.key
import common
import header
import forward_naive_proxy
log {
output file /var/log/caddy/access.json
format json
level INFO
}
}
Then run:
naiveproxy --listen=socks://127.0.0.1:8088 --proxy=https://user:password@example.com --log
The client will have the following error:
[0818/203822.118436:INFO:naive_proxy_bin.cc(561)] Listening on 127.0.0.1:8088
[0818/203831.377282:INFO:naive_connection.cc(273)] Connection 1 to www.gstatic.com:80
[0818/203832.034268:INFO:naive_proxy.cc(193)] Connection 1 closed: ERR_HTTP2_PROTOCOL_ERROR
If delete or comment the log
directive in the site block
:
{
admin off
order forward_proxy before file_server
log {
output file /var/log/caddy/caddy.log
level INFO
}
auto_https off
servers :443 {
protocols h1 h2 h2c h3
}
}
# Common
(common) {
encode gzip zstd
root * /var/www/html
file_server
handle_errors {
abort
}
}
# Header
(header) {
header {
# enable HSTS
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}
# Forward proxy
(forward_naive_proxy) {
forward_proxy {
basic_auth user password
hide_ip
hide_via
probe_resistance
}
}
# HTTP
:80 {
redir https://{host}{uri} permanent
}
# HTTPS
:443, *.example.com {
tls /etc/ssl/caddy/fullchain.cer /etc/ssl/caddy/private.key
import common
import header
import forward_naive_proxy
# log {
# output file /var/log/caddy/access.json
# format json
# level INFO
# }
}
Then restart the caddy server
, everything works fine.
The version I'm using is:
# naiveproxy --version
naive 114.0.5735.91
I'm experiencing this issue as well. It seems that we'll have to await an upstream fix.
``` 2023-08-XXTXX:XX:XXZ ERROR http.log.error ResponseWriter doesn't implement http.Flusher { "request": { "remote_ip": "XXXX", "remote_port": "XXXX", "client_ip": "XXXX", "proto": "HTTP/2.0", "method": "CONNECT", "host": "XXXX", "uri": "XXXX", "headers": { "Padding": [ "XXXX" ], "Padding-Type-Request": [ "1, 0" ], "Proxy-Authorization": [] }, "tls": { "resumed": X, "version": X, "cipher_suite": X, "proto": "h2", "server_name": "XXX" } }, "duration": X, "status": 500, "err_id": "XXXX", "err_trace": "forwardproxy.(*Handler).ServeHTTP (forwardproxy.go:297)" } ```
Additionally, it's advisable to refine the issue's title for better clarity, making it easier for others to search.
Is this only reproducible with the log
directive?
Why would you want to log your proxy traffic? It's a privacy risk.
Is this only reproducible with the
log
directive?Why would you want to log your proxy traffic? It's a privacy risk.
No other directives were found to be affected
Why was this issue closed without being resolved?
update to 2.7.3, reporting status code 500