ActiveDirectory/PostfixDovecot: различия между версиями

Материал из ALT Linux Wiki
Нет описания правки
Строка 1: Строка 1:
{{Шаблон:Stub}}
Настройка Postfix и Dovecot для аутентификации пользователей в [[Active Directory]].


Настройка Postfix для аутентификации пользователей в [[Active Directory]].
{{Attention|Доступ к службам реализован только с помощью SSL по соображениям безопасности}}.
 
{{Note|Домен: '''test.alt'''}}


== Настройка ==
== Настройка ==
Строка 26: Строка 28:
inet_protocols = ipv4
inet_protocols = ipv4


sender_bcc_maps =
# Mappings
recipient_bcc_maps =
virtual_mailbox_domains = test.alt
relay_domains =
virtual_mailbox_maps = ldap:/etc/postfix/ad_local_recipients.cf
virtual_alias_maps = ldap:/etc/postfix/ad_mail_groups.cf
virtual_transport = dovecot


# SSL/TLS
smtpd_use_tls = yes
smtpd_tls_security_level = encrypt
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = test.alt
smtpd_sasl_local_domain = test.alt
virtual_mailbox_domains = test.alt
smtpd_sasl_path = private/auth
transport_maps = hash:/etc/postfix/transport
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = ldap:/etc/postfix/ad_sender_login.cf
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /var/lib/ssl/certs/postfix.cert
smtpd_tls_key_file = /var/lib/ssl/private/postfix.key
smtpd_tls_CAfile = /var/lib/ssl/certs/postfix.pem
</source>


# Used to verify sender.
== master.cf ==
smtpd_sender_login_maps = proxy:ldap:/etc/postfix/ad_sender_login_maps.cf</source>
В файл {{path|master.cf}} необходимо добавить:
<source lang="text">smtp      inet  n      -      -      -      -      smtpd
dovecot  unix  -      n      n      -      -      pipe
  flags=DRhu user=mail:mail argv=/usr/libexec/dovecot/deliver -d ${recipient}
smtps    inet  n      -      n      -      -      smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject</source>


==== ad_sender_login_maps.cf ====
==== ad_local_recipients.cf ====
<source lang="ini">server_host     = test.alt
<source lang="ini">version = 3
server_port    = 389
server_host = ldap://test.alt:3268
version        = 3
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind            = yes
bind_pw = Pa$$word
start_tls      = no
search_base = dc=test,dc=alt
bind_dn         = cn=vmail,cn=Users,dc=test,dc=alt
search_scope = subtree
bind_pw         = Pa$$word
query_filter = (&(|(mail=%s)(otherMailbox=%u@%d))(sAMAccountType=805306368))
search_base     = cn=Users,dc=test,dc=alt
result_attribute = mail
scope          = sub
cache = no</source>
query_filter   = (&(userPrincipalName=%s)(objectClass=person)(!(userAccountControl=514)))
result_attribute= userPrincipalName
debuglevel      = 0</source>


==== ad_virtual_group_maps.cf ====
==== ad_mail_groups.cf ====
<source lang="ini">server_host     = test.alt
<source lang="ini">debuglevel = 0
server_port    = 389
version = 3
version        = 3
server_host = ldap://test.alt
bind           = yes
bind = yes
start_tls      = no
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind_dn         = cn=vmail,cn=Users,dc=test,dc=alt
bind_pw = Pa$$word
bind_pw         = Pa$$word
search_base = dc=test,dc=alt
search_base     = cn=Users,dc=test,dc=alt
timeout = 3
scope          = sub
query_filter = (&(mail=%s)(sAMAccountType=268435456))
query_filter   = (&(objectClass=group)(mail=%s))
result_filter = %s
result_attribute = mail
special_result_attribute = member
special_result_attribute = member
leaf_result_attribute = mail
scope = sub</source>
result_attribute= userPrincipalName
debuglevel      = 0</source>


