How To Pass arguments to LUA from HAProxy config

May 13, 2016 1.1k views
Load Balancing Miscellaneous CentOS

How To Pass arguments to LUA from HAProxy config. I am trying to pass certificate DN information for client and CA, but getting error in haproxy config check.

HAProxy LUA config

    lua-load /usr/sbin/lua-choose-backend.lua

  frontend http-in
    mode http

    log-format %ci:%cp\ [%t]\ %ft\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ %hr\ %hs\ {%[ssl_c_verify],%{+Q}[ssl_c_s_dn],%{+Q}[ssl_c_i_dn]}\ %{+Q}r

    bind *:443 ssl crt /etc/haproxy/server.pem ca-file /etc/haproxy/ca.crt verify required

    use_backend %[lua.choose_backend([ssl_c_s_dn], [ssl_c_i_dn])]
    #use_backend app
    default_backend app
    reqadd X-Forwarded-Proto:\ https if { ssl_fc }
    option forwardfor



function choose_backend(txn, arg1, arg2)
        core.log(, "Hello World")
        core.log(, arg1)
        core.log(, arg2)

        return "app"

core.register_fetches("choose_backend", choose_backend)


$ haproxy -c -f /etc/haproxy/haproxy.cfg

[WARNING] 133/050028 (6381) : parsing [/etc/haproxy/haproxy.cfg:88] : 'acl' : sample fetch <lua.choose_backend([ssl_c_s_dn> failed with : missing closing ')' after arguments to fetch keyword 'lua.choose_backend'
[ALERT] 133/050028 (6381) : Proxy 'http-in': unable to find required use_backend: '%[lua.choose_backend([ssl_c_s_dn],'.
1 Answer
Have another answer? Share your knowledge.