|
Feature: TPROXY version 4.1+ Support
Contents
SponsorThis feature was Sponsored by Balabit and developed by Laszlo Attilla Toth and AmosJeffries. Production tested and debugged with the help of Krisztian Kovacs and Nicholas Ritter. WCCPv2 configuration is derived from testing by Steven Wilton and Adrian Chadd. It has not changed significantly since older TPROXY.
Minimum Requirements (IPv6 and IPv4)
Squid ConfigurationConfigure build options ./configure --enable-linux-netfilter squid.conf settings http_port 3128 http_port 3129 tproxy
Linux Kernel Configuration
NF_CONNTRACK=m NETFILTER_TPROXY=m NETFILTER_XT_MATCH_SOCKET=m NETFILTER_XT_TARGET_TPROXY=m So far we have this:
Routing configurationThe routing features in your kernel also need to be configured to enable correct handling of the intercepted packets. Both arriving and leaving your system. # IPv4-only ip -f inet rule add fwmark 1 lookup 100 ip -f inet route add local default dev eth0 table 100 # IPv6-only ip -f inet6 rule add fwmark 1 lookup 100 ip -f inet6 route add local default dev eth0 table 100 Every OS has different security and limitations around what you can do here.
On each boot startup set: echo 1 > /proc/sys/net/ipv4/ip_forward echo 0 > /proc/sys/net/ipv4/conf/default/rp_filter echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter Or configure /etc/sysctl.conf: net.ipv4.ip_forward = 1 net.ipv4.conf.default.rp_filter = 0 net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.eth0.rp_filter = 0
Some routing problems to be aware of
iptables Configuration
iptables on a Router device
Setup a chain DIVERT to mark packets iptables -t mangle -N DIVERT iptables -t mangle -A DIVERT -j MARK --set-mark 1 iptables -t mangle -A DIVERT -j ACCEPT Use DIVERT to prevent existing connections going through TPROXY twice: iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT Mark all other (new) packets and use TPROXY to pass into Squid: iptables -t mangle -A PREROUTING -p tcp --dport 80 -j TPROXY --tproxy-mark 0x1/0x1 --on-port 3129
ebtables on a Bridging deviceYou need to follow all the steps for setting up the Squid box as a router device. These bridging rules are additional steps to move packets from bridging mode to routing mode:
ebtables -t broute -A BROUTING -i $CLIENT_IFACE -p ipv6 --ip6-proto tcp --ip6-dport 80 -j redirect --redirect-target DROP ebtables -t broute -A BROUTING -i $CLIENT_IFACE -p ipv4 --ip-proto tcp --ip-dport 80 -j redirect --redirect-target DROP ebtables -t broute -A BROUTING -i $INET_IFACE -p ipv6 --ip6-proto tcp --ip6-sport 80 -j redirect --redirect-target DROP ebtables -t broute -A BROUTING -i $INET_IFACE -p ipv4 --ip-proto tcp --ip-sport 80 -j redirect --redirect-target DROP cd /proc/sys/net/bridge/ for i in * do echo 0 > $i done unset i
Bypassing TPROXY interceptAs always, bypassing the firewall rules is always an option. They need to go first, naturally.
If you do not understand how to do that or what to write in the bypass rules, please locate any beginners guide on iptables or ebtables and read up on how to operate them.
SELINUX Policy tuningOn Linux versions with selinux enabled you also need to tune the selinux policy to allow Squid to use TPROXY. By default the SELINUX policy for Squid denies some of the operations needed for TPROXY. You can tune the policy to allow this by setting a couple selinux booleans: setsebool squid_connect_any=yes setsebool squid_use_tproxy=yes If your version of the selinux policy is missing any of these then see the troubleshooting section for alternative approaches.
WCCP Configuration (only if you use WCCP)
squid.confIt is highly recommended that these definitions be used for the two wccp services, otherwise things will break if you have more than one cache (specifically, you will have problems when the a web server's name resolves to multiple ip addresses). wccp2_router $ROUTERIP wccp2_forwarding_method gre wccp2_return_method gre wccp2_service dynamic 80 wccp2_service_info 80 protocol=tcp flags=src_ip_hash priority=240 ports=80 wccp2_service dynamic 90 wccp2_service_info 90 protocol=tcp flags=dst_ip_hash,ports_source priority=240 ports=80
Router configOn the router, you need to make sure that all traffic going to/from the customer will be processed by _both_ WCCP rules. The way we implement this is to apply:
For Example: interface GigabitEthernet0/3.100 description ADSL customers encapsulation dot1Q 502 ip address x.x.x.x y.y.y.y ip wccp 80 redirect in ip wccp 90 redirect out interface GigabitEthernet0/3.101 description Dialup customers encapsulation dot1Q 502 ip address x.x.x.x y.y.y.y ip wccp 80 redirect in ip wccp 90 redirect out interface GigabitEthernet0/3.102 description proxy servers encapsulation dot1Q 506 ip address x.x.x.x y.y.y.y ip wccp redirect exclude in
Single Squid behind WCCP interceptor
Cluster of Sibling Squid behind WCCP interceptorWhen two sibling peers are both behind a WCCP interception gateway and using TPROXY to spoof the client IP, the WCCP gateway will get confused by two identical sources and redirect packets at the wrong sibling. This is now resolved by adding the no-tproxy flag to the cluster sibling cache_peer lines. This disables TPROXY spoofing on requests which are received through another peer in the cluster. cache_peer ip.of.peer sibling 3128 0 no-tproxy ...
Troubleshooting
Squid not spoofing the client IPCould be a few things. Check cache.log for messages like those listed here in Troubleshooting.
Stopping full transparency: Error enabling needed capabilities.Something went wrong while setting advanced privileges. What exactly, we don't know at this point. Unfortunately its not logged anywhere either. Perhaps your syslog or /var/log/messages log will have details recorded by the OS.
Stopping full transparency: Missing needed capability support.libcap support appears to be missing. The library needs to be built into Squid so a rebuild is required after installed the related packages for your system.
commBind: cannot bind socket FD X to X.X.X.X: (99) cannot assign requested addressThis error has many reasons for occurring. It might be seen repeatedly when Squid is running with TPROXY configured:
It may also be seen only at startup due to unrelated issues:
Traffic going through Squid but the timing outThis is usually seen when the network design prevents packets coming back to Squid.
Timeouts with Squid not running in the router directly
If your network topology uses a squid box sitting the inside the router which passes packets to Squid. Then you will need to explicitly add some additional configuration. The WCCPv2 example is provided for people using Cisco boxes. For others we can't point to exact routing configuration since it will depend on your router. But you will need to figure out some rule(s) which identify the Squid outbound traffic. Dedicated router interface, service groups, TOS set by Squid tcp_outgoing_tos, and MAC source have all been found to be useful under specific situations. IP address rules are the one thing guaranteed to fail.
Timeouts with Squid running as a bridge or multiple-NICWhen using the bridge configuration or when multi-homing the system care needs to be taken that the default route is correct and will route packets to the Internet. Ideally there is only one default route, but for a bridge with routing enabled or for multi-homed systems there may be multiple.
Wccp2 dst_ip_hash packet loops
Referring to the wccps_service_info settings detailed above. First method:
Ties a particular web server to a particular cache Second method:
Ties a particular client to a particular cache When using TPROXY the second method must be used. The problem with the first method is this sequence of events which starts to occur: Say a client wants to access http://some-large-site, their PC resolves the address and gets x.x.x.1
This cache takes the GET and does another DNS lookup of that host. This time it resolves to x.x.x.2
selinux policy denialsWhen configuring TPROXY support on Fedora 12 using the Squid shipped with Fedora selinux initially blocked Squid from usng the TPROXY feature. The quick fix is disabling selinux entirely, but this is not generally desired. A more permanent fix until the squid part of the selinux policy is updated is to make a custom selinux policy module allowing Squid access to the net operations is needs for TPROXY. # Temporarily set eslinux in permissive mode and test.. setenforce 0 service squid start # Make a request via Squid and verity that it works. service squid stop setenforce 1 # build & install selinux module based on the denials seen grep AVC.*squid /var/log/audit/autdit.log | audit2allow -M squidtproxy semodule -i squidtproxy.pp Alternatively you can download and install a precomposed policy module from http://www./code/squidtproxy.te wget http://www./code/squidtproxy.te checkmodule -M -m -o squidtproxy.mod squidtproxy.te semodule_package -o squidtproxy.pp squidtproxy.mod semodule -i squidtproxy.pp setsebool -P squid_connect_any true
References
|
|
|