Skip to content

Commit 0a4c3a6

Browse files
author
Programmierus
committed
Add LDAP Filter support for SOGo
Small corrections in README.md .gitignore .vscode
1 parent 807f7d0 commit 0a4c3a6

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
db
22
conf
33
__pycache__
4+
.vscode

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Adds LDAP accounts to mailcow-dockerized and enables LDAP (e.g., Active Director
88
* [Limitations](#limitations)
99
* [WebUI and EAS authentication](#webui-and-eas-authentication)
1010
* [Two-ways sync](#two-ways-sync)
11-
* [Customizations & Integration help](#customizations--integration-help)
11+
* [Customizations and Integration support](#customizations-and-integration-support)
1212

1313
## How does it work
1414

@@ -39,6 +39,7 @@ A python script periodically checks and creates new LDAP accounts and deactivate
3939
- LDAP-MAILCOW_API_KEY=XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX
4040
- LDAP-MAILCOW_SYNC_INTERVAL=300
4141
- 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'
4243
```
4344
4445
3. Configure environmental variables:
@@ -50,7 +51,9 @@ A python script periodically checks and creates new LDAP accounts and deactivate
5051
* `LDAP-MAILCOW_API_HOST` - mailcow API url. Make sure it's enabled and accessible from within the container for both reads and writes
5152
* `LDAP-MAILCOW_API_KEY` - mailcow API key (read/write)
5253
* `LDAP-MAILCOW_SYNC_INTERVAL` - interval in seconds between LDAP synchronizations
53-
* `LDAP-MAILCOW_LDAP_FILTER` - _optional_ LDAP filter to apply, defaults to `(&(objectClass=user)(objectCategory=person))`
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'`
5457

5558
4. Start additional container: `docker-compose up -d ldap-mailcow`
5659
5. Check logs `docker-compose logs ldap-mailcow`
@@ -69,7 +72,7 @@ These files have been tested against Active Directory running on Windows Server
6972

7073
### WebUI and EAS authentication
7174

72-
This tool enables authentication for Dovecot and SOGo, which means you will be able to log into POP3, SMTP, IMAP, and SOGo Web-Interface. **You will not be able to log into mailcow UI or EAS.**
75+
This tool enables authentication for Dovecot and SOGo, which means you will be able to log into POP3, SMTP, IMAP, and SOGo Web-Interface. **You will not be able to log into mailcow UI or EAS using your LDAP credentials by default.**
7376

7477
As a workaround, you can hook IMAP authentication directly to mailcow by adding the following code above [this line](https://github.com/mailcow/mailcow-dockerized/blob/48b74d77a0c39bcb3399ce6603e1ad424f01fc3e/data/web/inc/functions.inc.php#L608):
7578

@@ -81,16 +84,16 @@ As a workaround, you can hook IMAP authentication directly to mailcow by adding
8184
}
8285
```
8386

84-
As a side-effect, It will also allow logging into mailcow UI using mailcow app passwords (since they are valid for IMAP). **It is not a supported solution with mailcow and has to be done only on your own risk!**
87+
As a side-effect, It will also allow logging into mailcow UI using mailcow app passwords (since they are valid for IMAP). **It is not a supported solution with mailcow and has to be done only at your own risk!**
8588

86-
### Two-ways sync
89+
### Two-way sync
8790

8891
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.
8992

90-
## Customizations & Integration help
93+
## Customizations and Integration support
9194

92-
External authentication (identify 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 directly integrated into mailcow ever.
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.
9396

94-
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 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.
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.
9598

9699
**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.**

syncer.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,18 @@ def read_config():
135135

136136
for config_key in required_config_keys:
137137
if config_key not in os.environ:
138-
sys.exit (f"Required envrionment value {config_key} is not set")
138+
sys.exit (f"Required environment value {config_key} is not set")
139139

140140
config[config_key.replace('LDAP-MAILCOW_', '')] = os.environ[config_key]
141141

142+
if 'LDAP-MAILCOW_LDAP_FILTER' in os.environ and 'LDAP-MAILCOW_SOGO_LDAP_FILTER' not in os.environ:
143+
sys.exit('LDAP-MAILCOW_SOGO_LDAP_FILTER is required when you specify LDAP-MAILCOW_LDAP_FILTER')
144+
145+
if 'LDAP-MAILCOW_SOGO_LDAP_FILTER' in os.environ and 'LDAP-MAILCOW_LDAP_FILTER' not in os.environ:
146+
sys.exit('LDAP-MAILCOW_LDAP_FILTER is required when you specify LDAP-MAILCOW_SOGO_LDAP_FILTER')
147+
142148
config['LDAP_FILTER'] = os.environ['LDAP-MAILCOW_LDAP_FILTER'] if 'LDAP-MAILCOW_LDAP_FILTER' in os.environ else '(&(objectClass=user)(objectCategory=person))'
149+
config['SOGO_LDAP_FILTER'] = os.environ['LDAP-MAILCOW_SOGO_LDAP_FILTER'] if 'LDAP-MAILCOW_SOGO_LDAP_FILTER' in os.environ else "objectClass='user' AND objectCategory='person'"
143150

144151
return config
145152

@@ -160,7 +167,8 @@ def read_sogo_plist_ldap_template():
160167
ldap_uri=config['LDAP_URI'],
161168
ldap_base_dn=config['LDAP_BASE_DN'],
162169
ldap_bind_dn=config['LDAP_BIND_DN'],
163-
ldap_bind_dn_password=config['LDAP_BIND_DN_PASSWORD']
170+
ldap_bind_dn_password=config['LDAP_BIND_DN_PASSWORD'],
171+
sogo_ldap_filter=config['SOGO_LDAP_FILTER']
164172
)
165173

166174
def read_dovecot_extra_conf():

templates/sogo/plist_ldap

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<key>canAuthenticate</key>
3333
<string>YES</string>
3434

35+
<key>filter</key>
36+
<string>$sogo_ldap_filter</string>
37+
3538
<key>isAddressBook</key>
3639
<string>NO</string>
3740
<key>displayName</key>

0 commit comments

Comments
 (0)