Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PROXY protocol support to tcp inbound #103

Merged
merged 3 commits into from
Aug 21, 2020
Merged

Add PROXY protocol support to tcp inbound #103

merged 3 commits into from
Aug 21, 2020

Conversation

lucifer9
Copy link
Member

This commit adds PROXY protocol (v1 & v2) support to tcp inbound ("network": "tcp" in streamSettings). So with a properly configured reverse proxy, we can see real client IPs, not lots of 127.0.0.1, in access log.

@RPRX RPRX self-requested a review August 19, 2020 14:58
Copy link
Contributor

@RPRX RPRX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

接收 PROXY protocol 时,没有相应 header 的请求将被拒绝,这里需要加一个可选开关。

@lucifer9
Copy link
Member Author

https://github.com/pires/go-proxyproto 这里的实现考虑了 passthrough 的情况。测试过不用反向代理或者haproxy不加 send-proxy 也正常。当然后者的情况log里就还是127.0.01了。

@kslr
Copy link
Contributor

kslr commented Aug 19, 2020

测试看起来坏掉了,等会到家修一修

@RPRX
Copy link
Contributor

RPRX commented Aug 19, 2020

https://github.com/pires/go-proxyproto 这里的实现考虑了 passthrough 的情况。测试过不用反向代理或者haproxy不加 send-proxy 也正常。当然后者的情况log里就还是127.0.01了。

根据 PROXY protocol 的原理,并不能完美区分发送方是否使用了 PROXY protocol(比如如果流量本身就有相同的头部,则会被误判)。这个库如何区分是否 PROXY protocol 需要研究,但如果 v2ray 只能同时接收它,则必定会导致:

  1. 客户端可以伪造 IP 和端口
  2. 强特征(轻易被主动探测)
  3. 可能的读取长度特征问题
  4. 可能的总体性能下降

所以加开关是必要的,比如 bool acceptProxyProtocol(至于开关的位置,则不一定在 tcpSettings 内)

@lucifer9
Copy link
Member Author

lucifer9 commented Aug 21, 2020

增加了相应的开关

          "tcpSettings": {
              "acceptProxyProtocol": true
          }

默认为 false,此时跟之前的处理方式一致,即不接受 PROXY 头。
设为 true 时前端必须传递 PROXY 头过来否则会断开连接。

@RPRX RPRX merged commit 5df1733 into v2fly:master Aug 21, 2020
@lucifer9 lucifer9 deleted the pp branch August 21, 2020 13:35
RPRX added a commit to RPRX/v2ray-vless that referenced this pull request Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants