# HAPROXY with auth LDAP

**URL:** <https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980>\
**Category:** Help!\
**Created:** [June 28, 2019, 11:00am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980 "2019-06-28T11:00:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TJarriault](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@TJarriault](https://discourse.haproxy.org/u/TJarriault)\
**Post date:** [June 28, 2019, 11:00am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/1 "2019-06-28T11:00:21Z")

</div>

Hi,  
I need to add an LDAP authentication on my haproxy. Is it possible to do this instead basic auth ?

Many thanks,

Tony

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [June 28, 2019, 11:10am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/2 "2019-06-28T11:10:03Z")

</div>

There was a similar question a few days ago. I’ll link to my reply:

> [@LDAP as backend for BasicAuth (Userlist)](https://discourse.haproxy.org/t/ldap-as-backend-for-basicauth-userlist/3923/2):
>
> To my knowledge HAProxy doesn’t support LDAP (or any non-static configuration) backend for authentication. However, given that HAProxy does have support for Lua based fetches or actions, one could implement a simple web service that interacts with LDAP and exposes an HTTP-based API, and then from Lua one can interrogate this translator service. (In fact if you search for HAProxy + Lua + LDAP you might be lucky and find something already implemented.)

---

<div class="post-metadata">

**Author:** ![TJarriault](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@TJarriault](https://discourse.haproxy.org/u/TJarriault)\
**Post date:** [July 2, 2019, 6:36pm UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/3 "2019-07-02T18:36:42Z")

</div>

> [@ciprian.craciun](#):
>
> HAProxy + Lua + LDAP

Many thanks, that i find, it’s not user frendly to integrate LDAP authentification on haproxy.  
damn…

an other question, if you know :  
is it possible to catch status code 404 from the backend to do redirect to an URI for exemple ?  
I try this with you success :  
acl not\_there status 404  
http-request redirect code 301 location [http://www.yahoo.fr/](http://www.yahoo.fr/) if not\_there

Regards,  
tony

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [July 2, 2019, 6:40pm UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/4 "2019-07-02T18:40:51Z")

</div>

> [@TJarriault](#):
>
> is it possible to catch status code 404 from the backend to do redirect to an URI for exemple ?  
> I try this with you success :  
> acl not\_there status 404  
> http-request redirect code 301 location [http://www.yahoo.fr/](http://www.yahoo.fr/) if not\_there

Yes, but you need to use `http-response` (instead of `http-request`), though as per documentation there are perhaps some limitations:  
[http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-http-response](http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-http-response)

---

<div class="post-metadata">

**Author:** ![TJarriault](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@TJarriault](https://discourse.haproxy.org/u/TJarriault)\
**Post date:** [July 3, 2019, 7:26am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/5 "2019-07-03T07:26:04Z")

</div>

Hi,  
When i tried, the solution you mentionned, with the sample bellow, i’ve got an error during restart

**Error**  
Jul 3 07:25:03 ip-10-215-10-68 haproxy-systemd-wrapper: [ALERT] 183/072503 (9066) : parsing [/etc/haproxy/haproxy.cfg:62]: ‘http-response’ expects ‘allow’, ‘deny’, ‘redirect’, ‘add-header’, ‘del-header’, ‘set-header’, ‘replace-header’, ‘replace-value’, ‘set-nice’, ‘set-tos’, ‘set-mark’, ‘set-log-level’, ‘del-acl’, ‘add-acl’, ‘del-map’, ‘set-map’, but got ‘redirect’.  
Jul 3 07:25:03 ip-10-215-10-68 haproxy-systemd-wrapper: [ALERT] 183/072503 (9066) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg

**Config file**

frontend http\_front  
bind \*:80  
stats uri /haproxy?stats  
default\_backend app

#---------------------------------------------------------------------  
backend app  
balance roundrobin  
server app1 [openspeedtest.com:80](http://openspeedtest.com:80) check

acl not\_there status 404  
http-response redirect location [http://www.yahoo.fr/](http://www.yahoo.fr/) code 301 if not\_there

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [July 3, 2019, 11:55am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/6 "2019-07-03T11:55:09Z")

</div>

> [@TJarriault](#):
>
> When i tried, the solution you mentionned, with the sample bellow, i’ve got an error during restart

It might be that the `http-response redirect` syntax is slightly different for responses than requests. Try to fiddle with the various keywords (like removing `code 301` and `location`).

---

<div class="post-metadata">

**Author:** ![Tlams](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@Tlams](https://discourse.haproxy.org/u/Tlams)\
**Post date:** [December 26, 2019, 6:04pm UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/7 "2019-12-26T18:04:01Z")

</div>

Hello,

It’s a bit late, but I use to work on this problem:  
[https://www.tlams.fr/articles/haproxy/LDAP\_Auth.html](https://www.tlams.fr/articles/haproxy/LDAP_Auth.html)

All comments to improve it are welcome.

Regards,  
Tlams.

---

<div class="post-metadata">

**Author:** ![Gaitonde](https://avatars.discourse-cdn.com/v4/letter/g/8797f3/32.png) [@Gaitonde](https://discourse.haproxy.org/u/Gaitonde)\
**Post date:** [June 1, 2024, 6:12am UTC](https://discourse.haproxy.org/t/haproxy-with-auth-ldap/3980/8 "2024-06-01T06:12:48Z")

</div>

Hi,  
The link does not work anymore. Possible to share the updated link?  
Thanks
