blob: 9448f43adcffce88a18b4199c4101a1ecdd11161 [file] [log] [blame]
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +01001Linux network namespace support for HAProxy
2===========================================
3
4HAProxy supports proxying between Linux network namespaces. This
5feature can be used, for example, in a multi-tenant networking
6environment to proxy between different networks. HAProxy can also act
7as a front-end proxy for non namespace-aware services.
8
9The proxy protocol has been extended to support transferring the
10namespace information, so the originating namespace information can be
11kept. This is useful when chaining multiple proxies and services.
12
13To enable Linux namespace support, compile HAProxy with the `USE_NS=1`
14make option.
15
16
17## Setting up namespaces on Linux
18
19To create network namespaces, use the 'ip netns' command. See the
20manual page ip-netns(8) for details.
21
22Make sure that the file descriptors representing the network namespace
23are located under `/var/run/netns`.
24
25For example, you can create a network namespace and assign one of the
26networking interfaces to the new namespace:
27
28```
29$ ip netns add netns1
30$ ip link set eth7 netns netns1
31```
32
33
34## Listing namespaces in the configuration file
35
36HAProxy uses namespaces explicitly listed in its configuration file.
37If you are not using namespace information received through the proxy
38protocol, this usually means that you must specify namespaces for
39listeners and servers in the configuration file with the 'namespace'
40keyword.
41
42However, if you're using the namespace information received through
43the proxy protocol to determine the namespace of servers (see
44'namespace * below'), you have to explicitly list all allowed
45namespaces in the namespace_list section of your configuration file:
46
47```
48namespace_list
49 namespace netns1
50 namespace netns2
51```
52
53
54## Namespace information flow
55
56The haproxy process always runs in the namespace it was started on.
57This is the default namespace.
58
59The bind addresses of listeners can have their namespace specified in
60the configuration file. Unless specified, sockets associated with
61listener bind addresses are created in the default namespace. For
62example, this creates a listener in the netns2 namespace:
63
64```
65frontend f_example
66 bind 192.168.1.1:80 namespace netns2
67 default_backend http
68```
69
70Each client connection is associated with its source namespace. By
71default, this is the namespace of the bind socket it arrived on, but
72can be overridden by information received through the proxy protocol.
73Proxy protocol v2 supports transferring namespace information, so if
74it is enabled for the listener, it can override the associated
75namespace of the connection.
76
77Servers can have their namespaces specified in the configuration file
78with the 'namespace' keyword:
79
80```
81backend b_example
82 server s1 192.168.1.100:80 namespace netns2
83```
84
85If no namespace is set for a server, it is assumed that it is in the
86default namespace. When specified, outbound sockets to the server are
87created in the network namespace configured. To create the outbound
88(server) connection in the namespace associated with the client, use
89the '*' namespace. This is especially useful when using the
90destination address and namespace received from the proxy protocol.
91
92```
93frontend f_example
94 bind 192.168.1.1:9990 accept-proxy
95 default_backend b_example
96
97backend b_example
98 mode tcp
99 source 0.0.0.0 usesrc clientip
100 server snodes * namespace *
101```
102
103If HAProxy is configured to send proxy protocol v2 headers to the
104server, the outgoing header will always contain the namespace
105associated with the client connection, not the namespace configured
106for the server.