Re: [PATCH] MINOR: set IP_FREEBIND on IPv6 sockets in transparent mode

2014-03-04 Thread Sander Klein

On 03.03.2014 21:31, Willy Tarreau wrote:

On Mon, Mar 03, 2014 at 09:10:51PM +0100, Lukas Tribus wrote:
Lets set IP_FREEBIND on IPv6 sockets as well, this works since Linux 
3.3

and doesn't require CAP_NET_ADMIN privileges (IPV6_TRANSPARENT does).

This allows unprivileged users to bind to non-local IPv6 addresses, 
which

can be useful when setting up the listening sockets or when connecting
to backend servers with a specific, non-local source IPv6 address (at 
that

point we usually dropped root privileges already).


Patch applied, thank you Lukas!


I will test the patch. Stupid question, but is it really supported from 
3.3 and higher? A quick test with dev22 yesterday seemed to be working 
but I didn't put any traffic through it. It was late so I didn't give it 
enough attention ;-)


Sander



Re: [PATCH] MINOR: set IP_FREEBIND on IPv6 sockets in transparent mode

2014-03-04 Thread Lukas Tribus
Hi Sander,


 Patch applied, thank you Lukas!

 I will test the patch. Stupid question, but is it really supported
 from 3.3 and higher? A quick test with dev22 yesterday seemed to be
 working but I didn't put any traffic through it. It was late so I
 didn't give it enough attention ;-)


 Just tested it with plain dev22 and 3.2 and IPv6 seems to work nicely.
 What does the patch do? Because I don't quite understand.

Sorry for the confusion. In your case, as long as you start haproxy
initially as root, you don't need this patch and you don't need linux 3.3.

All you need is start haproxy as root, it will set IPV6_TRANSPARENT on the
socket and it will work in all kernels starting with 2.6.37.

The problem with the behavior before this patch was that IPV6_TRANSPARENT
requires superuser privileges (or more specifically the CAP_NET_ADMIN
capability).

There are 2 use cases where we may not have this capability:
- when HAProxy is not started as root initially (and listens only to ports
 1024) - I suspect this is not very common
- when HAProxy drops root privileges after the initial setup, and the
  socket option is needed on backend connections (which are not setup at
  HAproxy start of course, but when the connection is actually needed, but
  at that point we don't have the capabilities anymore)


IP_FREEBIND doesn't need special privileges, so this fixes those 2 cases.


In your case however you don't need IP_FREEBIND, because:
- you only need the socket options on frontend connections (specified on the
  bind line) - which are setup before dropping to a normal user
- you start haproxy with root privileges (most likely you bind to port 80
  or 443, so you need to start privileged anyway)


So the patch is not necessary for you. IP_FREEBIND on IPv6 sockets requires
Linux 3.3, but IPV6_TRANSPARENT only requires 2.6.37.



Regards,

Lukas 


Re: [PATCH] MINOR: set IP_FREEBIND on IPv6 sockets in transparent mode

2014-03-03 Thread Willy Tarreau
On Mon, Mar 03, 2014 at 09:10:51PM +0100, Lukas Tribus wrote:
 Lets set IP_FREEBIND on IPv6 sockets as well, this works since Linux 3.3
 and doesn't require CAP_NET_ADMIN privileges (IPV6_TRANSPARENT does).
 
 This allows unprivileged users to bind to non-local IPv6 addresses, which
 can be useful when setting up the listening sockets or when connecting
 to backend servers with a specific, non-local source IPv6 address (at that
 point we usually dropped root privileges already).

Patch applied, thank you Lukas!

Willy