mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.27k stars 1.12k forks source link

"Login Failed" with Generic OIDC SSO with Authentik #5445

Open derfabianpeter opened 9 months ago

derfabianpeter commented 9 months ago

Contribution guidelines

I've found a bug and checked that ...

Description

I've set up mailcow on "Nightly: 45717ccd" since I wanted to test the SSO setup with Authentik as per [this blog post](https://mailcow.email/posts/2023/mailcow-idp/).

Configuration in mailcow:

- Authorization Endpoint: https://id.example.de/application/o/authorize
- Token Endpoint: https://id.example.de/application/o/token
- Userinfo Endpoint: https://id.example.de/application/o/userinfo
- Redirect URL: https://mail.example.de
- Attribute Mapping: "default" maps to the Default Template
- Client ID & Secret as shown in Authentik

Configuration in Authentik:

- Added a property mapping / scope named "maildow-dedicated" in Authentik
- Added the following expression as value for attribute mapping:

#####
return { "mailcow_template": "default" }
#####

- Added the scope to the OpenID provider 
- Validated that the claim "mailcow_template" with value "default" is also added to the ID token

Everything looks configured correctly, yet when logging in via SSO I get "Login failed/Anmeldung fehlgeschlagen".

Logs:

# mailcow UI logs:

["login_failed","Invalid response received from Authorization Server. Expected JSON."]

# nginx logs:

mailcowdockerized-php-fpm-mailcow-1    | 172.22.1.10 -  07/Oct/2023:15:18:03 +0200 "GET /index.php" 200
mailcowdockerized-nginx-mailcow-1      | 79.232.84.69 - - [07/Oct/2023:15:18:03 +0200] "GET /?code=ea2889c4e5594a7bbc3073a0a570ce2f&state=7f18397e8449f7727f3d4a9a925c4f4e HTTP/2.0" 200 11270 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
mailcowdockerized-php-fpm-mailcow-1    | fd4d:6169:6c63:6f77::d -  07/Oct/2023:15:18:04 +0200 "GET /json_api.php" 200
mailcowdockerized-nginx-mailcow-1      | 79.232.84.69 - - [07/Oct/2023:15:18:04 +0200] "GET /api/v1/get/passwordpolicy/html HTTP/2.0" 200 20 "https://mail.ayedo.de/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"

Steps to reproduce:

1. Create OpenID Provider + Application in Authentik
2. Configure Identity Provider with new credentials in mailcow
3. Login via SSO

Which branch are you using?

nightly

Operating System:

Ubuntu 22.04

Server/VM specifications:

16GB Ram, 4 Cores

Is Apparmor, SELinux or similar active?

no

Virtualization technology:

KVM

Docker version:

24.0.6

docker-compose version or docker compose version:

Docker Compose version v2.21.0

mailcow version:

2023-09

Reverse proxy:

-

Logs of git diff:

No changes made on my end

Logs of iptables -L -vn:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 108K   55M DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 108K   55M DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
89817   49M ACCEPT     all  --  *      br-mailcow  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
 7795  481K DOCKER     all  --  *      br-mailcow  0.0.0.0/0            0.0.0.0/0           
10205 6230K ACCEPT     all  --  br-mailcow !br-mailcow  0.0.0.0/0            0.0.0.0/0           
 7627  471K ACCEPT     all  --  br-mailcow br-mailcow  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.249         tcp dpt:6379
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.5           tcp dpt:8983
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.8           tcp dpt:3306
  115  7132 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.10          tcp dpt:443
    1    64 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.10          tcp dpt:80
    2   100 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.253         tcp dpt:587
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:12345
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:4190
   43  2564 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.253         tcp dpt:465
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:995
    7   364 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.253         tcp dpt:25
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:993
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:143
    0     0 ACCEPT     tcp  --  !br-mailcow br-mailcow  0.0.0.0/0            172.22.1.250         tcp dpt:110

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
10205 6230K DOCKER-ISOLATION-STAGE-2  all  --  br-mailcow !br-mailcow  0.0.0.0/0            0.0.0.0/0           
    0     0 DOCKER-ISOLATION-STAGE-2  all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0           
 112K   57M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  *      br-mailcow  0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      docker0  0.0.0.0/0            0.0.0.0/0           
