Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit 6e3000c

Browse files
committed
feat: disable login instead of disabling account
1 parent 7f9cb24 commit 6e3000c

File tree

3 files changed

+43
-57
lines changed

3 files changed

+43
-57
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3-alpine
22

3-
RUN apk --no-cache add build-base openldap-dev python2-dev python3-dev
3+
RUN apk --no-cache add build-base openldap-dev python3-dev
44
RUN pip3 install python-ldap sqlalchemy requests
55

66
COPY templates ./templates

README.md

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Adds LDAP accounts to mailcow-dockerized and enables LDAP (e.g., Active Directory) authentication.
44

5-
* [How does it work](#how-does-it-work)
6-
* [Usage](#usage)
7-
* [LDAP Fine-tuning](#ldap-fine-tuning)
8-
* [Limitations](#limitations)
9-
* [WebUI and EAS authentication](#webui-and-eas-authentication)
10-
* [Two-way sync](#two-way-sync)
11-
* [Customizations and Integration support](#customizations-and-integration-support)
5+
- [How does it work](#how-does-it-work)
6+
- [Usage](#usage)
7+
- [LDAP Fine-tuning](#ldap-fine-tuning)
8+
- [Limitations](#limitations)
9+
- [WebUI and EAS authentication](#webui-and-eas-authentication)
10+
- [Two-way sync](#two-way-sync)
11+
- [Customizations and Integration support](#customizations-and-integration-support)
1212

1313
## How does it work
1414

@@ -19,41 +19,41 @@ A python script periodically checks and creates new LDAP accounts and deactivate
1919
1. Create a `data/ldap` directory. SQLite database for synchronization will be stored there.
2020
2. Extend your `docker-compose.override.yml` with an additional container:
2121

22-
```yaml
23-
ldap-mailcow:
24-
image: programmierus/ldap-mailcow
25-
network_mode: host
26-
container_name: mailcowcustomized_ldap-mailcow
27-
depends_on:
28-
- nginx-mailcow
29-
volumes:
30-
- ./data/ldap:/db:rw
31-
- ./data/conf/dovecot:/conf/dovecot:rw
32-
- ./data/conf/sogo:/conf/sogo:rw
33-
environment:
34-
- LDAP-MAILCOW_LDAP_URI=ldap(s)://dc.example.local
35-
- LDAP-MAILCOW_LDAP_BASE_DN=OU=Mail Users,DC=example,DC=local
36-
- LDAP-MAILCOW_LDAP_BIND_DN=CN=Bind DN,CN=Users,DC=example,DC=local
37-
- LDAP-MAILCOW_LDAP_BIND_DN_PASSWORD=BindPassword
38-
- LDAP-MAILCOW_API_HOST=https://mailcow.example.local
39-
- LDAP-MAILCOW_API_KEY=XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX
40-
- LDAP-MAILCOW_SYNC_INTERVAL=300
41-
- LDAP-MAILCOW_LDAP_FILTER=(&(objectClass=user)(objectCategory=person)(memberOf:1.2.840.113556.1.4.1941:=CN=Group,CN=Users,DC=example DC=local))
42-
- LDAP-MAILCOW_SOGO_LDAP_FILTER=objectClass='user' AND objectCategory='person' AND memberOf:1.2.840.113556.1.4.1941:='CN=Group,CN=Users,DC=example DC=local'
43-
```
22+
```yaml
23+
ldap-mailcow:
24+
image: ghcr.io/wardpieters/mailcow-ldap
25+
network_mode: host
26+
container_name: mailcowcustomized_ldap-mailcow
27+
depends_on:
28+
- nginx-mailcow
29+
volumes:
30+
- ./data/ldap:/db:rw
31+
- ./data/conf/dovecot:/conf/dovecot:rw
32+
- ./data/conf/sogo:/conf/sogo:rw
33+
environment:
34+
- LDAP-MAILCOW_LDAP_URI=ldap(s)://dc.example.local
35+
- LDAP-MAILCOW_LDAP_BASE_DN=OU=Mail Users,DC=example,DC=local
36+
- LDAP-MAILCOW_LDAP_BIND_DN=CN=Bind DN,CN=Users,DC=example,DC=local
37+
- LDAP-MAILCOW_LDAP_BIND_DN_PASSWORD=BindPassword
38+
- LDAP-MAILCOW_API_HOST=https://mailcow.example.local
39+
- LDAP-MAILCOW_API_KEY=XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX
40+
- LDAP-MAILCOW_SYNC_INTERVAL=300
41+
- LDAP-MAILCOW_LDAP_FILTER=(&(objectClass=user)(objectCategory=person)(memberOf:1.2.840.113556.1.4.1941:=CN=Group,CN=Users,DC=example DC=local))
42+
- LDAP-MAILCOW_SOGO_LDAP_FILTER=objectClass='user' AND objectCategory='person' AND memberOf:1.2.840.113556.1.4.1941:='CN=Group,CN=Users,DC=example DC=local'
43+
```
4444
4545
3. Configure environmental variables:
4646
47-
* `LDAP-MAILCOW_LDAP_URI` - LDAP (e.g., Active Directory) URI (must be reachable from within the container). The URIs are in syntax `protocol://host:port`. For example `ldap://localhost` or `ldaps://secure.domain.org`
48-
* `LDAP-MAILCOW_LDAP_BASE_DN` - base DN where user accounts can be found
49-
* `LDAP-MAILCOW_LDAP_BIND_DN` - bind DN of a special LDAP account that will be used to browse for users
50-
* `LDAP-MAILCOW_LDAP_BIND_DN_PASSWORD` - password for bind DN account
51-
* `LDAP-MAILCOW_API_HOST` - mailcow API url. Make sure it's enabled and accessible from within the container for both reads and writes
52-
* `LDAP-MAILCOW_API_KEY` - mailcow API key (read/write)
53-
* `LDAP-MAILCOW_SYNC_INTERVAL` - interval in seconds between LDAP synchronizations
54-
* **Optional** LDAP filters (see example above). SOGo uses special syntax, so you either have to **specify both or none**:
55-
* `LDAP-MAILCOW_LDAP_FILTER` - LDAP filter to apply, defaults to `(&(objectClass=user)(objectCategory=person))`
56-
* `LDAP-MAILCOW_SOGO_LDAP_FILTER` - LDAP filter to apply for SOGo ([special syntax](https://sogo.nu/files/docs/SOGoInstallationGuide.html#_authentication_using_ldap)), defaults to `objectClass='user' AND objectCategory='person'`
47+
- `LDAP-MAILCOW_LDAP_URI` - LDAP (e.g., Active Directory) URI (must be reachable from within the container). The URIs are in syntax `protocol://host:port`. For example `ldap://localhost` or `ldaps://secure.domain.org`
48+
- `LDAP-MAILCOW_LDAP_BASE_DN` - base DN where user accounts can be found
49+
- `LDAP-MAILCOW_LDAP_BIND_DN` - bind DN of a special LDAP account that will be used to browse for users
50+
- `LDAP-MAILCOW_LDAP_BIND_DN_PASSWORD` - password for bind DN account
51+
- `LDAP-MAILCOW_API_HOST` - mailcow API url. Make sure it's enabled and accessible from within the container for both reads and writes
52+
- `LDAP-MAILCOW_API_KEY` - mailcow API key (read/write)
53+
- `LDAP-MAILCOW_SYNC_INTERVAL` - interval in seconds between LDAP synchronizations
54+
- **Optional** LDAP filters (see example above). SOGo uses special syntax, so you either have to **specify both or none**:
55+
- `LDAP-MAILCOW_LDAP_FILTER` - LDAP filter to apply, defaults to `(&(objectClass=user)(objectCategory=person))`
56+
- `LDAP-MAILCOW_SOGO_LDAP_FILTER` - LDAP filter to apply for SOGo ([special syntax](https://sogo.nu/files/docs/SOGoInstallationGuide.html#_authentication_using_ldap)), defaults to `objectClass='user' AND objectCategory='person'`
5757

5858
4. Start additional container: `docker-compose up -d ldap-mailcow`
5959
5. Check logs `docker-compose logs ldap-mailcow`
@@ -63,8 +63,8 @@ A python script periodically checks and creates new LDAP accounts and deactivate
6363

6464
Container internally uses the following configuration templates:
6565

66-
* SOGo: `/templates/sogo/plist_ldap`
67-
* dovecot: `/templates/dovecot/ldap/passdb.conf`
66+
- SOGo: `/templates/sogo/plist_ldap`
67+
- dovecot: `/templates/dovecot/ldap/passdb.conf`
6868

6969
These files have been tested against Active Directory running on Windows Server 2019 domain controller. If necessary, you can edit and remount them through docker volumes. Some documentation on these files can be found here: [dovecot](https://doc.dovecot.org/configuration_manual/authentication/ldap/), [SOGo](https://sogo.nu/files/docs/SOGoInstallationGuide.html#_authentication_using_ldap)
7070

@@ -89,11 +89,3 @@ As a side-effect, It will also allow logging into mailcow UI using mailcow app p
8989
### Two-way sync
9090

9191
Users from your LDAP directory will be added (and deactivated if disabled/not found) to your mailcow database. Not vice-versa, and this is by design.
92-
93-
## Customizations and Integration support
94-
95-
External authentication (identity federation) is an enterprise feature [for mailcow](https://github.com/mailcow/mailcow-dockerized/issues/2316#issuecomment-491212921). That’s why I developed an external solution, and it is unlikely that it’ll be ever directly integrated into mailcow.
96-
97-
I’ve created this tool because I needed it for my regular work. You are free to use it for commercial needs. Please understand that I can work on issues only if they fall within the scope of my current work interests or if I’ll have some available free time (never happened for many years). I’ll do my best to review submitted PRs ASAP, though.
98-
99-
**You can always [contact me](mailto:[email protected]) to help you with the integration or for custom modifications on a paid basis. My current hourly rate (ActivityWatch tracked) is 100,-€ with 3h minimum commitment.**

api.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def add_user(email, name, active, quotum):
7070
def edit_user(email, active=None, name=None):
7171
attr = {}
7272
if (active is not None):
73-
attr['active'] = 1 if active else 0
73+
attr['active'] = 1 if active else 2
7474
if (name is not None):
7575
attr['name'] = name
7676

@@ -82,12 +82,6 @@ def edit_user(email, active=None, name=None):
8282
__post_request('api/v1/edit/mailbox', json_data)
8383

8484

85-
def __delete_user(email):
86-
json_data = [email]
87-
88-
__post_request('api/v1/delete/mailbox', json_data)
89-
90-
9185
def check_user(email):
9286
url = f"{api_host}/api/v1/get/mailbox/{email}"
9387
headers = {'X-API-Key': api_key, 'Content-type': 'application/json'}

0 commit comments

Comments
 (0)