ldap-rest 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -21
- package/docs/README.md +23 -486
- package/docs/{DEVELOPER_GUIDE.md → client-development/README.md} +24 -24
- package/docs/client-development/api/README.md +75 -0
- package/docs/client-development/browser/README.md +65 -0
- package/docs/{plugins/DEVELOPMENT.md → plugin-development/README.md} +4 -9
- package/docs/plugin-development/hooks.md +18 -0
- package/docs/usage/README.md +89 -0
- package/docs/usage/configuration.md +375 -0
- package/docs/usage/plugins/README.md +87 -0
- package/docs/usage/plugins/auth/README.md +65 -0
- package/docs/usage/plugins/auth/crowdsec.md +95 -0
- package/docs/usage/plugins/auth/hmac.md +293 -0
- package/docs/usage/plugins/auth/llng.md +99 -0
- package/docs/usage/plugins/auth/oidc.md +167 -0
- package/docs/usage/plugins/auth/rate-limit.md +62 -0
- package/docs/usage/plugins/auth/token.md +136 -0
- package/docs/usage/plugins/auth/totp.md +213 -0
- package/docs/usage/plugins/auth/trusted-proxy.md +127 -0
- package/docs/usage/plugins/integrations/README.md +42 -0
- package/docs/usage/plugins/ldap/README.md +79 -0
- package/docs/usage/troubleshooting.md +105 -0
- package/package.json +9 -1
- package/docs/authentication.md +0 -1194
- /package/docs/{OPENAPI.md → client-development/api/openapi.md} +0 -0
- /package/docs/{api/REFERENCE.md → client-development/api/reference.md} +0 -0
- /package/docs/{api/REST_API.md → client-development/api/rest-api.md} +0 -0
- /package/docs/{browser/LIBRARIES.md → client-development/browser/libraries.md} +0 -0
- /package/docs/{examples/EXAMPLES.md → client-development/examples/README.md} +0 -0
- /package/docs/{examples → client-development/examples/ldif}/twake-mailbox-type-nomenclature.ldif +0 -0
- /package/docs/{examples → client-development/examples/ldif}/twake-mailbox-type-schema-amendment.ldif +0 -0
- /package/docs/{schemas/SCHEMAS.md → client-development/schemas/README.md} +0 -0
- /package/docs/{PLUGIN_DEPENDENCIES.md → plugin-development/dependencies.md} +0 -0
- /package/docs/{testing-with-embedded-ldap.md → plugin-development/testing.md} +0 -0
- /package/docs/{presenterm.md → presentations/en.md} +0 -0
- /package/docs/{presenterm-fr.md → presentations/fr.md} +0 -0
- /package/docs/{authzLinid1.md → usage/plugins/auth/authz-linid1.md} +0 -0
- /package/docs/{authzPerBranch.md → usage/plugins/auth/authz-per-branch.md} +0 -0
- /package/docs/{twakeAppAccountsApi.md → usage/plugins/integrations/app-accounts.md} +0 -0
- /package/docs/{twakeCalendarResources.md → usage/plugins/integrations/calendar-resources.md} +0 -0
- /package/docs/{twakeJames.md → usage/plugins/integrations/james-mail.md} +0 -0
- /package/docs/{jamesTeamMailboxes.md → usage/plugins/integrations/james-mailboxes.md} +0 -0
- /package/docs/{ldapBulkImport.md → usage/plugins/ldap/bulk-import.md} +0 -0
- /package/docs/{ldapExternalUsersInGroups.md → usage/plugins/ldap/external-users.md} +0 -0
- /package/docs/{ldapFlatGeneric.md → usage/plugins/ldap/flat-generic.md} +0 -0
- /package/docs/{ldapGroups.md → usage/plugins/ldap/groups.md} +0 -0
- /package/docs/{onChange.md → usage/plugins/ldap/on-change.md} +0 -0
- /package/docs/{ldapOrganizations.md → usage/plugins/ldap/organizations.md} +0 -0
- /package/docs/{ldapTrash.md → usage/plugins/ldap/trash.md} +0 -0
- /package/docs/{static.md → usage/plugins/utilities/static.md} +0 -0
- /package/docs/{weblogs.md → usage/plugins/utilities/weblogs.md} +0 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# HMAC Authentication
|
|
2
|
+
|
|
3
|
+
HMAC-SHA256 request signing authentication for backend services (Registration Service, admin panel backend, cloudery, etc.).
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
### Basic Configuration
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
--plugin core/auth/hmac \
|
|
11
|
+
--auth-hmac "registration-service:secret-key-minimum-32-chars:Registration Service" \
|
|
12
|
+
--auth-hmac "cloudery:another-secret-key-long-enough:Cloudery Backend"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Environment Variable:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
DM_AUTH_HMAC="registration-service:secret-key-minimum-32-chars:Registration Service,cloudery:another-secret-key-long-enough:Cloudery Backend"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Syntax:** `service-id:secret:name`
|
|
22
|
+
|
|
23
|
+
- **service-id**: Service identifier (e.g., `registration-service`, `cloudery`)
|
|
24
|
+
- **secret**: Shared secret for HMAC (minimum 32 characters recommended)
|
|
25
|
+
- **name**: Descriptive service name (can contain colons)
|
|
26
|
+
|
|
27
|
+
### Advanced Configuration
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
--auth-hmac-window 120000 # Time window in milliseconds (default: 120000 = 2 minutes)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Environment Variable:**
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
DM_AUTH_HMAC_WINDOW=120000 # Default: 120000ms (2 minutes)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **window**: Maximum time difference (in milliseconds) between server and client timestamp
|
|
40
|
+
- Prevents replay attacks by rejecting requests with timestamps outside the window
|
|
41
|
+
|
|
42
|
+
## How It Works
|
|
43
|
+
|
|
44
|
+
### Request Signing Process
|
|
45
|
+
|
|
46
|
+
1. **Client calculates signature:**
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
signature = HMAC-SHA256(
|
|
50
|
+
secret,
|
|
51
|
+
"METHOD|PATH|timestamp|body-hash"
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Where:
|
|
56
|
+
- `METHOD`: HTTP method (GET, POST, PATCH, DELETE, PUT, etc.)
|
|
57
|
+
- `PATH`: Request path with query string (e.g., `/api/v1/ldap/users?filter=active`)
|
|
58
|
+
- `timestamp`: Unix timestamp in milliseconds (e.g., `1698765432000`)
|
|
59
|
+
- `body-hash`: SHA256(request_body) for POST/PATCH/PUT, empty string for GET/DELETE/HEAD
|
|
60
|
+
|
|
61
|
+
2. **Client sends Authorization header:**
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Authorization: HMAC-SHA256 service-id:timestamp:signature
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. **Server validates:**
|
|
68
|
+
- Extracts `service-id`, `timestamp`, and `signature` from header
|
|
69
|
+
- Verifies timestamp is within configured window (prevents replay attacks)
|
|
70
|
+
- Retrieves service secret using `service-id`
|
|
71
|
+
- Recalculates signature using same method
|
|
72
|
+
- Compares signatures using constant-time comparison (prevents timing attacks)
|
|
73
|
+
- Rejects if mismatch or timestamp expired
|
|
74
|
+
|
|
75
|
+
4. **On success:**
|
|
76
|
+
- Sets `req.user` to service name
|
|
77
|
+
- Allows request to proceed
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
### Manual Request Example
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Example: GET request
|
|
85
|
+
SERVICE_ID="registration-service"
|
|
86
|
+
SECRET="secret-key-minimum-32-chars"
|
|
87
|
+
METHOD="GET"
|
|
88
|
+
PATH="/api/v1/ldap/users"
|
|
89
|
+
TIMESTAMP=$(date +%s000) # Unix timestamp in milliseconds
|
|
90
|
+
|
|
91
|
+
# Calculate body hash (empty for GET)
|
|
92
|
+
BODY_HASH=""
|
|
93
|
+
|
|
94
|
+
# Create signing string
|
|
95
|
+
SIGNING_STRING="${METHOD}|${PATH}|${TIMESTAMP}|${BODY_HASH}"
|
|
96
|
+
|
|
97
|
+
# Calculate HMAC-SHA256 signature
|
|
98
|
+
SIGNATURE=$(echo -n "$SIGNING_STRING" | openssl dgst -sha256 -hmac "$SECRET" | cut -d' ' -f2)
|
|
99
|
+
|
|
100
|
+
# Make request
|
|
101
|
+
curl -H "Authorization: HMAC-SHA256 ${SERVICE_ID}:${TIMESTAMP}:${SIGNATURE}" \
|
|
102
|
+
http://localhost:8081${PATH}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### POST Request with Body
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
SERVICE_ID="registration-service"
|
|
109
|
+
SECRET="secret-key-minimum-32-chars"
|
|
110
|
+
METHOD="POST"
|
|
111
|
+
PATH="/api/v1/ldap/users"
|
|
112
|
+
TIMESTAMP=$(date +%s000)
|
|
113
|
+
BODY='{"uid":"user1","mail":"user1@example.com"}'
|
|
114
|
+
|
|
115
|
+
# Calculate body hash
|
|
116
|
+
BODY_HASH=$(echo -n "$BODY" | openssl dgst -sha256 | cut -d' ' -f2)
|
|
117
|
+
|
|
118
|
+
# Create signing string
|
|
119
|
+
SIGNING_STRING="${METHOD}|${PATH}|${TIMESTAMP}|${BODY_HASH}"
|
|
120
|
+
|
|
121
|
+
# Calculate signature
|
|
122
|
+
SIGNATURE=$(echo -n "$SIGNING_STRING" | openssl dgst -sha256 -hmac "$SECRET" | cut -d' ' -f2)
|
|
123
|
+
|
|
124
|
+
# Make request
|
|
125
|
+
curl -X POST \
|
|
126
|
+
-H "Authorization: HMAC-SHA256 ${SERVICE_ID}:${TIMESTAMP}:${SIGNATURE}" \
|
|
127
|
+
-H "Content-Type: application/json" \
|
|
128
|
+
-d "$BODY" \
|
|
129
|
+
http://localhost:8081${PATH}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Browser Client
|
|
133
|
+
|
|
134
|
+
The HMAC client library is available as an npm module export:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm install ldap-rest
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { HmacAuthClient } from 'ldap-rest/browser-shared-utils-hmac';
|
|
142
|
+
|
|
143
|
+
const client = new HmacAuthClient({
|
|
144
|
+
serviceId: 'registration-service',
|
|
145
|
+
secret: 'secret-key-minimum-32-chars',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Automatic authentication with HMAC signature
|
|
149
|
+
const response = await client.get('/api/v1/ldap/users');
|
|
150
|
+
const users = await response.json();
|
|
151
|
+
|
|
152
|
+
// POST with automatic body hashing and signing
|
|
153
|
+
await client.post('/api/v1/ldap/users', {
|
|
154
|
+
uid: 'user1',
|
|
155
|
+
mail: 'user1@example.com',
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Other methods: put, patch, delete
|
|
159
|
+
await client.put('/api/v1/ldap/users/user1', { mail: 'new@example.com' });
|
|
160
|
+
await client.delete('/api/v1/ldap/users/user1');
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Manual signature generation:**
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { generateHmacSignature } from 'ldap-rest/browser-shared-utils-hmac';
|
|
167
|
+
|
|
168
|
+
const signature = await generateHmacSignature(
|
|
169
|
+
'secret-key-minimum-32-chars',
|
|
170
|
+
'GET',
|
|
171
|
+
'/api/v1/ldap/users',
|
|
172
|
+
Date.now(),
|
|
173
|
+
undefined // no body for GET
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const authHeader = `HMAC-SHA256 registration-service:${Date.now()}:${signature}`;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Use Cases
|
|
180
|
+
|
|
181
|
+
- **Backend Services**: Service-to-service authentication (Registration Service, admin panels, etc.)
|
|
182
|
+
- **Microservices**: Secure inter-service communication
|
|
183
|
+
- **Webhooks**: Verify request authenticity and integrity
|
|
184
|
+
- **API Gateways**: Backend service authentication
|
|
185
|
+
- **Cloudery Integration**: Secure communication with cloudery backend
|
|
186
|
+
- **Automated Services**: CI/CD, monitoring, backup services
|
|
187
|
+
|
|
188
|
+
## Security Considerations
|
|
189
|
+
|
|
190
|
+
- **Secret Strength**: Use secrets of at least 32 characters (64+ recommended)
|
|
191
|
+
- **Secret Storage**: Store secrets securely (encrypted configuration, environment variables, secret managers)
|
|
192
|
+
- **HTTPS Required**: Always use HTTPS to protect signatures in transit
|
|
193
|
+
- **Time Synchronization**: Ensure server and client clocks are synchronized (NTP recommended)
|
|
194
|
+
- **Replay Protection**: Time window prevents replay attacks (adjust `auth-hmac-window` as needed)
|
|
195
|
+
- **Constant-Time Comparison**: Signature validation uses `timingSafeEqual` to prevent timing attacks
|
|
196
|
+
- **Secret Rotation**: Rotate secrets periodically for enhanced security
|
|
197
|
+
- **Body Integrity**: Body hash ensures request payload hasn't been tampered with
|
|
198
|
+
- **Path Integrity**: Full path (including query parameters) is signed
|
|
199
|
+
|
|
200
|
+
## Security Features
|
|
201
|
+
|
|
202
|
+
1. **Replay Attack Prevention**: Timestamp validation with configurable window
|
|
203
|
+
2. **Timing Attack Protection**: Constant-time signature comparison
|
|
204
|
+
3. **Request Integrity**: Body hash ensures payload integrity
|
|
205
|
+
4. **Path Integrity**: Query parameters included in signature
|
|
206
|
+
5. **Multi-Service Support**: Isolated secrets per service
|
|
207
|
+
6. **Clock Drift Tolerance**: Configurable time window (default 2 minutes)
|
|
208
|
+
|
|
209
|
+
## Advantages Over Other Methods
|
|
210
|
+
|
|
211
|
+
| Feature | HMAC | Token | TOTP |
|
|
212
|
+
| ------------------------- | ---------------- | ----------- | ---------------- |
|
|
213
|
+
| **Request Integrity** | Yes (body hash) | No | No |
|
|
214
|
+
| **Replay Protection** | Yes (timestamp) | No | Yes (time-based) |
|
|
215
|
+
| **Signature Per Request** | Yes | No (static) | Yes (30s codes) |
|
|
216
|
+
| **Body Tampering Detect** | Yes | No | No |
|
|
217
|
+
| **Path/Query Protection** | Yes | No | No |
|
|
218
|
+
| **Setup Complexity** | Medium | Simple | Simple |
|
|
219
|
+
| **Best For** | Backend services | Simple APIs | MFA, user auth |
|
|
220
|
+
|
|
221
|
+
## Comparison with Standards
|
|
222
|
+
|
|
223
|
+
This implementation is similar to:
|
|
224
|
+
|
|
225
|
+
- **AWS Signature V4**: Similar approach but simpler (AWS is more complex with canonicalization)
|
|
226
|
+
- **HTTP Message Signatures (RFC 9421)**: IETF standard for HTTP signatures
|
|
227
|
+
- **HMAC-Based Authentication**: Industry-standard pattern for service authentication
|
|
228
|
+
|
|
229
|
+
Our approach provides a good balance between security and simplicity:
|
|
230
|
+
|
|
231
|
+
- Simpler than AWS Signature V4 (easier to implement)
|
|
232
|
+
- More secure than static tokens (request-specific signatures)
|
|
233
|
+
- Better integrity than TOTP (includes body and path hashing)
|
|
234
|
+
- Standard cryptography (HMAC-SHA256)
|
|
235
|
+
|
|
236
|
+
## Troubleshooting
|
|
237
|
+
|
|
238
|
+
**Problem:** 401 Unauthorized despite correct signature
|
|
239
|
+
|
|
240
|
+
**Solutions:**
|
|
241
|
+
|
|
242
|
+
1. Verify service-id matches exactly (case-sensitive)
|
|
243
|
+
2. Verify secret is correctly configured (minimum 32 characters)
|
|
244
|
+
3. Check system clock synchronization (use NTP: `ntpdate -q pool.ntp.org`)
|
|
245
|
+
4. Increase `--auth-hmac-window` if experiencing timing issues
|
|
246
|
+
5. Verify Authorization header format: `HMAC-SHA256 service-id:timestamp:signature`
|
|
247
|
+
6. Check server logs for specific error messages
|
|
248
|
+
7. Ensure timestamp is in milliseconds, not seconds
|
|
249
|
+
8. Verify body hash calculation (must match exactly)
|
|
250
|
+
|
|
251
|
+
**Problem:** Timestamp outside allowed window
|
|
252
|
+
|
|
253
|
+
**Solutions:**
|
|
254
|
+
|
|
255
|
+
1. Synchronize clocks using NTP
|
|
256
|
+
2. Increase `--auth-hmac-window` (default: 120000ms = 2 minutes)
|
|
257
|
+
3. Check if timestamp is in milliseconds (not seconds)
|
|
258
|
+
4. Verify both server and client are using same timezone reference (UTC)
|
|
259
|
+
|
|
260
|
+
**Problem:** Signature mismatch
|
|
261
|
+
|
|
262
|
+
**Solutions:**
|
|
263
|
+
|
|
264
|
+
1. Verify signing string format: `METHOD|PATH|timestamp|body-hash`
|
|
265
|
+
2. Ensure METHOD is uppercase (GET, POST, etc.)
|
|
266
|
+
3. Include full path with query parameters
|
|
267
|
+
4. For POST/PATCH/PUT: verify body hash is SHA256(JSON.stringify(body))
|
|
268
|
+
5. For GET/DELETE/HEAD: body-hash must be empty string
|
|
269
|
+
6. Ensure secret is exactly the same on client and server
|
|
270
|
+
7. Use hex encoding for signature (lowercase)
|
|
271
|
+
8. Check for trailing whitespace in secret
|
|
272
|
+
|
|
273
|
+
**Problem:** Warning about short secrets
|
|
274
|
+
|
|
275
|
+
**Solutions:**
|
|
276
|
+
|
|
277
|
+
1. Use secrets of at least 32 characters
|
|
278
|
+
2. Recommended: 64+ characters for enhanced security
|
|
279
|
+
3. Generate secure random secrets:
|
|
280
|
+
```bash
|
|
281
|
+
openssl rand -hex 32 # 64-character hex string
|
|
282
|
+
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Debug Example:**
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# Enable debug logging
|
|
289
|
+
DM_LOG_LEVEL=debug npm start
|
|
290
|
+
|
|
291
|
+
# Check signing string in logs
|
|
292
|
+
# Expected format: "GET|/api/v1/ldap/users|1698765432000|"
|
|
293
|
+
```
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# LemonLDAP::NG Authentication
|
|
2
|
+
|
|
3
|
+
Integration with [LemonLDAP::NG](https://lemonldap-ng.org/) (LLNG) Web SSO solution.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
--plugin core/auth/llng \
|
|
9
|
+
--llng-ini /etc/lemonldap-ng/lemonldap-ng.ini
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
**Environment Variable:**
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
DM_LLNG_INI="/etc/lemonldap-ng/lemonldap-ng.ini"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
1. **LemonLDAP::NG Handler**: The `lemonldap-ng-handler` npm package (optional dependency)
|
|
21
|
+
2. **LLNG Configuration**: Valid `lemonldap-ng.ini` file
|
|
22
|
+
3. **Virtual Host Configuration**: LDAP-Rest must be configured as a protected application in LLNG
|
|
23
|
+
|
|
24
|
+
## How It Works
|
|
25
|
+
|
|
26
|
+
1. Uses the LemonLDAP::NG Handler to validate requests
|
|
27
|
+
2. Extracts user identity from `Lm-Remote-User` header
|
|
28
|
+
3. Sets `req.user` to authenticated username
|
|
29
|
+
4. Inherits all LLNG authorization rules and features
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Install the optional dependency:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install lemonldap-ng-handler
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## LLNG Configuration
|
|
40
|
+
|
|
41
|
+
Configure LDAP-Rest as a protected virtual host in LemonLDAP::NG:
|
|
42
|
+
|
|
43
|
+
```apache
|
|
44
|
+
# In LLNG Manager: Virtual Hosts > api.example.com
|
|
45
|
+
<VirtualHost *:443>
|
|
46
|
+
ServerName api.example.com
|
|
47
|
+
|
|
48
|
+
# LemonLDAP::NG Handler
|
|
49
|
+
PerlHeaderParserHandler Lemonldap::NG::Handler::ApacheMP2
|
|
50
|
+
|
|
51
|
+
# Proxy to LDAP-Rest
|
|
52
|
+
ProxyPass / http://localhost:8081/
|
|
53
|
+
ProxyPassReverse / http://localhost:8081/
|
|
54
|
+
</VirtualHost>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Use Cases
|
|
58
|
+
|
|
59
|
+
- **Enterprise SSO**: Centralized authentication for multiple applications
|
|
60
|
+
- **Advanced Authorization**: Fine-grained access control using LLNG rules
|
|
61
|
+
- **Session Management**: Centralized session handling
|
|
62
|
+
- **Multi-Factor Authentication**: MFA support through LLNG
|
|
63
|
+
|
|
64
|
+
## Example: LLNG Authorization Rules
|
|
65
|
+
|
|
66
|
+
Configure access rules in LLNG Manager:
|
|
67
|
+
|
|
68
|
+
```perl
|
|
69
|
+
# Allow only HR group to access users endpoint
|
|
70
|
+
$groups =~ /\bhr\b/ and $uri =~ m#^/api/v1/ldap/users#
|
|
71
|
+
|
|
72
|
+
# Allow admins full access
|
|
73
|
+
$groups =~ /\badmins\b/
|
|
74
|
+
|
|
75
|
+
# Allow specific users to manage groups
|
|
76
|
+
$uid eq "groupmanager" and $uri =~ m#^/api/v1/ldap/groups#
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Troubleshooting
|
|
80
|
+
|
|
81
|
+
**Problem:** Handler not found
|
|
82
|
+
|
|
83
|
+
**Solution:** Install optional dependency:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
npm install lemonldap-ng-handler
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Problem:** Authentication refused
|
|
90
|
+
|
|
91
|
+
**Solutions:**
|
|
92
|
+
|
|
93
|
+
1. Verify LLNG handler is configured correctly
|
|
94
|
+
2. Check virtual host configuration
|
|
95
|
+
3. Review LLNG access logs
|
|
96
|
+
|
|
97
|
+
## See Also
|
|
98
|
+
|
|
99
|
+
- [LemonLDAP::NG Documentation](https://lemonldap-ng.org/documentation)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# OpenID Connect Authentication
|
|
2
|
+
|
|
3
|
+
OAuth 2.0 / OpenID Connect authentication for modern identity providers.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
--plugin core/auth/openidconnect \
|
|
9
|
+
--oidc-server "https://auth.example.com" \
|
|
10
|
+
--oidc-client-id "ldap-rest-client" \
|
|
11
|
+
--oidc-client-secret "client-secret-here" \
|
|
12
|
+
--base-url "https://api.example.com"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Environment Variables:**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
DM_OIDC_SERVER="https://auth.example.com"
|
|
19
|
+
DM_OIDC_CLIENT_ID="ldap-rest-client"
|
|
20
|
+
DM_OIDC_CLIENT_SECRET="client-secret-here"
|
|
21
|
+
DM_BASE_URL="https://api.example.com"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Prerequisites
|
|
25
|
+
|
|
26
|
+
1. **OpenID Provider**: [Lemonldap-NG](https://lemonldap-ng.org), Keycloak, Auth0, Okta, Azure AD, etc.
|
|
27
|
+
2. **Client Registration**: LDAP-Rest registered as OAuth2/OIDC client
|
|
28
|
+
3. **Optional Dependency**: The `express-openid-connect` npm package
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Install the optional dependency:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install express-openid-connect
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## How It Works
|
|
39
|
+
|
|
40
|
+
1. Uses `express-openid-connect` for OAuth2/OIDC flow
|
|
41
|
+
2. Handles authorization code flow automatically
|
|
42
|
+
3. Extracts user identity from `sub` claim
|
|
43
|
+
4. Sets `req.user` to user's subject identifier
|
|
44
|
+
5. Provides `beforeAuth` and `afterAuth` hooks for customization
|
|
45
|
+
|
|
46
|
+
## Provider Configuration
|
|
47
|
+
|
|
48
|
+
### Keycloak
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
--oidc-server "https://keycloak.example.com/realms/master" \
|
|
52
|
+
--oidc-client-id "ldap-rest" \
|
|
53
|
+
--oidc-client-secret "abc123..." \
|
|
54
|
+
--base-url "https://api.example.com"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Client Settings:**
|
|
58
|
+
|
|
59
|
+
- Access Type: `confidential`
|
|
60
|
+
- Valid Redirect URIs: `https://api.example.com/callback`
|
|
61
|
+
- Standard Flow Enabled: `ON`
|
|
62
|
+
|
|
63
|
+
### Auth0
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
--oidc-server "https://tenant.auth0.com" \
|
|
67
|
+
--oidc-client-id "your-client-id" \
|
|
68
|
+
--oidc-client-secret "your-client-secret" \
|
|
69
|
+
--base-url "https://api.example.com"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Azure AD
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
--oidc-server "https://login.microsoftonline.com/{tenant-id}/v2.0" \
|
|
76
|
+
--oidc-client-id "application-id" \
|
|
77
|
+
--oidc-client-secret "client-secret" \
|
|
78
|
+
--base-url "https://api.example.com"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Scopes
|
|
82
|
+
|
|
83
|
+
Default scopes requested:
|
|
84
|
+
|
|
85
|
+
- `openid` - Basic OpenID Connect
|
|
86
|
+
- `profile` - User profile information
|
|
87
|
+
- `email` - User email address
|
|
88
|
+
|
|
89
|
+
## Hooks
|
|
90
|
+
|
|
91
|
+
The OpenID Connect plugin supports custom hooks:
|
|
92
|
+
|
|
93
|
+
### beforeAuth Hook
|
|
94
|
+
|
|
95
|
+
Called before authentication processing:
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
hooks: {
|
|
99
|
+
beforeAuth: async ([req, res]) => {
|
|
100
|
+
// Custom pre-authentication logic
|
|
101
|
+
console.log('Authentication attempt from:', req.ip);
|
|
102
|
+
return [req, res];
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### afterAuth Hook
|
|
108
|
+
|
|
109
|
+
Called after successful authentication:
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
hooks: {
|
|
113
|
+
afterAuth: async ([req, res]) => {
|
|
114
|
+
// Access OIDC user data
|
|
115
|
+
const user = req.oidc.user;
|
|
116
|
+
console.log('User authenticated:', user.email);
|
|
117
|
+
|
|
118
|
+
// Add custom user properties
|
|
119
|
+
req.customData = {
|
|
120
|
+
email: user.email,
|
|
121
|
+
name: user.name,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return [req, res];
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Use Cases
|
|
130
|
+
|
|
131
|
+
- **Modern Identity Providers**: Integration with cloud identity services
|
|
132
|
+
- **Social Login**: Google, Microsoft, GitHub authentication
|
|
133
|
+
- **Multi-Tenant Applications**: Different OIDC providers per tenant
|
|
134
|
+
- **Standards-Based**: Portable across OIDC-compliant providers
|
|
135
|
+
|
|
136
|
+
## Troubleshooting
|
|
137
|
+
|
|
138
|
+
**Problem:** express-openid-connect not found
|
|
139
|
+
|
|
140
|
+
**Solution:** Install optional dependency:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
npm install express-openid-connect
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Problem:** Missing config parameter
|
|
147
|
+
|
|
148
|
+
**Solution:** Ensure all required parameters are set:
|
|
149
|
+
|
|
150
|
+
- `--oidc-server`
|
|
151
|
+
- `--oidc-client-id`
|
|
152
|
+
- `--oidc-client-secret`
|
|
153
|
+
- `--base-url`
|
|
154
|
+
|
|
155
|
+
**Problem:** Redirect loop
|
|
156
|
+
|
|
157
|
+
**Solutions:**
|
|
158
|
+
|
|
159
|
+
1. Set a long secret, shorts are refused by `openid-client`
|
|
160
|
+
2. Verify `--base-url` matches actual public URL
|
|
161
|
+
3. Check redirect URI in provider matches `{base-url}/callback`
|
|
162
|
+
4. Ensure HTTPS in production (many providers require it)
|
|
163
|
+
|
|
164
|
+
## See Also
|
|
165
|
+
|
|
166
|
+
- [OpenID Connect Specification](https://openid.net/connect/)
|
|
167
|
+
- [express-openid-connect](https://github.com/auth0/express-openid-connect)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Rate Limiting
|
|
2
|
+
|
|
3
|
+
Prevent brute force attacks by limiting the number of requests per IP address.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
--plugin core/auth/rateLimit \
|
|
9
|
+
--rate-limit-window 60000 \
|
|
10
|
+
--rate-limit-max 100
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Environment Variables:**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
DM_RATE_LIMIT_WINDOW=60000 # Time window in milliseconds (default: 60000 = 1 minute)
|
|
17
|
+
DM_RATE_LIMIT_MAX=100 # Maximum requests per window (default: 100)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## How It Works
|
|
21
|
+
|
|
22
|
+
1. Tracks request count per IP address
|
|
23
|
+
2. Uses sliding window algorithm
|
|
24
|
+
3. Returns `429 Too Many Requests` when limit exceeded
|
|
25
|
+
4. Automatically respects `X-Forwarded-For` when behind trusted proxy
|
|
26
|
+
|
|
27
|
+
## Use Cases
|
|
28
|
+
|
|
29
|
+
- **Brute Force Prevention**: Limit authentication attempts
|
|
30
|
+
- **API Protection**: Prevent abuse of API endpoints
|
|
31
|
+
- **DDoS Mitigation**: Basic protection against flood attacks
|
|
32
|
+
- **Fair Usage**: Ensure equitable API access
|
|
33
|
+
|
|
34
|
+
## Headers
|
|
35
|
+
|
|
36
|
+
When rate limiting is active, responses include:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
X-RateLimit-Limit: 100
|
|
40
|
+
X-RateLimit-Remaining: 95
|
|
41
|
+
X-RateLimit-Reset: 1698765492
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Combining with Trusted Proxy
|
|
45
|
+
|
|
46
|
+
For correct IP detection behind reverse proxies:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
--plugin core/auth/trustedProxy \
|
|
50
|
+
--trusted-proxy "127.0.0.1" \
|
|
51
|
+
--plugin core/auth/rateLimit \
|
|
52
|
+
--rate-limit-max 100
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The rate limiter will use the real client IP from `X-Forwarded-For` when the request comes from a trusted proxy.
|
|
56
|
+
|
|
57
|
+
## Security Considerations
|
|
58
|
+
|
|
59
|
+
- Always use with `trustedProxy` plugin behind reverse proxies
|
|
60
|
+
- Consider different limits for different endpoints
|
|
61
|
+
- Monitor for legitimate users hitting limits
|
|
62
|
+
- Combine with CrowdSec for IP reputation
|