源IP透传proxy protocol 的完整实现
2021-01-05 11:11:19
林夏
1.1. 需求说明及解决方案思路
第一层F5 LTM四层负载,经过nat66/nat44/nat64转址后无法进行真实客户端溯源。故需在第一层F5 LTM上将客户端真实地址通过proxy protocol插入,第二层F5 LTM可读取到客户端的真实地址,并插入到XFF中以确保真实服务器可以进行溯源。
Proxy protocols的原理是会在三次握手后的第一个PSH包中擦入客户端的源IP信息,因此对第二层F5的需求是需要将三次握手后的第一个PSH中取出源ip地址,插入到XFF,并且消除掉这个数据包,不能往后台服务器进行转发。
1.2. 详细说明
1. 创建iRules,确保将真实客户端地址插入到tcp proxy protocol
ltm rule tcp-proxy-protocol { when CLIENT_ACCEPTED { set proxyheader "PROXY " if {[IP::version] eq 4} { append proxyheader "TCP4 " } else { append proxyheader "TCP6 " } append proxyheader "[IP::remote_addr]PPP [IP::local_addr] [TCP::remote_port] [TCP::local_port]\r\n" } when SERVER_CONNECTED { log local0. "server connect" TCP::respond $proxyheader } } |
2. 在第一层LTM的VS上调用相关配置
ltm virtual VIP1 { destination 192.168.199.88:https ip-protocol tcp mask 255.255.255.255 pool vip1-pool profiles { tcp { } } rules { tcp-proxy-protocol } source 0.0.0.0/0 source-address-translation { type automap } translate-address enabled translate-port enabled vs-index 28 } |
3. 第二层LTM上创建iRules,提取tcp proxy并插入到XFF中
ltm rule tcp-proxy-protocol-recive { when CLIENT_ACCEPTED { TCP::collect log local0. "conn established:[IP::client_addr]:[TCP::client_port] ,dport:[TCP::local_port]" } when CLIENT_DATA { #if { [TCP::payload] starts_with "PROXY TCP" } { log local0. "conn date1:[TCP::payload]" set srcip [findstr [TCP::payload] "PROXY TCP" 10 "PPP" ] log local0. "srcip:$srcip" TCP::payload replace 0 [TCP::payload length] "" log local0. "conn date2:[TCP::payload]" #} TCP::release } when HTTP_REQUEST { if { [info exists srcip] } { HTTP::header insert "X-Forwarded-For" $srcip log local0. "Real client ip is $srcip" } } } |
4. 在VS中调用相关配置
ltm virtual VIP2 { creation-time 2020-12-03:15:28:42 destination 192.168.199.100:https ip-protocol tcp last-modified-time 2020-12-03:17:19:55 mask 255.255.255.255 pool DVWA-80 profiles { clientssl { context clientside } http { } tcp { } } rules { tcp-proxy-protocol-recive } serverssl-use-sni disabled source 0.0.0.0/0 source-address-translation { type automap } translate-address enabled translate-port enabled vs-index 15 } |
1.3. 测试通过场景
1. 单栈V4场景(双层F5全v4)- 第二层F5上处理明文http流量
2. 单栈V4场景(双层F5全v4)- 第二层F5上处理密文https流量
3. 单栈V6场景(双层F5全v6)- 第二层F5上处理明文http流量
4. 单栈V6场景(双层F5全v6)- 第二层F5上处理密文https流量
5. 双栈场景(nat64)- 第二层F5上处理明文http流量
6. 双栈场景(nat64)- 第二层F5上处理密文https流量
发布评论 加入社群
Will Tang
2021-01-12 12:53:10
0
不错,很实用!
林夏
2021-03-01 20:17:18
0
那是
Brian
2021-11-10 09:37:48
0
太强了
相关文章

博文精选 | 金融级分布式交易的技术路径
F5小安
2022-06-07 17:58:37 758

F5分布式数据库增强型架构
王亚军
2021-06-21 10:04:36 1221

F5助力金融科技
熊平
2020-06-25 22:00:37 1375

回复评论
发布评论