lldap-cli 1.0.3

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.
Files changed (4) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +368 -0
  3. package/dist/cli.js +3626 -0
  4. package/package.json +58 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stephen Eaton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,368 @@
1
+ # lldap-cli
2
+
3
+ A TypeScript CLI tool for managing [LLDAP](https://github.com/lldap/lldap) (Lightweight LDAP) users, groups, and schema.
4
+
5
+ Built with [Bun](https://bun.sh/) for fast execution and modern TypeScript support.
6
+
7
+ [![CI](https://github.com/madeinoz67/lldap-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/madeinoz67/lldap-cli/actions/workflows/ci.yml)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![Bun](https://img.shields.io/badge/Bun-%23000000.svg?style=flat&logo=bun&logoColor=white)](https://bun.sh/)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
11
+ [![GitHub release](https://img.shields.io/github/v/release/madeinoz67/lldap-cli)](https://github.com/madeinoz67/lldap-cli/releases)
12
+ [![GitHub issues](https://img.shields.io/github/issues/madeinoz67/lldap-cli)](https://github.com/madeinoz67/lldap-cli/issues)
13
+
14
+ ## Features
15
+
16
+ - **User Management** - Create, list, update, and delete users
17
+ - **Group Management** - Create, list, and manage group membership
18
+ - **Schema Management** - View and modify custom user/group attributes
19
+ - **Secure Authentication** - JWT-based auth with automatic token refresh
20
+ - **Security Hardened** - Input validation, rate limiting, audit logging
21
+
22
+ ## Installation
23
+
24
+ ### From Release
25
+
26
+ Download the standalone binary for your platform from the [releases page](https://github.com/madeinoz67/lldap-cli/releases):
27
+
28
+ ```bash
29
+ # Linux x64
30
+ curl -LO https://github.com/madeinoz67/lldap-cli/releases/latest/download/lldap-cli-linux-x64
31
+ chmod +x lldap-cli-linux-x64
32
+ sudo mv lldap-cli-linux-x64 /usr/local/bin/lldap-cli
33
+
34
+ # Linux ARM64
35
+ curl -LO https://github.com/madeinoz67/lldap-cli/releases/latest/download/lldap-cli-linux-arm64
36
+ chmod +x lldap-cli-linux-arm64
37
+ sudo mv lldap-cli-linux-arm64 /usr/local/bin/lldap-cli
38
+
39
+ # macOS x64 (Intel)
40
+ curl -LO https://github.com/madeinoz67/lldap-cli/releases/latest/download/lldap-cli-darwin-x64
41
+ chmod +x lldap-cli-darwin-x64
42
+ sudo mv lldap-cli-darwin-x64 /usr/local/bin/lldap-cli
43
+
44
+ # macOS ARM64 (Apple Silicon)
45
+ curl -LO https://github.com/madeinoz67/lldap-cli/releases/latest/download/lldap-cli-darwin-arm64
46
+ chmod +x lldap-cli-darwin-arm64
47
+ sudo mv lldap-cli-darwin-arm64 /usr/local/bin/lldap-cli
48
+ ```
49
+
50
+ ### From Source
51
+
52
+ ```bash
53
+ # Clone the repository
54
+ git clone https://github.com/madeinoz67/lldap-cli.git
55
+ cd lldap-cli
56
+
57
+ # Install dependencies
58
+ bun install
59
+
60
+ # Build
61
+ bun run build
62
+
63
+ # Run directly with Bun
64
+ bun run dev -- user list
65
+ ```
66
+
67
+ ## Configuration
68
+
69
+ ### Environment Variables
70
+
71
+ ```bash
72
+ export LLDAP_HTTP_URL="http://localhost:17170"
73
+ export LLDAP_USERNAME="admin"
74
+ export LLDAP_PASSWORD="your-password"
75
+ # Or use tokens (set automatically by eval $(lldap-cli login -p))
76
+ export LLDAP_TOKEN="your-jwt-token"
77
+ export LLDAP_REFRESH_TOKEN="your-refresh-token"
78
+ ```
79
+
80
+ You can also create a `.env` file in your working directory with these variables - it will be loaded automatically.
81
+
82
+ ### Config File
83
+
84
+ Create `~/.config/lldap-cli/config.json`:
85
+
86
+ ```json
87
+ {
88
+ "httpUrl": "http://localhost:17170",
89
+ "username": "admin"
90
+ }
91
+ ```
92
+
93
+ ### CLI Options
94
+
95
+ CLI options override environment variables and config file:
96
+
97
+ ```bash
98
+ lldap-cli -H http://localhost:17170 -u admin user list
99
+ ```
100
+
101
+ ## Usage
102
+
103
+ ### Authentication
104
+
105
+ ```bash
106
+ # Login with password prompt (recommended - password hidden, tokens set automatically)
107
+ eval $(lldap-cli login -p)
108
+
109
+ # Login with password on command line (less secure)
110
+ eval $(lldap-cli login -w password)
111
+
112
+ # Login and save tokens to file (most secure for scripts)
113
+ lldap-cli login -p -o ~/.lldap-tokens
114
+ source ~/.lldap-tokens
115
+
116
+ # Logout and invalidate tokens
117
+ eval $(lldap-cli logout)
118
+ ```
119
+
120
+ The `-p` flag prompts for password securely (input hidden). The `eval $(...)` pattern automatically sets `LLDAP_TOKEN` and `LLDAP_REFRESHTOKEN` environment variables for subsequent commands.
121
+
122
+ ### User Management
123
+
124
+ ```bash
125
+ # List users
126
+ lldap-cli user list # List user IDs (default)
127
+ lldap-cli user list email # List user emails
128
+ lldap-cli user list all # Table with ID, email, display name
129
+ lldap-cli user list -g admins # List users in 'admins' group
130
+ lldap-cli user list all -g staff # Table of users in 'staff' group
131
+ lldap-cli user info # Show detailed user info
132
+
133
+ # Search users (supports * and ? wildcards)
134
+ lldap-cli user search john # Search by uid, email, or display name
135
+ lldap-cli user search "*@corp.com" # Find users with corp.com email
136
+ lldap-cli user search "svc_*" # Find service accounts
137
+
138
+ # Create a user
139
+ lldap-cli user add jsmith john@example.com -d "John Smith" -f John -l Smith
140
+
141
+ # Delete a user
142
+ lldap-cli user del jsmith
143
+
144
+ # Set user password (requires lldap_set_password tool)
145
+ lldap-cli user set-password jsmith
146
+
147
+ # Update user attributes
148
+ lldap-cli user update set jsmith displayName "Johnny Smith"
149
+ lldap-cli user update clear jsmith avatar
150
+ lldap-cli user update add jsmith mailAlias "johnny@example.com"
151
+ lldap-cli user update del jsmith mailAlias "johnny@example.com"
152
+
153
+ # User attributes
154
+ lldap-cli user attribute list jsmith
155
+ lldap-cli user attribute values jsmith mailAlias
156
+
157
+ # User group membership
158
+ lldap-cli user group list jsmith
159
+ lldap-cli user group add jsmith "mail users"
160
+ lldap-cli user group del jsmith "mail users"
161
+ ```
162
+
163
+ ### Group Management
164
+
165
+ ```bash
166
+ # List groups
167
+ lldap-cli group list
168
+
169
+ # Search groups (supports * and ? wildcards)
170
+ lldap-cli group search admin* # Find groups starting with 'admin'
171
+ lldap-cli group search "*users" # Find groups ending with 'users'
172
+
173
+ # Create a group
174
+ lldap-cli group add "mail users"
175
+
176
+ # Delete a group
177
+ lldap-cli group del "mail users"
178
+
179
+ # Show users in a group
180
+ lldap-cli group info "mail users"
181
+
182
+ # Add/remove users
183
+ lldap-cli group add-user 1 jsmith
184
+ lldap-cli group remove-user 1 jsmith
185
+
186
+ # Update group attributes
187
+ lldap-cli group update set "mail users" description "Mail system users"
188
+
189
+ # Group attributes
190
+ lldap-cli group attribute list "mail users"
191
+ lldap-cli group attribute values "mail users" description
192
+ ```
193
+
194
+ ### Schema Management
195
+
196
+ ```bash
197
+ # User schema attributes
198
+ lldap-cli schema attribute user list
199
+ lldap-cli schema attribute user add mailAlias string -l -v # list, visible
200
+ lldap-cli schema attribute user del mailAlias
201
+
202
+ # Group schema attributes
203
+ lldap-cli schema attribute group list
204
+ lldap-cli schema attribute group add memberCount integer
205
+ lldap-cli schema attribute group del memberCount
206
+
207
+ # User object classes
208
+ lldap-cli schema objectclass user list
209
+ lldap-cli schema objectclass user add inetOrgPerson
210
+ lldap-cli schema objectclass user del inetOrgPerson
211
+
212
+ # Group object classes
213
+ lldap-cli schema objectclass group list
214
+ lldap-cli schema objectclass group add posixGroup
215
+ lldap-cli schema objectclass group del posixGroup
216
+ ```
217
+
218
+ ### Attribute Types
219
+
220
+ When adding schema attributes, use one of:
221
+ - `string` - Text values
222
+ - `integer` - Numeric values
223
+ - `date_time` - Date/time values
224
+ - `jpeg_photo` - Binary image data
225
+
226
+ ### Attribute Options
227
+
228
+ - `-l, --list` - Attribute can have multiple values
229
+ - `-v, --visible` - Attribute is visible in LDAP queries
230
+ - `-e, --editable` - Attribute can be modified via LDAP
231
+
232
+ ### Global Options
233
+
234
+ | Option | Description |
235
+ |--------|-------------|
236
+ | `-H, --http-url <url>` | LLDAP HTTP URL |
237
+ | `-u, --username <user>` | Username for authentication |
238
+ | `-t, --token <token>` | JWT access token |
239
+ | `-r, --refresh-token <token>` | JWT refresh token |
240
+ | `-q, --quiet` | Suppress header and non-essential output |
241
+ | `--debug` | Enable debug output (WARNING: may expose sensitive info) |
242
+ | `-h, --help` | Show help |
243
+ | `-V, --version` | Show version |
244
+
245
+ ### Login Options
246
+
247
+ | Option | Description |
248
+ |--------|-------------|
249
+ | `-p, --prompt-password` | Prompt for password (input hidden) |
250
+ | `-w, --password <pass>` | Password on command line (less secure) |
251
+ | `-o, --output <file>` | Write tokens to file instead of stdout |
252
+ | `-q, --quiet` | Suppress security warnings |
253
+
254
+ ## Programmatic Usage
255
+
256
+ ```typescript
257
+ import { LldapClient, UserService, GroupService, SchemaService, buildConfig } from 'lldap-cli';
258
+
259
+ const config = buildConfig({
260
+ httpUrl: 'http://localhost:17170',
261
+ username: 'admin',
262
+ password: 'password',
263
+ });
264
+
265
+ const client = new LldapClient(config);
266
+ const userService = new UserService(client);
267
+
268
+ // List all users
269
+ const users = await userService.getUsers();
270
+ console.log(users);
271
+
272
+ // Clean up
273
+ await client.cleanup();
274
+ ```
275
+
276
+ ## Exit Codes
277
+
278
+ The CLI uses standard BSD sysexits.h exit codes for scripting:
279
+
280
+ | Code | Name | Description |
281
+ |------|------|-------------|
282
+ | 0 | SUCCESS | Command completed successfully |
283
+ | 1 | ERROR | General/unknown error |
284
+ | 64 | USAGE | Invalid arguments or usage |
285
+ | 69 | UNAVAILABLE | Service unavailable (server down) |
286
+ | 74 | IOERR | I/O error (file not found) |
287
+ | 75 | TEMPFAIL | Temporary failure (rate limited) |
288
+ | 77 | NOPERM | Authentication/authorization failed |
289
+ | 78 | CONFIG | Configuration error |
290
+
291
+ Example scripting usage:
292
+ ```bash
293
+ lldap-cli login -p
294
+ case $? in
295
+ 0) echo "Login successful" ;;
296
+ 77) echo "Authentication failed" ;;
297
+ 78) echo "Configuration error - check username/URL" ;;
298
+ *) echo "Other error: $?" ;;
299
+ esac
300
+ ```
301
+
302
+ ## Security Features
303
+
304
+ This CLI includes comprehensive security hardening:
305
+
306
+ | Feature | Description |
307
+ |---------|-------------|
308
+ | **Input Validation** | All inputs validated for length and dangerous characters |
309
+ | **Password Complexity** | Passwords must be 8-128 chars with letters and numbers |
310
+ | **Rate Limiting** | Exponential backoff on 429 responses (max 3 retries) |
311
+ | **Session Timeout** | 30-minute inactivity timeout |
312
+ | **Token Management** | Automatic refresh, expiration detection |
313
+ | **Audit Logging** | Security events logged to stderr |
314
+ | **Error Sanitization** | Sensitive data redacted from error messages |
315
+ | **Path Traversal Protection** | File paths validated to prevent attacks |
316
+ | **HTTPS Warning** | Warns when using HTTP to non-localhost servers |
317
+
318
+ ## Development
319
+
320
+ ```bash
321
+ # Install dependencies
322
+ bun install
323
+
324
+ # Run tests
325
+ bun test
326
+
327
+ # Run tests in watch mode
328
+ bun test --watch
329
+
330
+ # Type check
331
+ bun run typecheck
332
+
333
+ # Lint
334
+ bun run lint
335
+
336
+ # Lint and fix
337
+ bun run lint:fix
338
+
339
+ # Build
340
+ bun run build
341
+ ```
342
+
343
+ ## Requirements
344
+
345
+ - [Bun](https://bun.sh/) 1.0+ (for development/running from source)
346
+ - LLDAP server running and accessible
347
+ - `lldap_set_password` tool (optional, for password management)
348
+
349
+ ## License
350
+
351
+ MIT License - Copyright (c) 2026 Stephen Eaton
352
+
353
+ See [LICENSE](LICENSE) for details.
354
+
355
+ ## Contributing
356
+
357
+ Contributions are welcome! Please ensure:
358
+
359
+ 1. All tests pass (`bun test`)
360
+ 2. Code passes linting (`bun run lint`)
361
+ 3. TypeScript compiles without errors (`bun run typecheck`)
362
+ 4. Security scanning passes (Trivy, TruffleHog)
363
+
364
+ ## Acknowledgments
365
+
366
+ - [LLDAP](https://github.com/lldap/lldap) - The lightweight LDAP server this tool manages
367
+ - [Commander.js](https://github.com/tj/commander.js) - CLI framework
368
+ - [Bun](https://bun.sh/) - JavaScript runtime and toolkit