Apache Traffic Server
Apache Traffic Server
27 Feb 2013
at ApacheCon NA 2013
Speaker
Alan M. Carroll, PMC
Started working on Traffic Server in summer 2010.
Implemented
Transparency
IPv6
Other stuff
27 Feb 2013
Goal
A starting point for deploying ATS as a
transparent HTTP proxy
Provide sample scripts
Help you understand what the commands in
the scripts are intended to accomplish
Guide to useful tools
27 Feb 2013
Outline
Basic theory
Drill down to increasing detail for deployment
Trouble shooting
Commands not discussed directly
Not really helpful
You can look ahead to appendix scripts and ask
questions on them that relate to slides
27 Feb 2013
BASIC THEORY
27 Feb 2013
Transparency Basics
Quick review to avoid misunderstandings
Use standard client / server terminology
Client initiates connection
Server receives connection
Users think this is how it works:
Transparency contributes to this
illusion in the presence of proxies
27 Feb 2013
27 Feb 2013
Proxying
You want to modify network traffic
Use a proxy to intercept connections
If just monitor and track, not modify, use a sniffer.
Much easier.
27 Feb 2013
27 Feb 2013
Proxy Types
Address used by proxy
Client connects to
Proxy Address
Client connects to
Server Address
Explicit Proxy
(Not transparent)
Inbound transparent
Outbound transparent
Fully transparent
27 Feb 2013
10
HTTP Proxies
ATS is an HTTP proxy/cache
To modify traffic proxy must understand traffic
Other traffic must be handled as opaque data
11
27 Feb 2013
12
Proxy Topologies
Routed
Proxy is between different networks
Bridged
Same network on both sides of the proxy
13
Why Transparency
Transparency makes a proxied topology look
like the simple client / server topology
Should you use transparency?
From whom do you want to hide the proxy?
Hide from clients?
Hide from server?
27 Feb 2013
14
Proxy Types
Address used by proxy
Client connects to
Proxy Address
Client connects to
Server Address
Explicit Proxy
(Not hidden)
Inbound transparent
(hidden from clients)
Outbound transparent
(hidden from servers)
Fully transparent
(hidden from clients
and servers)
27 Feb 2013
15
Outbound transparent
CDN
Clients connect to explicit (advertised) proxy address
Server addresses are hidden from clients, servers could
use non-routable addresses
Servers can still see client address on connection
27 Feb 2013
16
Fully transparent
Proxy is not visible to clients or servers - no changes
required for clients or servers, they still see each
others addresses
Corporate use
Need to proxy
Need to have servers see distinct IP addresses for clients
Infeasible to configure clients for explicit proxy
27 Feb 2013
17
DEPLOYMENT
27 Feb 2013
18
Deploying
27 Feb 2013
19
27 Feb 2013
20
Generic Deployment
Normal packet flow is through ATS box
Need to divert specific flows to ATS
Use iptables/ebtables to mark packets
Use routing table to re-route packets to ATS
Configure ATS to handle those packets
Tweak host OS
27 Feb 2013
21
Now that Ive scared you, lets look at just what we need to know for HTTP transparency
27 Feb 2013
22
TPROXY
Short for Transparent PROXY
Linux kernel feature to support binding foreign
IP addresses
Accessible through iptables and socket options
Should be present in modern Linux kernels
27 Feb 2013
23
Building ATS
Transparency will be enabled by default if
possible
Can forced with --enable-tproxy=force option
Uses built in values
Also with --enable-tproxy=19 to force a
value (e.g. 19) for the sockopt parameter
Need Linux Kernel 2.6.31.13 or later
24
Generic Pre-Deployment
Decide on ATS options
Type of transparency
Routed, bridged, WCCP
27 Feb 2013
25
Generic Setup
27 Feb 2013
26
Pre-deployment cautions
ATS box is in line so all other traffic will pass
through it
Firewall mark and ATS proxy ports are
arbitrary and local so select to avoid
interference with other activity on the host
27 Feb 2013
27
ebtables
Break packets out of layer 2 bridge
Packets then processed as in other cases
Can do both IPv4 and IPv6 with ebtables
27 Feb 2013
28
iptables
Set firewall mark to enable special routing
Can use entire mark or a bit range and value
Only need 1 bit
Mark based on server port and host interface
Mark TPROXY for inbound transparent
Required for ATS to accept connection with
foreign destination address
29
iptables
iptables is used for many things, including
firewalling
Lots of potential cross interference
ATS uses the mangle table only
Default iptables configuration will block ATS
operation test client to server connectivity
through ATS host without ATS
27 Feb 2013
30
Routing table
Use policy routing to force table for packets
with ATS firewall mark
Add table for intercepted packets
Table sends everything to loopback
27 Feb 2013
31
ATS Configuration
Create proxy port(s) marked transparent as
needed
ATS proxy port must agree with iptables
redirection for inbound transparent
27 Feb 2013
32
tr-pass =
33
Host OS Configuration
Enable packet forwarding
Disable reverse path check (rp_filter) on
transparent physical interfaces
Do routing or bridged configuration
But thats already done because of course youve
checked for connectivity before deploying ATS
27 Feb 2013
34
27 Feb 2013
35
WCCP Topology
Router does packet interception for ATS
27 Feb 2013
36
WCCP
Past end of life Cisco protocol, still in use
Significant parts undocumented, no support
37
27 Feb 2013
38
27 Feb 2013
39
ATS Plugins
Can control outbound transparency per
connection
Can control server address per connection
Still a few bugs on URLs because HTTP headers
are different
27 Feb 2013
40
Making it work
TROUBLE SHOOTING
27 Feb 2013
41
Trouble Shooting
Step One: Make it work without ATS
Cannot over emphasize this
Always see Step One
27 Feb 2013
42
Wireshark
Graphical interface, very powerful
43
proxy.config.diags.debug.enabled INT 1
records.config value
44
Troubleshooting Checklist
Remove ATS ebtables, iptables, routing do
you have connectivity?
Enable ATS are all the processes running?
Check ATS logs to verify startup success. Look
for error messages!
traffic.out
error.log
dmesg
27 Feb 2013
45
Troubleshooting Checklist
Review configuration
Verify iptables target port, ATS proxy port match
Check iptables for packet / connection filtering
Bridge mode ebtables set up?
Policy routing in place?
Check OS tweaks (ip_forward, rp_filter)
27 Feb 2013
46
Troubleshooting Checklist
Capture client side
SYN-ACK from ATS?
Connection / request sent?
Capture loopback
Client SYN packets redirected?
SYN-ACK from ATS?
47
27 Feb 2013
48
ATS Logging
Enable debugging out
-T tags
Edit records.config values
proxy.config.diags.debug.enabled INT 1
Proxy.config.diags.debug.tags STRING tag1|tag2
Useful tags
hostdb, dns see outbound connections
http_accept see inbound connections
tproxy - extra TPROXY related events
Output to etc/trafficserver/traffic.out
27 Feb 2013
49
27 Feb 2013
50
Issues
Potential problems from field experience
Origin server address resolution
Port transparency
Proxy port address binding
Keep Alive
HTTPS
Non-HTTP tunneling
IP family lock
Currently limited to Linux variants
27 Feb 2013
51
27 Feb 2013
52
27 Feb 2013
53
Port Transparency
By default server connection can have a
different client port than actual client
Can configure ATS to use the client port
proxy.config.http.use_client_source_port INT 1
54
Keep Alive
ATS doesnt always match keep alive between
client side and server side.
Can cause port shift
In practice seems to matter only rarely
27 Feb 2013
55
HTTPS
HTTPS proxying requires certificates
ATS must terminate the connections
Easy for CDN situations
Cant just slap on ssl proxy port option
27 Feb 2013
56
Non-HTTP Tunneling
There exist protocols that use port 80 and
HTTP like headers but are not HTTP
By default ATS rejects the connection
TS-1423 patch enables this use with caution
27 Feb 2013
57
IP Family lock
ATS handles cross IP family connections
E.g. IPv4 client connection, IPv6 server connection
58
Remapping
In general remapping works
Be careful client and ATS will differ on the IP
address for server
Currently explicitly inhibited if ATS uses server
address from client connection
Not sure now why I did that
27 Feb 2013
59
Linux Required
Depends on TPROXY, iptables, policy routing
Requires POSIX capabilities or equivalent
Transparent binding is a privileged operation
27 Feb 2013
60
Script Kiddies
For inbound transparent ISP case, script
kiddies probing for open servers
ATS will accept connections to any foreign IP
address:port
Script thinks everything has an open port at
intercept ports
Can have an impact on ATS loading
27 Feb 2013
61
APPENDIX
27 Feb 2013
62
Resources
ATS has online documentation, a wiki, mailing
lists, bug tracker, and IRC channel. Access
these via
http://trafficserver.apache.org
NG Consulting services
http://network-geographics.com
27 Feb 2013
63
A beginning
These scripts are just starting points
Customize for local conditions
Illustrate essential commands and basic options
Plenty of other documentation for commands
27 Feb 2013
64
Environmental Concerns
Scripts presume
Client interface is eth1
Server interface is eth0
Server side network is 192.168.56.0/24
Client side network is 172.28.56.0/24
ATS proxy port is 8080
27 Feb 2013
65
Routed Topology
Bridged Topology
27 Feb 2013
66
67
Setup Script
Script for bridged and routed cases
Set shell variables to control setup
Works from a cold start
Pick out pieces for less intrusive operation
27 Feb 2013
68
27 Feb 2013
Network Geographics at ApacheCon NA 2013
69
fi
# br0 must have an address on the same network as the default gateway addr
ip route add default via 192.168.56.1
#ip -6 route add default via fc01:192:168:56::11
##
#
ip
ip
#
ip
ip
#
ip
ip
fi
## System tweaks
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Disable RP filter. Oddly, not needed on loopback
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter
#!/bin/sh
27 Feb 2013
Network Geographics at ApacheCon NA 2013
70
if (( $OUTBOUND )) ; then
# do the same from traffic from web server
ebtables -t broute -A BROUTING -p IPv4 --ip-proto tcp --ip-sport 80 -j redirect -redirect-target DROP
ebtables -t broute -A BROUTING -p IPv6 --ip6-proto tcp --ip6-sport 80 -j redirect -redirect-target DROP
fi
fi
if (( $INBOUND )) ; then
ip6tables -t mangle -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j TPROXY --on-ip :: --onport 8080 --tproxy-mark 1/1
fi
if (( $OUTBOUND )) ; then
ip6tables -t mangle -A PREROUTING -i eth0 -p tcp -m tcp --sport 80 -j MARK --set-mark 1/1
fi
# Be sure we're not filtering packets before they go to ATS (default on Linux)
# This disables *all* firewall protection. Don't do this if you want to preserver
# any filtering! In that case verify the filter rules don't break connectivity.
# I use this because the default installed rules are a problem.
iptables -t filter --flush FORWARD
ip6tables -t filter --flush FORWARD
iptables -t filter --flush INPUT
ip6tables -t filter --flush INPUT
# You might need to flush the mangle table as well, if there's cruft there.
## Iptables setup
# IPv4
# Brutal - get rid of everything else in the mangle table and put our stuff in
iptables -t mangle --flush PREROUTING
if (( $INBOUND )) ; then
iptables -t mangle -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j TPROXY --on-ip 0.0.0.0 -on-port 8080 --tproxy-mark 1/1
fi
if (( $OUTBOUND )) ; then
iptables -t mangle -A PREROUTING -i eth0 -p tcp -m tcp --sport 80 -j MARK --set-mark 1/1
fi
71
NAT style
Proxy ports 8080
iptables
iptables t nat A PREROUTING i eth1 p tcp m
tcp --dport 80 j REDIRECT --to-port 8080
Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
27 Feb 2013
72
WCCP Setup
Example router config
Tunnel addresses are on the 10.28.56.0/24 network
ATS host shares outside interface network (192.168.56.0/24)
no
ip
ip
ip
ip source-route
wccp check services all
wccp 51 password apache
wccp 52 password apache
interface Tunnel0
ip address 10.28.56.1 255.255.255.0
tunnel source 192.168.56.12
tunnel destination 192.168.56.11
interface FastEthernet0/0
ip address 192.168.56.12 255.255.255.0
ip wccp redirect exclude in
ip wccp 52 redirect in
interface FastEthernet0/1
ip address 172.28.56.12 255.255.255.0
ip wccp 51 redirect in
27 Feb 2013
73
27 Feb 2013
74
27 Feb 2013
75