Skip to content

Commit 3338f5f

Browse files
committed
- Add support of a resolver to resolve LDAP hostname
- Add possibility to retrieve LDAP attributes during LDAP search
1 parent 5cc107c commit 3338f5f

File tree

3 files changed

+553
-53
lines changed

3 files changed

+553
-53
lines changed

README.md

Lines changed: 180 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
# LDAP Authentication module for nginx
22
LDAP module for nginx which supports authentication against multiple LDAP servers.
33

4-
# How to install
4+
## Project history
55

6-
## FreeBSD
6+
This project is a clone of [nginx-auth-ldap](https://github.com/kvspb/nginx-auth-ldap) original module from [kvspb](https://github.com/kvspb).
7+
8+
The reasons for this fork are:
9+
10+
* The original project seems abondonned (no commit since 2 years)
11+
* Inherit from other contributors fixes/features
12+
* [Pull request #237](https://github.com/kvspb/nginx-auth-ldap/pull/237) from [mmguero-dev](https://github.com/mmguero-dev/nginx-auth-ldap)
13+
* Add new features
14+
* Add the use of `resolver` to resolve hostname of the LDAP server
15+
* Support LDAP attributes fecthing during search
16+
17+
## How to install
18+
19+
### FreeBSD
720

821
```bash
922
cd /usr/ports/www/nginx && make config install clean
@@ -16,10 +29,10 @@ Check HTTP_AUTH_LDAP options
1629
[*] HTTP_AUTH_LDAP 3rd party http_auth_ldap module
1730
```
1831

19-
## Linux
32+
### Linux
2033

2134
```bash
22-
cd ~ && git clone https://github.com/kvspb/nginx-auth-ldap.git
35+
cd ~ && git clone https://github.com/Ericbla/nginx-auth-ldap.git
2336
```
2437

2538
in nginx source folder
@@ -29,11 +42,14 @@ in nginx source folder
2942
make install
3043
```
3144

32-
# Example configuration
45+
## Example configuration
46+
3347
Define list of your LDAP servers with required user/group requirements:
3448

3549
```bash
3650
http {
51+
auth_ldap_resolver 8.8.8.8;
52+
3753
ldap_server test1 {
3854
url ldap://192.168.0.1:3268/DC=test,DC=local?sAMAccountName?sub?(objectClass=person);
3955
binddn "TEST\\LDAPUSER";
@@ -55,14 +71,15 @@ Define list of your LDAP servers with required user/group requirements:
5571
```
5672

5773
And add required servers in correct order into your location/server directive:
74+
5875
```bash
5976
server {
6077
listen 8000;
6178
server_name localhost;
6279

6380
auth_ldap "Forbidden";
6481
auth_ldap_servers test1;
65-
auth_ldap_servers test2;
82+
auth_ldap_servers test2;
6683

6784
location / {
6885
root html;
@@ -72,49 +89,149 @@ And add required servers in correct order into your location/server directive:
7289
}
7390
```
7491

75-
# Available config parameters
92+
## Available config parameters
93+
94+
### auth_ldap_cache_enabled
95+
96+
* Syntax: auth_ldap_cache_enabled on | off;
97+
* Default: auth_ldap_cache_enabled off;
98+
* Context: http
99+
100+
### auth_ldap_cache_expiration_time
101+
102+
* Syntax: auth_ldap_cache_expiration_time time;
103+
* Default: auth_ldap_cache_expiration_time 10000;
104+
* Context: http
105+
106+
Cache expiration time (in ms).
107+
108+
### auth_ldap_cache_size
109+
110+
* Syntax: auth_ldap_cache_size size;
111+
* Default: auth_ldap_cache_size 100;
112+
* Context: http
113+
114+
Number of cached LDAP authentications (min 100)
115+
116+
### auth_ldap_servers_size
117+
118+
* Syntax: auth_ldap_servers_size size;
119+
* Syntax: auth_ldap_servers_size 7;
120+
* Context: http
121+
122+
Maximum number of `ldap_server` elements to support
123+
124+
### auth_ldap
125+
126+
* Syntax: auth_ldap off | _realm_;
127+
* Default: --
128+
* Context: http, server, loc, limit_expect
129+
130+
Set the _realm_ to be used with the `WWW-Authenticate` response header when authentication failed or is missing.
131+
132+
### auth_ldap_servers
133+
134+
* Syntax: auth_ldap_servers _name_;
135+
* Default: --
136+
* Context: http, server, loc, limit_expect
137+
138+
Select the server _name_ to work with user authentication
139+
140+
### auth_ldap_resolver
141+
142+
* Syntax: auth_ldap_resolver _address_ ... [valid=time] [ipv4=on|off] [ipv6=on|off] [status_zone=zone];
143+
* Default: --
144+
* Context: http
145+
146+
The resolver to use as a fallback when the system hostname resolution
147+
(gethostbyname()) can't resolve the LDAP server hostname.
148+
See the `resolver` directive of the **ngx_http_core_module**
149+
150+
### auth_ldap_resolver_timeout
76151

77-
## url
78-
expected value: string
152+
* Syntax: auth_ldap_resolver_timeout time;
153+
* Default: auth_ldap_resolver_timeout 10000;
154+
* Context: http
79155

80-
Available URL schemes: ldap://, ldaps://
156+
Resolver requests timeout (in ms).
81157

82-
## binddn
83-
expected value: string
158+
### ldap_server
84159

85-
## binddn_passwd
86-
expected value: string
160+
* Syntax: ldap_server _name_ { ... }
161+
* Default: none
162+
* Context: http
87163

88-
## group_attribute
89-
expected value: string
164+
## Configuration parameters for the `ldap_server` block
90165

91-
## group_attribute_is_dn
92-
expected value: on or off, default off
166+
### url
93167

94-
## require
95-
expected value: valid_user, user, group
168+
* Syntax: url _url_;
169+
* Default: --
170+
* Context: `ldap_server` block
96171

97-
## satisfy
98-
expected value: all, any
172+
url format: ldap[s]://host[:port]/dn?attrs?scope?filter[?exts]
99173

100-
## max_down_retries
101-
expected value: a number, default 0
174+
### binddn
175+
176+
* Syntax: binddn _dn_;
177+
* Default: --
178+
* Context: `ldap_server` block
179+
180+
### binddn_passwd
181+
182+
* Syntax: binddn_passwd _password_;
183+
* Default: --
184+
* Context: `ldap_server` block
185+
186+
### group_attribute
187+
188+
* Syntax: group attr;
189+
* Default: --
190+
* Context: `ldap_server` block
191+
192+
### group_attribute_is_dn
193+
194+
* Syntax: group_attribute_is_dn on | off;
195+
* Default: group_attribute_is_dn off;
196+
* Context: `ldap_server` block
197+
198+
Tell to search for full DN in member object.
199+
200+
### require
201+
202+
* Syntax: require valid_user | user | group;
203+
* Default: --;
204+
* Context: `ldap_server` block
205+
206+
207+
### satisfy
208+
209+
* Syntax: satisfy all | any;
210+
* Default: --;
211+
* Context: `ldap_server` block
212+
213+
### max_down_retries
214+
215+
* Syntax: max_down_retries _number_;
216+
* Default: max_down_retries 0;
217+
* Context: `ldap_server` block
102218

103219
Retry count for attempting to reconnect to an LDAP server if it is considered
104220
"DOWN". This may happen if a KEEP-ALIVE connection to an LDAP server times
105221
out or is terminated by the server end after some amount of time.
106222

107223
This can usually help with the following error:
108224

109-
```
225+
```text
110226
http_auth_ldap: ldap_result() failed (-1: Can't contact LDAP server)
111227
```
112228

113-
## connections
114-
expected value: a number greater than 0
115229

116-
## ssl_check_cert
117-
expected value: on or off, default off
230+
### ssl_check_cert
231+
232+
* Syntax: ssl_check_cert on | chain | off;
233+
* Default: ssl_check_cert off;
234+
* Context: `ldap_server` block
118235

119236
Verify the remote certificate for LDAPs connections. If disabled, any remote certificate will be
120237
accepted which exposes you to possible man-in-the-middle attacks. Note that the server's
@@ -123,23 +240,51 @@ See below how to trust CAs without installing them system-wide.
123240

124241
This options needs OpenSSL >= 1.0.2; it is unavailable if compiled with older versions.
125242

126-
## ssl_ca_file
127-
expected value: file path
243+
When `chain` is given, verify cert chain but not hostname/IP in SAN
244+
245+
### ssl_ca_file
246+
247+
* Syntax: ssl_ca_file _file-path_;
248+
* Default: --;
249+
* Context: `ldap_server` block
128250

129251
Trust the CA certificate in this file (see ssl_check_cert above).
130252

131-
## ssl_ca_dir
132-
expected value: directory path
253+
### ssl_ca_dir
254+
255+
* Syntax: ssl_ca_file _dir-path_;
256+
* Default: --;
257+
* Context: `ldap_server` block
133258

134259
Trust all CA certificates in this directory (see ssl_check_cert above).
135260

136261
Note that you need to provide hash-based symlinks in the directory for this to work;
137262
you'll basically need to run OpenSSL's c_rehash command in this directory.
138263

139-
## referral
140-
expected value: on, off
264+
### referral
265+
266+
* Syntax: referral on | off;
267+
* Default: referral on;
268+
* Context: `ldap_server` block
141269

142270
LDAP library default is on. This option disables usage of referral messages from
143271
LDAP server. Usefull for authenticating against read only AD server without access
144272
to read write.
145273

274+
### attribute_header_prefix
275+
276+
* Syntax: attribute_header_prefix _string_;
277+
* Default: attribute_header_prefix X-LDAP-ATTRS-;
278+
* Context: `ldap_server` block
279+
280+
The prefix for the HEADER names used to carry the feteched attributes (default: "X-LDAP-ATTRS-")
281+
282+
### search_attribute
283+
284+
* Syntax: search_attribute _attr_;
285+
* Default: --
286+
* Context: `ldap_server` block
287+
288+
Add this LDAP attribute description for the search (require valid-user or require user). The attribute value will be return as a HTTP header (<attribute_header_prefix><search_attribute>) in the authentication response.
289+
290+
_Note_: This parameter can be repeated several times when several attributes need to be fetched

example.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@ http {
1111
sendfile on;
1212
keepalive_timeout 65;
1313

14+
auth_ldap_resolver 8.8.8.8;
15+
auth_ldap_cache_enabled on;
16+
1417
# define ldap server
1518
ldap_server ad_1 {
1619
# user search base.
1720
url "ldap://<YOUR LDAP SERVER>:3268/OU=Offices,DC=company,DC=com?sAMAccountName?sub?(objectClass=person)";
1821
# bind as
1922
binddn "CN=Operator,OU=Service Accounts,DC=company,DC=com";
2023
# bind pw
21-
binddn_passwd <PUT Operator's PASSWORD HERE>;
24+
binddn_passwd <OPERATOR PASSWORD HERE>;
25+
# Select attributes to be retrieved during the search (several are possible)
26+
search_attribute mail;
27+
search_attribute sn;
28+
search_attribute givenName;
2229
# group attribute name which contains member object
2330
group_attribute member;
2431
# search for full DN in member object

0 commit comments

Comments
 (0)