ActiveDirectory/PostfixDovecot: различия между версиями
м (переименовал ActiveDirectory/Postfix в ActiveDirectory/PostfixDovecot) |
Нет описания правки |
||
Строка 1: | Строка 1: | ||
Настройка Postfix и Dovecot для аутентификации пользователей в [[Active Directory]]. | |||
{{Attention|Доступ к службам реализован только с помощью SSL по соображениям безопасности}}. | |||
{{Note|Домен: '''test.alt'''}} | |||
== Настройка == | == Настройка == | ||
Строка 26: | Строка 28: | ||
inet_protocols = ipv4 | 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_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 | |||
</source> | |||
== master.cf == | |||
В файл {{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_local_recipients.cf ==== | ||
<source lang="ini">server_host | <source lang="ini">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 | |||
bind_dn | search_scope = subtree | ||
bind_pw | query_filter = (&(|(mail=%s)(otherMailbox=%u@%d))(sAMAccountType=805306368)) | ||
search_base | result_attribute = mail | ||
cache = no</source> | |||
query_filter | |||
result_attribute= | |||
==== | ==== ad_mail_groups.cf ==== | ||
<source lang="ini">server_host | <source lang="ini">debuglevel = 0 | ||
version = 3 | |||
server_host = ldap://test.alt | |||
bind | bind = yes | ||
bind_dn = cn=vmail,cn=users,dc=test,dc=alt | |||
bind_dn | bind_pw = Pa$$word | ||
bind_pw | search_base = dc=test,dc=alt | ||
search_base | timeout = 3 | ||
query_filter = (&(mail=%s)(sAMAccountType=268435456)) | |||
query_filter | result_filter = %s | ||
result_attribute = mail | |||
special_result_attribute = member | special_result_attribute = member | ||
scope = sub</source> | |||
==== | ==== ad_sender_login.cf ==== | ||
<source lang="ini">server_host | <source lang="ini">debuglevel = 0 | ||
version = 3 | |||
server_host = test.alt:3268 | |||
bind | bind = yes | ||
bind_dn = cn=vmail,cn=users,dc=test,dc=alt | |||
bind_dn | bind_pw = Pa$$word | ||
bind_pw | search_base = dc=test,dc=alt | ||
search_base | query_filter = (&(|(mail=%s)(otherMailbox=%s))(sAMAccountType=805306368)) | ||
result_attribute = userPrincipalName</source> | |||
query_filter | |||
result_attribute= userPrincipalName | |||
==== transport ==== | ==== transport ==== | ||
Строка 92: | Строка 105: | ||
Проверка пользователя почты {{term|petrov}}: | Проверка пользователя почты {{term|petrov}}: | ||
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ | <source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ad_local_recipients.cf | ||
test.alt | petrov@test.alt</source> | ||
Проверка входа: | Проверка входа: | ||
<source lang="text"># postmap -q petrov@test.alt ldap:/etc/postfix/ | <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/ | # postmap -q sales@test.alt ldap:/etc/postfix/ad_mail_groups.cf | ||
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 | <source lang="ini">hosts = test.alt:3268 | ||
ldap_version | ldap_version = 3 | ||
auth_bind | auth_bind = yes | ||
dn | auth_bind_userdn = %Lu | ||
dnpass | dn = cn=vmail,cn=Users,dc=test,dc=alt | ||
base | dnpass = Pa$$word | ||
scope | base = cn=Users,dc=test,dc=alt | ||
deref | scope = subtree | ||
user_filter | deref = finding | ||
pass_filter | |||
pass_attrs | user_filter = (&(sAMAccountType=805306368)(|(userPrincipalName=%Lu)(mail=%Lu))) | ||
user_attrs = =uid=8 | |||
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=" | Для Dovecot добавьте в {{path|/etc/dovecot/conf.d/10-logging.conf}} | ||
<source lang="ini">auth_verbose = yes | |||
auth_debug = yes | |||
mail_debug = yes</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