]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: proxy: support use_backend with dynamic names
authorBertrand Jacquin <bjacquin@exosec.fr>
Tue, 19 Nov 2013 10:43:06 +0000 (11:43 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 31 Mar 2014 08:18:30 +0000 (10:18 +0200)
commit702d44f2ff98def1c8ebcc5c3de6293919a390d0
treea9569a91f8c8843c41d481a20f12c916b7433723
parentfa45f1d06c46ce7d88a0205e08a3ed4df124aea1
MEDIUM: proxy: support use_backend with dynamic names

We have a use case where we look up a customer ID in an HTTP header
and direct it to the corresponding server. This can easily be done
using ACLs and use_backend rules, but the configuration becomes
painful to maintain when the number of customers grows to a few
tens or even a several hundreds.

We realized it would be nice if we could make the use_backend
resolve its name at run time instead of config parsing time, and
use a similar expression as http-request add-header to decide on
the proper backend to use. This permits the use of prefixes or
even complex names in backend expressions. If no name matches,
then the default backend is used. Doing so allowed us to get rid
of all the use_backend rules.

Since there are some config checks on the use_backend rules to see
if the referenced backend exists, we want to keep them to detect
config errors in normal config. So this patch does not modify the
default behaviour and proceeds this way :

  - if the backend name in the use_backend directive parses as a log
    format rule, it's used as-is and is resolved at run time ;

  - otherwise it's a static name which must be valid at config time.

There was the possibility of doing this with the use-server directive
instead of use_backend, but it seems like use_backend is more suited
to this task, as it can be used for other purposes. For example, it
becomes easy to serve a customer-specific proxy.pac file based on the
customer ID by abusing the errorfile primitive :

     use_backend bk_cust_%[hdr(X-Cust-Id)] if { hdr(X-Cust-Id) -m found }
     default_backend bk_err_404

     backend bk_cust_1
         errorfile 200 /etc/haproxy/static/proxy.pac.cust1

Signed-off-by: Bertrand Jacquin <bjacquin@exosec.fr>
doc/configuration.txt
include/types/proxy.h
src/cfgparse.c
src/session.c