==== ad_virtual_mailbox_maps.cf ====
==== ad_sender_login.cf ====
<source lang="ini">server_host     = test.alt
<source lang="ini">debuglevel = 0
server_port    = 389
version = 3
version        = 3
server_host = test.alt:3268
bind           = yes
bind = yes
start_tls      = no
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind_dn         = cn=vmail,cn=Users,dc=test,dc=alt
bind_pw = Pa$$word
bind_pw         = Pa$$word
search_base = dc=test,dc=alt
search_base     = cn=Users,dc=test,dc=alt
query_filter = (&(|(mail=%s)(otherMailbox=%s))(sAMAccountType=805306368))
scope          = sub
result_attribute = userPrincipalName</source>
query_filter   = (&(objectclass=person)(userPrincipalName=%s))
result_attribute= userPrincipalName
result_format  = %d/%u/Maildir/
debuglevel      = 0</source>


==== transport ====
==== transport ====
Строка 92: Строка 105:


Проверка пользователя почты {{term|petrov}}:
Проверка пользователя почты {{term|petrov}}:
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ad_virtual_mailbox_maps.cf
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ad_local_recipients.cf
test.alt/petrov/Maildir/</source>
petrov@test.alt</source>


Проверка входа:
Проверка входа:
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ad_sender_login_maps.cf
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ad_sender_login.cf
petrov@test.alt</source>
petrov@test.alt</source>


Строка 104: Строка 117:
# samba-tool group addmembers Sales ivanov,petrov
# samba-tool group addmembers Sales ivanov,petrov
Added members to group Sales
Added members to group Sales
# postmap -q sales@test.alt ldap:/etc/postfix/ad_virtual_group_maps.cf
# postmap -q sales@test.alt ldap:/etc/postfix/ad_mail_groups.cf
ivanov@test.alt,ivanov@test.alt,petrov@test.alt,petrov@test.alt</source>
sales@test.alt,ivanov@test.alt,petrov@test.alt</source>
 
=== Перезапуск службы ===
Перезапускаем службу {{cmd|postfix}}:
 
service postfix restart


== Настройка Dovecot ==
== Настройка Dovecot ==
Строка 113: Строка 131:
  apt-get install dovecot
  apt-get install dovecot


=== Изменение файлов ===
Создаём файл {{path|/etc/dovecot/dovecot-ldap.conf.ext}}
Создаём файл {{path|/etc/dovecot/dovecot-ldap.conf.ext}}
<source lang="ini">hosts           = test.alt:389
<source lang="ini">hosts           = test.alt:3268
ldap_version   = 3
ldap_version     = 3
auth_bind       = yes
auth_bind       = yes
dn             = cn=vmail,cn=Users,dc=test,dc=alt
auth_bind_userdn = %Lu
dnpass         = Pa$$word
dn               = cn=vmail,cn=Users,dc=test,dc=alt
base           = cn=Users,dc=example,dc=com
dnpass           = Pa$$word
scope           = subtree
base             = cn=Users,dc=test,dc=alt
deref           = never
scope           = subtree
user_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl=514)))
deref           = finding
pass_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl=514)))
 
pass_attrs     = userPassword=password
user_filter = (&(sAMAccountType=805306368)(|(userPrincipalName=%Lu)(mail=%Lu)))
default_pass_scheme = CRYPT
user_attrs  = =uid=8
user_attrs      = =home=/var/vmail/vmail1/%Ld/%Ln/Maildir/,=mail=maildir:/var/vmail/vmail1/%Ld/%Ln/Maildir/</source>
pass_filter = (&(sAMAccountType=805306368)(userPrincipalName=%Lu))
pass_attrs = userPrincipalName=user</source>
 
В каталоге {{path|/etc/dovecot/conf.d}} изменяем файлы для домена {{term|test.alt}}:
 
==== 10-auth.conf ====
<source lang="ini">auth_username_format = %Lu
auth_username_format = %Lu
auth_gssapi_hostname = "$ALL"
auth_krb5_keytab = /etc/dovecot/dovecot.keytab
auth_use_winbind = no
auth_winbind_helper_path = /usr/bin/ntlm_auth
auth_failure_delay = 2 secs
auth_mechanisms = plain
!include auth-ldap.conf.ext</source>
 
