LDAP-Monitor 1.0.0__py3-none-any.whl
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.
- ldap_monitor-1.0.0.dist-info/METADATA +267 -0
- ldap_monitor-1.0.0.dist-info/RECORD +10 -0
- ldap_monitor-1.0.0.dist-info/WHEEL +5 -0
- ldap_monitor-1.0.0.dist-info/entry_points.txt +2 -0
- ldap_monitor-1.0.0.dist-info/licenses/LICENSE +661 -0
- ldap_monitor-1.0.0.dist-info/top_level.txt +1 -0
- ldap_watchdog/__init__.py +2 -0
- ldap_watchdog/__main__.py +3 -0
- ldap_watchdog/config.py +50 -0
- ldap_watchdog/watchdog.py +343 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: LDAP-Monitor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Monitor LDAP directory changes in real-time
|
|
5
|
+
Home-page: https://github.com/MegaManSec/LDAP-Monitoring-Watchdog
|
|
6
|
+
Author: Joshua Rogers
|
|
7
|
+
Author-email: ldap-watchdog@joshua.hu
|
|
8
|
+
License: GPL-3.0
|
|
9
|
+
Project-URL: Blog Post, https://joshua.hu/ldap-watchdog-openldap-python-monitoring-tool-realtime-directory-slack-notifications
|
|
10
|
+
Project-URL: Author, https://joshua.hu/
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Topic :: System :: Monitoring
|
|
22
|
+
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory :: LDAP
|
|
23
|
+
Requires-Python: >=3.7
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: ldap3
|
|
27
|
+
Provides-Extra: slack
|
|
28
|
+
Requires-Dist: requests; extra == "slack"
|
|
29
|
+
Dynamic: author
|
|
30
|
+
Dynamic: author-email
|
|
31
|
+
Dynamic: classifier
|
|
32
|
+
Dynamic: description
|
|
33
|
+
Dynamic: description-content-type
|
|
34
|
+
Dynamic: home-page
|
|
35
|
+
Dynamic: license
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
Dynamic: project-url
|
|
38
|
+
Dynamic: provides-extra
|
|
39
|
+
Dynamic: requires-dist
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
Dynamic: summary
|
|
42
|
+
|
|
43
|
+
# LDAP Watchdog
|
|
44
|
+
|
|
45
|
+
## Overview
|
|
46
|
+
LDAP Watchdog is a tool designed to monitor record changes in an LDAP directory in real-time.
|
|
47
|
+
It provides a mechanism to track and visualize modifications, additions, and removals to user and group entries, allowing users to correlate expected changes with actual changes and identify potential security incidents.
|
|
48
|
+
It was created with OpenLDAP and Linux in mind, however it may work in other implementations of LDAP.
|
|
49
|
+
It is written in Python and only requires the ldap3 library.
|
|
50
|
+
|
|
51
|
+
This software was written by [Joshua Rogers](https://joshua.hu/).
|
|
52
|
+
|
|
53
|
+
If you're interesting in any of the following, then LDAP Watchdog is for you:
|
|
54
|
+
- Know what's going on in your LDAP directory on-demand with Slack webhook integration.
|
|
55
|
+
- See new hires, leavers, and promotions as they appear in LDAP.
|
|
56
|
+
- Monitor _when_ and what HR is doing.
|
|
57
|
+
- Detect unauthorized changes in LDAP.
|
|
58
|
+
- Monitor for accidentally leaked data.
|
|
59
|
+
- Detect when users are logging in and out of LDAP.
|
|
60
|
+
|
|
61
|
+
In addition to monitoring for modifications, additions, and removals in an LDAP directory, it can be configured to ignore specific attributes, or even fine-tuned to ignore fine-grained attributes depending on their old/new values.
|
|
62
|
+
|
|
63
|
+
The changes that are monitored can either be forwarded to a slack webhook or output to the terminal (or both). Optional colored output is also supported.
|
|
64
|
+
|
|
65
|
+
Previously named LDAP-Stalker (because monitoring changes of an LDAP directory is an excellent way to stalk changes in a company: learn about promotions before they're announced, new hires, leavers, etc.), a blog post about the details and history of this project [can be found here](https://joshua.hu/ldap-watchdog-openldap-python-monitoring-tool-realtime-directory-slack-notifications).
|
|
66
|
+
|
|
67
|
+
## Examples (No Filtering)
|
|
68
|
+
|
|
69
|
+
Note: in the below examples, entryCSN and modifyTimestamp can be completely ignored by setting `LDAP_WATCHDOG_IGNORED_ATTRIBUTES=entryCSN,modifyTimestamp`.
|
|
70
|
+
|
|
71
|
+
### Terminal (with color) output:
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
### Slack output:
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Features
|
|
80
|
+
|
|
81
|
+
1. **Real-time Monitoring:** LDAP Watchdog continuously monitors an LDAP directory for changes in user and group entries.
|
|
82
|
+
|
|
83
|
+
2. **Change Comparison:** The tool compares changes between consecutive LDAP searches, highlighting additions, modifications, and deletions.
|
|
84
|
+
|
|
85
|
+
3. **Control User Verification:** LDAP Watchdog supports a control user mechanism, triggering an error if the control user's changes are not found.
|
|
86
|
+
|
|
87
|
+
4. **Flexible LDAP Filtering:** Users can customize LDAP filtering using the `LDAP_WATCHDOG_SEARCH_FILTER` environment variable to focus on specific object classes or attributes.
|
|
88
|
+
|
|
89
|
+
5. **Slack Integration:** Receive real-time notifications on Slack for added, modified, or deleted LDAP entries.
|
|
90
|
+
|
|
91
|
+
6. **Customizable Output:** Console output provides clear and colored indications of additions, modifications, and deletions for easy visibility.
|
|
92
|
+
|
|
93
|
+
7. **Ignored Entries and Attributes:** Users can specify UUIDs and attributes to be ignored during the comparison process.
|
|
94
|
+
|
|
95
|
+
8. **Conditional Ignored Attributes:** Conditional filtering allows users to ignore specific attributes based on change type (additions, modifications, deletions).
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Requirements
|
|
99
|
+
- Python 3.7+.
|
|
100
|
+
- The `ldap3` package. If using a Slack webhook, the `requests` package is also required.
|
|
101
|
+
|
|
102
|
+
## Installation
|
|
103
|
+
|
|
104
|
+
### PyPI
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
pip install LDAP-Monitor
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
To include Slack webhook support:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pip install LDAP-Monitor[slack]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Docker
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
docker pull megamansec/ldap-monitor
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Or from GitHub Container Registry:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
docker pull ghcr.io/megamansec/ldap-monitoring-watchdog
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### From Source
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
git clone https://github.com/MegaManSec/LDAP-Monitoring-Watchdog.git
|
|
132
|
+
cd LDAP-Monitoring-Watchdog
|
|
133
|
+
pip install ".[slack]"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Usage
|
|
137
|
+
|
|
138
|
+
### Running with pip install
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
export LDAP_WATCHDOG_SERVER='ldaps://ldaps.intra.lan'
|
|
142
|
+
export LDAP_WATCHDOG_BASE_DN='dc=mouse,dc=com'
|
|
143
|
+
export LDAP_WATCHDOG_USERNAME='Emily'
|
|
144
|
+
export LDAP_WATCHDOG_PASSWORD='qwerty123'
|
|
145
|
+
ldap-watchdog
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Or using `python -m`:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
python -m ldap_watchdog
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Running with Docker
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
docker run -d \
|
|
158
|
+
-e LDAP_WATCHDOG_SERVER='ldaps://ldaps.intra.lan' \
|
|
159
|
+
-e LDAP_WATCHDOG_BASE_DN='dc=mouse,dc=com' \
|
|
160
|
+
-e LDAP_WATCHDOG_USERNAME='Emily' \
|
|
161
|
+
-e LDAP_WATCHDOG_PASSWORD='qwerty123' \
|
|
162
|
+
-e SLACK_WEBHOOK_URL='https://hooks.slack.com/services/[...]' \
|
|
163
|
+
-e LDAP_WATCHDOG_IGNORED_ATTRIBUTES='modifyTimestamp,phoneNumber,officeLocation,gecos' \
|
|
164
|
+
megamansec/ldap-monitor
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Systemd Installation (Debian-based)
|
|
168
|
+
|
|
169
|
+
A Debian-based installation script, [install.sh](install.sh), is provided. When run as root, this script:
|
|
170
|
+
|
|
171
|
+
1. Creates (if necessary) a Python virtual environment in `/opt/ldap-watchdog`.
|
|
172
|
+
2. Installs LDAP Watchdog from PyPI into that virtual environment.
|
|
173
|
+
3. Creates an environment file at `/etc/ldap-watchdog.env` for configuration.
|
|
174
|
+
4. Installs and enables a systemd service (`/etc/systemd/system/ldap-watchdog.service`) that runs **ldap-watchdog** in the background.
|
|
175
|
+
5. Configures logging to `/var/log/ldap-watchdog.log` and `/var/log/ldap-watchdog-error.log`.
|
|
176
|
+
6. Sets up log rotation in `/etc/logrotate.d/ldap-watchdog`.
|
|
177
|
+
|
|
178
|
+
You may optionally pass a single argument to `install.sh` to set the `SLACK_WEBHOOK_URL`:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
sudo ./install.sh "https://hooks.slack.com/services/[...]"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
After installation, edit `/etc/ldap-watchdog.env` to configure the LDAP connection settings, then restart the service:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
sudo systemctl restart ldap-watchdog
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Configuration
|
|
191
|
+
|
|
192
|
+
All configuration is done via environment variables. The following variables are supported:
|
|
193
|
+
|
|
194
|
+
### General Settings
|
|
195
|
+
|
|
196
|
+
| Environment Variable | Description | Default |
|
|
197
|
+
|---|---|---|
|
|
198
|
+
| `LDAP_WATCHDOG_SERVER` | LDAP server URL (e.g. `ldaps://ldaps.intra.lan`) | `""` |
|
|
199
|
+
| `LDAP_WATCHDOG_BASE_DN` | Base Distinguished Name for LDAP searches | `""` |
|
|
200
|
+
| `LDAP_WATCHDOG_USERNAME` | LDAP username for authentication. Leave empty for anonymous bind. | `""` |
|
|
201
|
+
| `LDAP_WATCHDOG_PASSWORD` | LDAP password for authentication. Leave empty for anonymous bind. | `""` |
|
|
202
|
+
| `LDAP_WATCHDOG_USE_SSL` | Set to `true` to use SSL, `false` otherwise | `true` |
|
|
203
|
+
| `LDAP_WATCHDOG_SEARCH_FILTER` | LDAP filter for user and group entries | `(&(|(objectClass=inetOrgPerson)(objectClass=groupOfNames)))` |
|
|
204
|
+
| `LDAP_WATCHDOG_SEARCH_ATTRIBUTE` | Comma-separated list of attributes to retrieve. [`*,+`](https://joshua.hu/tracking-secret-ldap-login-times-with-modifytimestamp-heuristics) is used by default to include operational attributes. | `*,+` |
|
|
205
|
+
| `LDAP_WATCHDOG_REFRESH_RATE` | Time interval in seconds between consecutive LDAP searches | `60` |
|
|
206
|
+
| `LDAP_WATCHDOG_DISABLE_COLOR_OUTPUT` | Set to `true` to disable colored terminal output | `false` |
|
|
207
|
+
|
|
208
|
+
### Control User
|
|
209
|
+
|
|
210
|
+
| Environment Variable | Description | Default |
|
|
211
|
+
|---|---|---|
|
|
212
|
+
| `LDAP_WATCHDOG_CONTROL_UUID` | UUID of a control user whose changes trigger an error if not found. If set, this user should always have some type of change when the LDAP directory is retrieved. | `""` |
|
|
213
|
+
| `LDAP_WATCHDOG_CONTROL_USER_ATTRIBUTE` | Specific attribute to check for changes in the control user. If set, this attribute _must_ have changed for the control UUID user. | `""` |
|
|
214
|
+
|
|
215
|
+
### Slack Integration
|
|
216
|
+
|
|
217
|
+
| Environment Variable | Description | Default |
|
|
218
|
+
|---|---|---|
|
|
219
|
+
| `SLACK_WEBHOOK_URL` | Slack Webhook URL for notifications. Requires the `slack` extra (`pip install LDAP-Monitor[slack]`). | `None` |
|
|
220
|
+
| `LDAP_WATCHDOG_SLACK_BULLETPOINT` | Bullet point character used in Slack and console output | ` \u2022 ` |
|
|
221
|
+
|
|
222
|
+
### Ignored Entries and Attributes
|
|
223
|
+
|
|
224
|
+
| Environment Variable | Description | Default |
|
|
225
|
+
|---|---|---|
|
|
226
|
+
| `LDAP_WATCHDOG_IGNORED_UUIDS` | Comma-separated list of UUIDs to ignore during comparison | `""` |
|
|
227
|
+
| `LDAP_WATCHDOG_IGNORED_ATTRIBUTES` | Comma-separated list of attributes to ignore during comparison | `""` |
|
|
228
|
+
| `LDAP_WATCHDOG_CONDITIONAL_IGNORED_ATTRIBUTES` | JSON string of attributes to conditionally ignore (see below) | `{}` |
|
|
229
|
+
|
|
230
|
+
### Conditional Ignored Attributes
|
|
231
|
+
|
|
232
|
+
The `LDAP_WATCHDOG_CONDITIONAL_IGNORED_ATTRIBUTES` variable accepts a JSON string where keys are attribute names and values are lists of values to ignore:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
export LDAP_WATCHDOG_CONDITIONAL_IGNORED_ATTRIBUTES='{
|
|
236
|
+
"objectClass": ["posixAccount"],
|
|
237
|
+
"memberOf": ["cn=mailing-list-user,ou=Accessgroups,dc=mouse,dc=com", "cn=interns,ou=Accessgroups,dc=mouse,dc=com"],
|
|
238
|
+
"organizationalStatus": ["researcher"]
|
|
239
|
+
}'
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Example Configuration
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
export LDAP_WATCHDOG_CONTROL_UUID='a71c6e4c-8881-4a03-95bf-4fc25d5e6359'
|
|
246
|
+
export LDAP_WATCHDOG_SERVER='ldaps://ldaps.intra.lan'
|
|
247
|
+
export LDAP_WATCHDOG_BASE_DN='dc=mouse,dc=com'
|
|
248
|
+
export LDAP_WATCHDOG_USERNAME='Emily'
|
|
249
|
+
export LDAP_WATCHDOG_PASSWORD='qwerty123'
|
|
250
|
+
export LDAP_WATCHDOG_USE_SSL='true'
|
|
251
|
+
export LDAP_WATCHDOG_REFRESH_RATE='60'
|
|
252
|
+
export LDAP_WATCHDOG_DISABLE_COLOR_OUTPUT='false'
|
|
253
|
+
export LDAP_WATCHDOG_IGNORED_UUIDS='e191c564-6e6d-42c1-ae51-bda0509fe846,8655e0d9-ecdc-46ce-ba42-1fa3dfbf5faa'
|
|
254
|
+
export LDAP_WATCHDOG_IGNORED_ATTRIBUTES='modifyTimestamp,phoneNumber,officeLocation,gecos'
|
|
255
|
+
export LDAP_WATCHDOG_CONDITIONAL_IGNORED_ATTRIBUTES='{"objectClass":["posixAccount"],"memberOf":["cn=mailing-list-user,ou=Accessgroups,dc=mouse,dc=com","cn=interns,ou=Accessgroups,dc=mouse,dc=com"],"organizationalStatus":["researcher"]}'
|
|
256
|
+
export SLACK_WEBHOOK_URL='https://hooks.slack.com/services/[...]'
|
|
257
|
+
|
|
258
|
+
ldap-watchdog
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Limitations
|
|
262
|
+
1. The _LDAP_WATCHDOG_CONDITIONAL_IGNORED_ATTRIBUTES_ configuration may unfortunately hide important changes that are not intended to be hidden. This may happen if an attribute has a single value which is changed. This is because conditional ignored attributes will hide changes to the attribute both when the value is changed __to__ _as well as_ __from__ the ignored value; for example, if a user is a memberOf _cn=mailing-list-user,ou=Accessgroups,dc=mouse,dc=com_ which gets __changed__ to _cn=super-administrator,ou=Accessgroups,dc=mouse,dc=com_, it will be missed.
|
|
263
|
+
2. Similar to #1, there is no real way to determine whether a change is really a change in some cases, or a removal and then addition in the same time. In theory, it doesn't really matter, however it's important to note.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
This project is licensed under [GPL3.0](/LICENSE).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ldap_monitor-1.0.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
|
|
2
|
+
ldap_watchdog/__init__.py,sha256=YiYwDqfLDRZrvJDL-leK572iHwF-7Mj_5bRto3K9uXc,89
|
|
3
|
+
ldap_watchdog/__main__.py,sha256=K4AzsfZB7eehqao1Q9xcF0r6KObxXMRQtQfRk_Esl1s,48
|
|
4
|
+
ldap_watchdog/config.py,sha256=SQl-UrZUpyLFbssmpVPycwyW7vqgw2FcKVaYWpWS99o,1723
|
|
5
|
+
ldap_watchdog/watchdog.py,sha256=DgJ3ThJ81sqQMJ2QDgCvr0llkN4mmKfQLQ2UumjCTZA,16351
|
|
6
|
+
ldap_monitor-1.0.0.dist-info/METADATA,sha256=o6NScMM4R5myjGkdMrOF2zeGE-VmNZdIstIDlEazEfs,11901
|
|
7
|
+
ldap_monitor-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
ldap_monitor-1.0.0.dist-info/entry_points.txt,sha256=vUEsGMph1KokKk_w3QRSM4mLUy8U9_2kzBmCscvKwq0,62
|
|
9
|
+
ldap_monitor-1.0.0.dist-info/top_level.txt,sha256=tayZiM9Sqc8R3XxKVAMWIgaPvqWOAeo3eZ1FjYhS7JI,14
|
|
10
|
+
ldap_monitor-1.0.0.dist-info/RECORD,,
|