Squid im Intercept-Modus via TPROXY mit nftables: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 5: | Zeile 5: | ||
* Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51 | * Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51 | ||
* Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen. | * Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen. | ||
| − | * Die Original-Ziel-IP soll erhalten bleiben – daher TPROXY | + | * Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall nur DNAT durchgeführt, und **TPROXY erfolgt ausschließlich auf dem Proxyserver**. |
| − | * Die Firewall nutzt nftables und | + | * Die Firewall nutzt nftables für NAT. |
| + | * Der Proxyserver setzt nftables und Policy Routing für TPROXY ein. | ||
== nftables-Regeln auf der Firewall == | == nftables-Regeln auf der Firewall == | ||
| + | ;NAT-Tabelle und Weiterleitung der Verbindungen an den Proxy: | ||
| + | *nft add table ip nat | ||
| + | *nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }' | ||
| + | *nft add rule ip nat prerouting tcp dport 80 dnat to 10.88.113.51:3029 | ||
| + | *nft add rule ip nat prerouting tcp dport 443 dnat to 10.88.113.51:3030 | ||
| + | |||
| + | == nftables-Regeln auf dem Proxyserver == | ||
;Tabelle und Kette erstellen: | ;Tabelle und Kette erstellen: | ||
*nft add table inet tproxy | *nft add table inet tproxy | ||
*nft add chain inet tproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }' | *nft add chain inet tproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }' | ||
| − | ;TPROXY-Regeln für HTTP und HTTPS | + | ;TPROXY-Regeln für HTTP und HTTPS: |
| − | *nft add rule inet tproxy prerouting ip daddr | + | *nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3029 tproxy to :3029 mark set 1 |
| − | *nft add rule inet tproxy prerouting ip daddr | + | *nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3030 tproxy to :3030 mark set 1 |
| − | == Policy Routing auf | + | == Policy Routing auf dem Proxyserver == |
| − | |||
*ip rule add fwmark 1 lookup 100 | *ip rule add fwmark 1 lookup 100 | ||
*ip route add local 0.0.0.0/0 dev lo table 100 | *ip route add local 0.0.0.0/0 dev lo table 100 | ||
| − | == Notwendige Kernel-Module == | + | == Notwendige Kernel-Module auf dem Proxyserver == |
| − | |||
*modprobe nf_conntrack | *modprobe nf_conntrack | ||
*modprobe nf_tproxy_ipv4 | *modprobe nf_tproxy_ipv4 | ||
| Zeile 44: | Zeile 50: | ||
== Squid-Rechte anpassen == | == Squid-Rechte anpassen == | ||
| − | |||
*setcap cap_net_bind_service,cap_net_admin=eip /usr/sbin/squid | *setcap cap_net_bind_service,cap_net_admin=eip /usr/sbin/squid | ||
== Test & Diagnose == | == Test & Diagnose == | ||
| − | + | ;Firewall: | |
| + | *nft list chain ip nat prerouting | ||
| + | |||
| + | ;Proxyserver: | ||
*nft list chain inet tproxy prerouting | *nft list chain inet tproxy prerouting | ||
| − | |||
| − | |||
*ip rule show | *ip rule show | ||
*ip route show table 100 | *ip route show table 100 | ||
| − | |||
| − | |||
*tail -f /var/log/squid/access.log | *tail -f /var/log/squid/access.log | ||
*tail -f /var/log/squid/cache.log | *tail -f /var/log/squid/cache.log | ||
== Hinweise == | == Hinweise == | ||
| − | + | * Die Weiterleitung funktioniert nur, wenn keine zusätzlichen NAT- oder Firewall-Regeln die Pakete blockieren. | |
| − | + | * Für HTTPS müssen die Clients die Root-CA des Proxyservers akzeptieren, wenn SSL-Bump aktiviert ist. | |
| − | + | * Diese Methode ist technisch aufwendig – in produktiven Umgebungen sollte, wenn möglich, ein expliziter Proxy via WPAD bevorzugt werden. | |
| − | |||
| − | Diese Methode ist technisch aufwendig – in produktiven Umgebungen sollte, wenn möglich, ein expliziter Proxy via WPAD bevorzugt werden. | ||
Version vom 24. April 2025, 04:01 Uhr
Squid im Intercept-Modus via TPROXY mit nftables
Voraussetzungen
- Die Firewall hat die interne IP 172.17.113.1
- Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51
- Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen.
- Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall nur DNAT durchgeführt, und **TPROXY erfolgt ausschließlich auf dem Proxyserver**.
- Die Firewall nutzt nftables für NAT.
- Der Proxyserver setzt nftables und Policy Routing für TPROXY ein.
nftables-Regeln auf der Firewall
- NAT-Tabelle und Weiterleitung der Verbindungen an den Proxy
- nft add table ip nat
- nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
- nft add rule ip nat prerouting tcp dport 80 dnat to 10.88.113.51:3029
- nft add rule ip nat prerouting tcp dport 443 dnat to 10.88.113.51:3030
nftables-Regeln auf dem Proxyserver
- Tabelle und Kette erstellen
- nft add table inet tproxy
- nft add chain inet tproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }'
- TPROXY-Regeln für HTTP und HTTPS
- nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3029 tproxy to :3029 mark set 1
- nft add rule inet tproxy prerouting ip daddr 10.88.113.51 tcp dport 3030 tproxy to :3030 mark set 1
Policy Routing auf dem Proxyserver
- ip rule add fwmark 1 lookup 100
- ip route add local 0.0.0.0/0 dev lo table 100
Notwendige Kernel-Module auf dem Proxyserver
- modprobe nf_conntrack
- modprobe nf_tproxy_ipv4
- modprobe nf_tproxy_ipv6
- modprobe xt_TPROXY
Squid-Setup auf dem Proxyserver
Squid muss mit TPROXY-Support kompiliert sein (mit --enable-linux-netfilter)
Squid-Konfiguration anpassen:
http_port 3029 tproxy https_port 3030 tproxy ssl-bump cert=/etc/squid/certs/proxy.pem key=/etc/squid/certs/proxy.key
- Optional
- SSL-Bump konfigurieren:
ssl_bump peek all ssl_bump bump all sslproxy_cert_error allow all sslproxy_flags DONT_VERIFY_PEER
Squid-Rechte anpassen
- setcap cap_net_bind_service,cap_net_admin=eip /usr/sbin/squid
Test & Diagnose
- Firewall
- nft list chain ip nat prerouting
- Proxyserver
- nft list chain inet tproxy prerouting
- ip rule show
- ip route show table 100
- tail -f /var/log/squid/access.log
- tail -f /var/log/squid/cache.log
Hinweise
- Die Weiterleitung funktioniert nur, wenn keine zusätzlichen NAT- oder Firewall-Regeln die Pakete blockieren.
- Für HTTPS müssen die Clients die Root-CA des Proxyservers akzeptieren, wenn SSL-Bump aktiviert ist.
- Diese Methode ist technisch aufwendig – in produktiven Umgebungen sollte, wenn möglich, ein expliziter Proxy via WPAD bevorzugt werden.