==== 10-mail.conf ====
<source lang="ini">mail_location = maildir:/var/mail/%d/%n:INBOX=/var/mail/%d/%n/Inbox
mail_uid = mail
mail_gid = mail
first_valid_uid = 5
first_valid_gid = 5</source>
 
==== 10-master.conf ====
<source lang="ini">service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 0
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
}
service auth {
  unix_listener auth-userdb {
  }
  unix_listener /var/spool/postfix/private/auth {
    mode = 0600
    user = postfix
    group = postfix
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
  }
}</source>
 
==== 15-lda.conf ====
<source lang="ini">protocol lda {
  hostname = test.alt
  postmaster_address = administrator@test.alt
}</source>
 
==== 15-mailboxes.conf ====
<source lang="ini">namespace inbox {
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
}</source>


=== Перезапуск службы ===
Перезапускаем службу {{cmd|dovecot}} и включаем её в автозапуск:
Перезапускаем службу {{cmd|dovecot}} и включаем её в автозапуск:


Строка 133: Строка 243:
  service dovecot restart
  service dovecot restart


=== Проверяем вход ===
== Отладка ==
 
{{Attention|Журнал работы Postfix и Dovecot ведётся в файле {{path|/var/log/maillog}}}}
 
Для Postfix в файле {{path|/etc/postfix/master.cf}} добавьте параметр -v — вместо
smtps    inet  n      -      n      -      -      smtpd
должно быть
smtps    inet  n      -      n      -      -      smtpd -v


<source lang="text"># telnet localhost 143
Для Dovecot добавьте в {{path|/etc/dovecot/conf.d/10-logging.conf}}
Trying 127.0.0.1...
<source lang="ini">auth_verbose = yes
Connected to localhost.
auth_debug = yes
Escape character is '^]'.
mail_debug = yes</source>
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN] Dovecot ready.
. login petrov@test.alt Pa$$word
. NO [AUTHENTICATIONFAILED] Authentication failed.
. quit</source>


== Ссылки ==
== Ссылки ==

Версия от 15:18, 30 марта 2016

Настройка Postfix и Dovecot для аутентификации пользователей в Active Directory.

Внимание! Доступ к службам реализован только с помощью SSL по соображениям безопасности

.

Примечание: Домен: test.alt


Настройка

Создание пользователя в Active Directory

samba-tool user add -W Users vmail
samba-tool user setexpiry vmail --noexpiry

Настройка Postfix

apt-get install postfix-ldap

Изменение файлов

В каталоге /etc/postfix изменяем файлы для домена test.alt:

main.cf

# Global Postfix configuration file.  This file lists only a small subset
# of all parameters.  For the syntax, and for a complete parameter list,
# see the postconf(5) manual page.  For a commented and more complete
# version of this file see /etc/postfix/main.cf.dist

mailbox_command = /usr/bin/procmail -a $DOMAIN -d $LOGNAME
inet_protocols = ipv4

# Mappings
virtual_mailbox_domains = test.alt
virtual_mailbox_maps = ldap:/etc/postfix/ad_local_recipients.cf
virtual_alias_maps = ldap:/etc/postfix/ad_mail_groups.cf
virtual_transport = dovecot

# SSL/TLS
smtpd_use_tls = yes
smtpd_tls_security_level = encrypt
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = test.alt
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = ldap:/etc/postfix/ad_sender_login.cf
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /var/lib/ssl/certs/postfix.cert
smtpd_tls_key_file = /var/lib/ssl/private/postfix.key
smtpd_tls_CAfile = /var/lib/ssl/certs/postfix.pem

master.cf

В файл master.cf необходимо добавить:

smtp      inet  n       -       -       -       -       smtpd
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=mail:mail argv=/usr/libexec/dovecot/deliver -d ${recipient}
smtps     inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

ad_local_recipients.cf

version = 3
server_host = ldap://test.alt:3268
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind_pw = Pa$$word
search_base = dc=test,dc=alt
search_scope = subtree
query_filter = (&(|(mail=%s)(otherMailbox=%u@%d))(sAMAccountType=805306368))
result_attribute = mail
cache = no