10564 6275K RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain DOCKER-USER (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  11M 6054M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Logs of ip6tables -L -vn:

# Warning: ip6tables-legacy tables present, use ip6tables-legacy to see them
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
19972   17M DOCKER-USER  all      *      *       ::/0                 ::/0                
19972   17M DOCKER-ISOLATION-STAGE-1  all      *      *       ::/0                 ::/0                
13292   17M ACCEPT     all      *      br-mailcow  ::/0                 ::/0                 ctstate RELATED,ESTABLISHED
 6022  413K DOCKER     all      *      br-mailcow  ::/0                 ::/0                
  658 63387 ACCEPT     all      br-mailcow !br-mailcow  ::/0                 ::/0                
 6021  413K ACCEPT     all      br-mailcow br-mailcow  ::/0                 ::/0                
    0     0 ACCEPT     all      *      docker0  ::/0                 ::/0                 ctstate RELATED,ESTABLISHED
    0     0 DOCKER     all      *      docker0  ::/0                 ::/0                
    0     0 ACCEPT     all      docker0 !docker0  ::/0                 ::/0                
    0     0 ACCEPT     all      docker0 docker0  ::/0                 ::/0                

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::d  tcp dpt:443
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::d  tcp dpt:80
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::e  tcp dpt:587
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::f  tcp dpt:4190
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::e  tcp dpt:465
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::f  tcp dpt:995
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::e  tcp dpt:25
    1    80 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::f  tcp dpt:993
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::f  tcp dpt:143
    0     0 ACCEPT     tcp      !br-mailcow br-mailcow  ::/0                 fd4d:6169:6c63:6f77::f  tcp dpt:110

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  658 63387 DOCKER-ISOLATION-STAGE-2  all      br-mailcow !br-mailcow  ::/0                 ::/0                
    0     0 DOCKER-ISOLATION-STAGE-2  all      docker0 !docker0  ::/0                 ::/0                
23624   18M RETURN     all      *      *       ::/0                 ::/0                

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all      *      br-mailcow  ::/0                 ::/0                
    0     0 DROP       all      *      docker0  ::/0                 ::/0                
  812 82344 RETURN     all      *      *       ::/0                 ::/0                

Chain DOCKER-USER (1 references)
 pkts bytes target     prot opt in     out     source               destination         
1440K  963M RETURN     all      *      *       ::/0                 ::/0

Logs of iptables -L -vn -t nat:

# Warning: iptables-legacy tables present, use iptables-legacy to see them
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1511 82033 DOCKER     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DOCKER     all  --  *      *       0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 2778  204K MASQUERADE  all  --  *      !br-mailcow  172.22.1.0/24        0.0.0.0/0           
    0     0 MASQUERADE  all  --  *      !docker0  172.17.0.0/16        0.0.0.0/0           
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.249         172.22.1.249         tcp dpt:6379
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.5           172.22.1.5           tcp dpt:8983
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.8           172.22.1.8           tcp dpt:3306
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.10          172.22.1.10          tcp dpt:443
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.10          172.22.1.10          tcp dpt:80
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.253         172.22.1.253         tcp dpt:587
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:12345
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:4190
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.253         172.22.1.253         tcp dpt:465
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:995
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.253         172.22.1.253         tcp dpt:25
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:993
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:143
    0     0 MASQUERADE  tcp  --  *      *       172.22.1.250         172.22.1.250         tcp dpt:110

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 RETURN     all  --  br-mailcow *       0.0.0.0/0            0.0.0.0/0           
    0     0 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0           
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            127.0.0.1            tcp dpt:7654 to:172.22.1.249:6379
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            127.0.0.1            tcp dpt:18983 to:172.22.1.5:8983
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            127.0.0.1            tcp dpt:13306 to:172.22.1.8:3306
  120  7452 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443 to:172.22.1.10:443
    1    64 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 to:172.22.1.10:80
    2   100 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:587 to:172.22.1.253:587
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            127.0.0.1            tcp dpt:19991 to:172.22.1.250:12345
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:4190 to:172.22.1.250:4190
  166  9944 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:465 to:172.22.1.253:465
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:995 to:172.22.1.250:995
    7   364 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:25 to:172.22.1.253:25
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:993 to:172.22.1.250:993
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:143 to:172.22.1.250:143
    0     0 DNAT       tcp  --  !br-mailcow *       0.0.0.0/0            0.0.0.0/0            tcp dpt:110 to:172.22.1.250:110

Logs of ip6tables -L -vn -t nat:

# Warning: ip6tables-legacy tables present, use ip6tables-legacy to see them
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   17  1296 DOCKER     all      *      *       ::/0                 ::/0                 ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DOCKER     all      *      *       ::/0                !::1                  ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  620 57782 MASQUERADE  all      *      !br-mailcow  fd4d:6169:6c63:6f77::/64  ::/0                
    0     0 MASQUERADE  all      *      docker0  ::/0                 ::/0                 ADDRTYPE match dst-type LOCAL
    0     0 MASQUERADE  all      *      !docker0  fd00:dead:beef:c0::/80  ::/0                
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::d  fd4d:6169:6c63:6f77::d  tcp dpt:443
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::d  fd4d:6169:6c63:6f77::d  tcp dpt:80
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::e  fd4d:6169:6c63:6f77::e  tcp dpt:587
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::f  fd4d:6169:6c63:6f77::f  tcp dpt:4190
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::e  fd4d:6169:6c63:6f77::e  tcp dpt:465
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::f  fd4d:6169:6c63:6f77::f  tcp dpt:995
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::e  fd4d:6169:6c63:6f77::e  tcp dpt:25
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::f  fd4d:6169:6c63:6f77::f  tcp dpt:993
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::f  fd4d:6169:6c63:6f77::f  tcp dpt:143
    0     0 MASQUERADE  tcp      *      *       fd4d:6169:6c63:6f77::f  fd4d:6169:6c63:6f77::f  tcp dpt:110

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    4   320 RETURN     all      br-mailcow *       ::/0                 ::/0                
    0     0 RETURN     all      docker0 *       ::/0                 ::/0                
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:443 to:[fd4d:6169:6c63:6f77::d]:443
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:80 to:[fd4d:6169:6c63:6f77::d]:80
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:587 to:[fd4d:6169:6c63:6f77::e]:587
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:4190 to:[fd4d:6169:6c63:6f77::f]:4190
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:465 to:[fd4d:6169:6c63:6f77::e]:465
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:995 to:[fd4d:6169:6c63:6f77::f]:995
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:25 to:[fd4d:6169:6c63:6f77::e]:25
    1    80 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:993 to:[fd4d:6169:6c63:6f77::f]:993
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:143 to:[fd4d:6169:6c63:6f77::f]:143
    0     0 DNAT       tcp      !br-mailcow *       ::/0                 ::/0                 tcp dpt:110 to:[fd4d:6169:6c63:6f77::f]:110

DNS check:

104.18.22.201
104.18.23.201
VermiumSifell commented 8 months ago

I can see this is still a issue

davidus05 commented 8 months ago

I can confirm that OIDC does not work with authentik. Also clicking "Test connection" does not work and shows a strange response.

Support for authentik was also discussed here: https://github.com/mailcow/mailcow-dockerized/issues/2316

{"type":"error","msg":"Cannot edit item"}

image

FreddleSpl0it commented 8 months ago

Please update your mailcow nightly and try again. I found an issue which was caused by removing all trailing / from the IdP URLs before saving. All HTTP requests then ended up at the wrong endpoint and Authentik returned 405 Method not allowed

Not sure if it was the only issue. Test Connection will continue to fail because for Authentik, client_id and client_secret are not enough to test the credentials with grant_type=client_credentials https://goauthentik.io/docs/providers/oauth2/client_credentials

Commit: https://github.com/mailcow/mailcow-dockerized/commit/1a302d8335289aa455d81d040b4cd814755795c8

davidus05 commented 8 months ago

Awesome, thank you! Fixed and working, except for mailboxes not being created on first login.

FreddleSpl0it commented 8 months ago

Probably because generic-oidc provider is only requesting hardcoded scopes openid profile email. I'll try to add a input field to set custom scopes

FreddleSpl0it commented 8 months ago

The requested client scopes are now configurable for generic-oidc. Now mailbox creation on first login is working for me.

Commit: https://github.com/mailcow/mailcow-dockerized/commit/dc2f61a27c3ca1eecf412478a94a75f2cef45637

davidus05 commented 8 months ago

Which scopes do you specify to get mailbox creation working?

FreddleSpl0it commented 8 months ago

In Authentik, go to Providers -> click the Edit button of your OAuth provider, then expand “Advanced protocol settings” and in Scopes select openid, email, profile and your created Property Mapping. In my case it was mailcow_template in your case it should be maildow-dedicated. In mailcow add maildow-dedicated to the scopes separated by whitespace.

davidus05 commented 8 months ago

Hmm, there seems to be something wrong at my end. Maybe because I have multiple domains?

Property mapping is set correctly, log in is working, but protocols are all red and logging into Webmail is unauthorized.

My expression:return { "mailcow_template": "default" }

FreddleSpl0it commented 8 months ago

Can you log in as admin and check the mailcow UI Logs? Maybe there is a hint.

davidus05 commented 8 months ago

Not really ...

["logged_in_as","mail@example.com"] Call ["identity_provider","mail@example.com","user"]

Did you change anything with the template?

The user seems to be recognized and created, but no mailbox. I can't even find that user anywhere in the admin view.

derfabianpeter commented 8 months ago

I've updated and while the original error has vanished, I now see the following in the logs after trying to login via IDP (which fails):


["identity_provider",null,null]
FreddleSpl0it commented 8 months ago

@derfabianpeter i have added some additional log messages. Please update and try again. https://github.com/mailcow/mailcow-dockerized/commit/89ed9147a658bd9004354d742e2fc2472b6e7699

@davidus05 Seems like some error occurred on mailbox creation. This is the function https://github.com/mailcow/mailcow-dockerized/blob/89ed9147a658bd9004354d742e2fc2472b6e7699/data/web/inc/functions.mailbox.inc.php#L1318. I'll try to add more error handling

derfabianpeter commented 8 months ago

@FreddleSpl0it I've updated as you suggested. Logging has improved:

Bildschirmfoto 2023-10-30 um 14 18 46

I've configured the attribute mapping as you suggested in one of your previous comments and additionally added mailcow-dedicated to the claims in Mailcow. Same result unfortunately.

EDIT: I actually changed the property mapping and scope name in Authentik to mailcow_template (instead of mailcow-dedicated) and now it all works!

Aterfax commented 7 months ago

Would one of you folks be willing to fully document the steps for getting this working as a Gist or similar?

I'd be happy to see if I can convert it into documentation on the Authentik community pages.

Had a crack at getting this working today but was getting curl failures against the token endpoint.

["login_failed","cURL error 28: Failed to connect to auth.domain.com port 443 after 131001 ms: Couldn't connect to server (see https:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html) for https:\/\/auth.domain.com\/application\/o\/token\/"]
davidroler commented 6 months ago

Hi there,

I'm trying to setup mailcow to work with Authentik following the instructions provided for Keycloak and the comments add to this thread.

I'm not getting any authentication error, but after authenticating on Authentik I'm getting redirected to the URL https://authentik.example.com/application/o/mailcow/.well-known/openid-configuration with the following content.

Does anybody know what could be missing on my configuration?

{ "issuer": "https://authentik.example.com/application/o/mailcow/", "authorization_endpoint": "https://authentik.example.com/application/o/authorize/", "token_endpoint": "https://authentik.example.com/application/o/token/", "userinfo_endpoint": "https://authentik.example.com/application/o/userinfo/", "end_session_endpoint": "https://authentik.example.com/application/o/mailcow/end-session/", "introspection_endpoint": "https://authentik.example.com/application/o/introspect/", "revocation_endpoint": "https://authentik.example.com/application/o/revoke/", "device_authorization_endpoint": "https://authentik.example.com/application/o/device/", "response_types_supported": [ "code", "id_token", "id_token token", "code token", "code id_token", "code id_token token" ], "response_modes_supported": [ "query", "fragment", "form_post" ], "jwks_uri": "https://authentik.example.com/application/o/mailcow/jwks/", "grant_types_supported": [ "authorization_code", "refresh_token", "implicit", "client_credentials", "password", "urn:ietf:params:oauth:grant-type:device_code" ], "id_token_signing_alg_values_supported": [ "RS256" ], "subject_types_supported": [ "public" ], "token_endpoint_auth_methods_supported": [ "client_secret_post", "client_secret_basic" ], "acr_values_supported": [ "goauthentik.io/providers/oauth2/default" ], "scopes_supported": [ "openid", "email", "profile", "ak_proxy", "mailcow_template" ], "request_parameter_supported": false, "claims_supported": [ "sub", "iss", "aud", "exp", "iat", "auth_time", "acr", "amr", "nonce", "sid", "ak_proxy", "email", "email_verified", "mailcow_template", "name", "given_name", "preferred_username", "nickname", "groups" ], "claims_parameter_supported": false, "code_challenge_methods_supported": [ "plain", "S256" ] }

davidroler commented 6 months ago

I've just found the issue on my configuration. There was a redirect URI missing on Authentik with the value http://mail.example.com

After adding the URI http://mail.example.com to service provider and updating Mailcow it worked just fine for me.

alexsalex commented 5 months ago

It will be nice to have the instruction for authentik too... Like you write for keycloak.

vnen commented 5 months ago

It worked for me with Authentik. Basic instructions:

Scope mapping

Provider

Under Applications > Providers create a new OAuth2/OpenID Provider.

Application

Under Applications > Applications, create a new application.

On the list of applications, click on the mailcow provider name. This will get you to the provider page with all the URLs.

mailcow settings

Go to System > Configuration. Then Access > Identity Provider.

Do not bother clicking on "Test Connection" because it won't work for the reasons mentioned before in this issue.

This should be enough. You can create a new user to test the login. Their email address will be set as a new mailbox in mailcow.

If you want a different mailbox template, you can add this to the user's Attributes box in Authentik:

mailcow_template: some_template

Assuming that some_template is mapped to a template in the mailcow config.

I hope this is helpful for anyone trying this.

pbvdven commented 3 months ago

Is there a way to add the users display name from authentik to mailcow thats now not getting trough to mailcow when the users mailbox is created.

pbvdven commented 3 months ago

@vnen Did you ever tried setting up authentik ldap as provider in mailcow? i would like to auto setup email in nextcloud for the users but for that to work the passwords need to be the same with oidc the user needs to create an app password in mailcow thats not great solution i would rather use there authentik password.

but Ive i can connect mailcow to authentik ldap that no issue the passwords would be the same except you probably cant use both in mailcow at the moment you should be able to use oidc and ldap at the same time that also solves the problem. But for now i rather have ldap with auto email setup in nextcloud that also has SSO and users that can use there normal password for imap connections instead of app password.

Creating an app password is an issue most of my users use there own desktop or mobile clients for email and dont have any clue where to do that i dont want to create an helpdesk for this.

aep commented 1 month ago

the instructions from vnen work for me, except i get

["login_failed","mailbox creation failed"]
["identity_provider","aep@domain"]

how do you even debug the oidc flow? is there a way to get a proper log? the docker logs dont show anything useful and the ui is very high level


with a pre-created mailbox i get one step further. login to the mailcow webui works, but sogo says "Unauthorized"


ok finally got it working. after setting up oidc, you need to still create the users in mailcow, and then restart sogo.

DecDuck commented 5 days ago

@pbvdven sorry to bump such an old thread, but did you manage to get Mailcow to import display names from Authentik?