ad_mail_groups.cf

debuglevel = 0
version = 3
server_host = ldap://test.alt
bind = yes
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind_pw = Pa$$word
search_base = dc=test,dc=alt
timeout = 3
query_filter = (&(mail=%s)(sAMAccountType=268435456))
result_filter = %s
result_attribute = mail
special_result_attribute = member
scope = sub

ad_sender_login.cf

debuglevel = 0
version = 3
server_host = test.alt:3268
bind = yes
bind_dn = cn=vmail,cn=users,dc=test,dc=alt
bind_pw = Pa$$word
search_base = dc=test,dc=alt
query_filter = (&(|(mail=%s)(otherMailbox=%s))(sAMAccountType=805306368))
result_attribute = userPrincipalName

transport

test.alt        dovecot

Запуск postmap

postmap hash:/etc/postfix/transport

Тестируем работу

Проверка пользователя почты petrov:

# postmap -q petrov@test.alt ldap:/etc/postfix/ad_local_recipients.cf
petrov@test.alt

Проверка входа:

# postmap -q petrov@test.alt ldap:/etc/postfix/ad_sender_login.cf
petrov@test.alt

Проверка общего адреса e-mail:

# samba-tool group add --mail-address=sales@test.alt Sales
Added group Sales
# samba-tool group addmembers Sales ivanov,petrov
Added members to group Sales
# postmap -q sales@test.alt ldap:/etc/postfix/ad_mail_groups.cf
sales@test.alt,ivanov@test.alt,petrov@test.alt

Перезапуск службы

Перезапускаем службу postfix:

service postfix restart

Настройка Dovecot

Устанавливаем Dovecot:

apt-get install dovecot

Изменение файлов

Создаём файл /etc/dovecot/dovecot-ldap.conf.ext

hosts            = test.alt:3268
ldap_version     = 3
auth_bind        = yes
auth_bind_userdn = %Lu
dn               = cn=vmail,cn=Users,dc=test,dc=alt
dnpass           = Pa$$word
base             = cn=Users,dc=test,dc=alt
scope            = subtree
deref            = finding

user_filter = (&(sAMAccountType=805306368)(|(userPrincipalName=%Lu)(mail=%Lu)))
user_attrs  = =uid=8
pass_filter = (&(sAMAccountType=805306368)(userPrincipalName=%Lu))
pass_attrs = userPrincipalName=user

В каталоге /etc/dovecot/conf.d изменяем файлы для домена test.alt:

10-auth.conf

auth_username_format = %Lu
auth_username_format = %Lu
auth_gssapi_hostname = "$ALL"
auth_krb5_keytab = /etc/dovecot/dovecot.keytab
auth_use_winbind = no
auth_winbind_helper_path = /usr/bin/ntlm_auth
auth_failure_delay = 2 secs
auth_mechanisms = plain
!include auth-ldap.conf.ext

10-mail.conf

mail_location = maildir:/var/mail/%d/%n:INBOX=/var/mail/%d/%n/Inbox
mail_uid = mail
mail_gid = mail
first_valid_uid = 5
first_valid_gid = 5

10-master.conf

service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 0
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
}
service auth {
  unix_listener auth-userdb {
  }
  unix_listener /var/spool/postfix/private/auth {
    mode = 0600
    user = postfix
    group = postfix
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
  }
}

15-lda.conf

protocol lda {
  hostname = test.alt
  postmaster_address = administrator@test.alt
}

15-mailboxes.conf

namespace inbox {
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
}

Перезапуск службы

Перезапускаем службу dovecot и включаем её в автозапуск:

chkconfig dovecot on
service dovecot restart

Отладка

Внимание! Журнал работы Postfix и Dovecot ведётся в файле /var/log/maillog


Для Postfix в файле /etc/postfix/master.cf добавьте параметр -v — вместо

smtps     inet  n       -       n       -       -       smtpd

должно быть

smtps     inet  n       -       n       -       -       smtpd -v

Для Dovecot добавьте в /etc/dovecot/conf.d/10-logging.conf

auth_verbose = yes
auth_debug = yes
mail_debug = yes

Ссылки