Skip to content

Instantly share code, notes, and snippets.

@WNYmathGuy
Forked from barryo/dovecot-10-auth.conf
Last active December 6, 2017 03:06
Show Gist options
  • Save WNYmathGuy/819cbb8af6e04d47ecc0f485dbb8df19 to your computer and use it in GitHub Desktop.
Save WNYmathGuy/819cbb8af6e04d47ecc0f485dbb8df19 to your computer and use it in GitHub Desktop.
Configuration Files for ViMbAdmin on Ubuntu 13.10 with Dovecot and Postfix - referenced from https://github.com/opensolutions/ViMbAdmin3/wiki/Mail-System-Install-on-Ubuntu
auth_mechanisms = plain login
!include auth-sql.conf.ext
mail_location = maildir:/srv/vmail/%d/%n
namespace inbox {
inbox = yes
}
mail_uid = 2000
mail_gid = 2000
mail_privileged_group = vmail
first_valid_uid = 2000
last_valid_uid = 2000
maildir_copy_with_hardlinks = yes
service imap-login {
inet_listener imap {
port = 143
}
inet_listener imaps {
port = 993
ssl = yes
}
service_count = 0
}
service pop3-login {
inet_listener pop3 {
port = 110
}
inet_listener pop3s {
port = 995
ssl = yes
}
}
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0666
user = postfix
}
}
service imap {
}
service pop3 {
}
service auth {
unix_listener auth-userdb {
mode = 0666
user = vmail
group = vmail
}
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
service auth-worker {
}
service dict {
unix_listener dict {
}
}
ssl = yes
ssl_cert = </etc/postfix/ssl/mail.example.com.pem
ssl_key = </etc/postfix/ssl/mail.example.com.pem
ssl_require_crl = no
postmaster_address = postmaster@example.com
hostname = mail.example.com
quota_full_tempfail = yes
recipient_delimiter = +
lda_mailbox_autocreate = yes
lda_mailbox_autosubscribe = yes
protocol lda {
mail_plugins = $mail_plugins sieve quota
}
protocol imap {
mail_plugins = $mail_plugins quota imap_quota
}
protocol lmtp {
postmaster_address = postmaster@example.com
mail_plugins = quota sieve
}
service managesieve-login {
inet_listener sieve {
port = 4190
}
service_count = 1
}
service managesieve {
}
protocol sieve {
}
protocol pop3 {
mail_plugins = $mail_plugins quota
}
passdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
driver = prefetch
}
userdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
driver = mysql
connect = host=localhost user=vimbadmin password=password dbname=vimbadmin
default_pass_scheme = MD5
password_query = SELECT username as user, password as password, \
homedir AS userdb_home, maildir AS userdb_mail, \
concat('*:bytes=', quota) as userdb_quota_rule, uid AS userdb_uid, gid AS userdb_gid \
FROM mailbox \
WHERE username = '%Lu' AND active = '1' \
AND ( access_restriction = 'ALL' OR LOCATE( '%Us', access_restriction ) > 0 )
user_query = SELECT homedir AS home, maildir AS mail, \
concat('*:bytes=', quota) as quota_rule, uid, gid \
FROM mailbox WHERE username = '%u'
!include_try /usr/share/dovecot/protocols.d/*.protocol
!include conf.d/*.conf
!include_try local.conf
# Sample Postfix configuration for use with ViMbAdmin :: Virtual Mailbox Administration
#
# See: https://github.com/opensolutions/ViMbAdmin
#
# By Barry O'Donovan - 2014-02 - http://www.barryodonovan.com/
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file = /etc/postfix/ssl/mail.example.com.pem
smtpd_tls_key_file = /etc/postfix/ssl/mail.example.com.pem
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_scache
smtpd_tls_loglevel = 1
smtpd_tls_auth_only = yes
smtpd_tls_dh1024_param_file = /etc/postfix/dh_1024.pem
smtpd_tls_dh512_param_file = /etc/postfix/dh_512.pem
smtpd_tls_eecdh_grade = strong
myhostname = mail.example.com
myorigin = mail.example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_protocols = all
inet_interfaces = all
notify_classes = resource, software
error_notice_recipient = admin@example.com
#dovecot_destination_recipient_limit = 1
# multi-site stuff, see http://www.postfix.org/VIRTUAL_README.html
# See http://www.postfix.org/postconf.5.html#relay_domains & http://www.postfix.org/postconf.5.html#relay_recipient_maps & http://www.postfix.org/VIRTUAL_README.html#canonical & The relay domain class in http://www.postfix.org/ADDRESS_CLASS_README.html
#relay_domains = mysql:/etc/postfix/mysql/relay_domains_maps.cf
#relay_recipient_maps = mysql:/etc/postfix/mysql/relay_recipient_maps.cf
# As simple as can be: shared domains, UNIX system accounts
# NEVER list a virtual alias domain name as a mydestination domain!
# NEVER list a virtual MAILBOX domain name as a mydestination domain!
mydestination = localhost localhost.$mydomain
# Postfix virtual ALIAS example: separate domains, UNIX system accounts
# See http://www.postfix.org/postconf.5.html#virtual_alias_domains
# NEVER list a virtual MAILBOX domain name as a virtual ALIAS domain!
# NEVER list the FQDN of your server as a virtual ALIAS domain!
virtual_alias_domains = mysql:/etc/postfix/mysql/virtual_aliasdomain_maps.cf
# Postfix virtual MAILBOX example: separate domains, non-UNIX accounts
virtual_mailbox_base = /srv/vmail
virtual_minimum_uid = 100
virtual_uid_maps = mysql:/etc/postfix/mysql/virtual_uid_maps.cf
virtual_gid_maps = mysql:/etc/postfix/mysql/virtual_gid_maps.cf
# Non-Postfix mailbox store: TRANSPORT separate domains, non-UNIX accounts
virtual_transport = lmtp:unix:private/dovecot-lmtp
## Postfix virtual system COMMON FILES
## Common to Virtual Alias Domains, Virtual Mailboxes and Virtual Transport
virtual_alias_maps = mysql:/etc/postfix/mysql/virtual_alias_maps.cf
## Common to Virtual Mailboxes and Virtual Transport
virtual_mailbox_domains = mysql:/etc/postfix/mysql/virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql/virtual_mailbox_maps.cf
# Mailing list stuff
# http://www.postfix.org/VIRTUAL_README.html#mailing_lists
# Autoreply stuff
# http://www.postfix.org/VIRTUAL_README.html#autoreplies
#transport_maps = proxy:mysql:/etc/postfix/mysql/virtual_transport_maps.cf
# REJECTING MAIL FOR UNKNOWN LOCAL USERS
# See http://www.postfix.org/postconf.5.html#local_recipient_maps
local_recipient_maps = mysql:/etc/postfix/mysql/local_recipient_maps.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
broken_sasl_auth_clients = yes
message_size_limit = 40000000
home_mailbox = Maildir/
smtpd_sasl_authenticated_header = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
#mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -m "${EXTENSION}"
smtp_use_tls = yes
smtpd_tls_received_header = yes
smtpd_tls_mandatory_protocols = SSLv3, TLSv1
smtpd_tls_mandatory_ciphers = medium
tls_random_source = dev:/dev/urandom
smtpd_recipient_restrictions =
reject_unknown_sender_domain,
reject_unknown_recipient_domain,
reject_unauth_pipelining,
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
# reject_non_fqdn_hostname,
# reject_invalid_hostname
#smtpd_helo_restrictions =
# check_helo_access hash:/etc/postfix/ehlo_whitelist,
# reject_non_fqdn_hostname,
# reject_invalid_hostname
# check_helo_access hash:/etc/postfix/ehlo_whitelist,
# reject_unknown_helo_hostname
smtpd_helo_required = yes
smtpd_sender_restrictions =
reject_unknown_sender_domain
# check_sender_access hash:/etc/postfix/sender_access,
smtpd_data_restrictions =
reject_unauth_pipelining
smtpd_client_restrictions =
permit_sasl_authenticated
# check_client_access hash:/etc/postfix/client_access,
# reject_rbl_client zen.spamhaus.org
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT username FROM mailbox WHERE username = '%s' AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport = 'local' AND backupmx = '0' AND active = '1')
table = mailbox
select_field = username
where_field = username
additional_conditions = AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport = 'local' AND backupmx = '0' AND active = '1')
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT domain FROM domain WHERE domain = '%d' AND transport = 'relay' AND backupmx = '0' AND active = '1'
table = domain
select_field = domain
where_field = domain
additional_conditions = AND transport = 'relay' AND backupmx = '0' AND active = '1'
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT username FROM mailbox WHERE username = '%s' AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport = 'relay' AND backupmx = '0' AND active = '1')
table = mailbox
select_field = username
where_field = username
additional_conditions = AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport = 'relay' AND backupmx = '0' AND active = '1')
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT goto FROM alias WHERE address = '%s' AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport IN ('alias','transport') AND backupmx = '0' AND active = '1')
table = alias
select_field = goto
where_field = address
additional_conditions = AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport IN ('alias','transport') AND backupmx = '0' AND active = '1')
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT domain FROM domain WHERE domain = '%d' AND transport = 'alias' AND backupmx = '0' AND active = '1'
table = domain
select_field = domain
where_field = domain
additional_conditions = AND transport = 'alias' AND backupmx = '0' AND active = '1'
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT domain FROM domain WHERE domain = '%d' AND transport IN ('virtual','transport') AND backupmx = '0' AND active = '1'
table = domain
select_field = domain
where_field = domain
additional_conditions = AND transport IN ('virtual','transport') AND backupmx = '0' AND active = '1'
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT gid FROM mailbox WHERE username = '%s' AND active = '1'
table = mailbox
select_field = gid
where_field = username
additional_conditions = AND active = '1'
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT maildir FROM mailbox WHERE username = '%s' AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport IN ('alias','transport') AND backupmx = '0' AND active = '1')
table = mailbox
select_field = maildir
where_field = username
additional_conditions = AND active = '1' AND Domain_id IN (SELECT id FROM domain WHERE transport IN ('alias','transport') AND backupmx = '0' AND active = '1')
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT domain FROM domain WHERE domain = '%d' AND transport = 'transport' AND backupmx = '0' AND active = '1'
table = domain
select_field = domain
where_field = domain
additional_conditions = AND transport = 'transport' AND backupmx = '0' AND active = '1'
hosts = 127.0.0.1
user = vimbadmin
password = password
dbname = vimbadmin
query = SELECT uid FROM mailbox WHERE username = '%s' AND active = '1'
table = mailbox
select_field = uid
where_field = username
additional_conditions = AND active = '1'
@WNYmathGuy
Copy link
Author

Note: I never got my server to send secured mail out, but everything inbound worked and I was doing one virtual alias domain, and one virtual mailbox domain. Each domain had multiple accounts. I was able to send from the virtual alias to the virtual mailbox accounts, so I think all these suggestions are good, but somebody else has to test them to be sure they are good.

Some of the <something>_maps.cf files will only populate if a user can modify data that is currently not accessible via ViMbAdmin's interface. e.g. domain table's transport field.

If the UID and GID maps were going to identify local users, like in the case of virtual aliases, then ViMbAdmin would need to give access to copying the OS uid & gid for that user or let the admin type in numbers in the vimbadmin database directly.

Some entries I moved around for clarity because there is a natural grouping based on the Postfix literature.

Relay domains/recipients, mailing list and autoreply stuff I left commented out. I'm not confident that I understand those parts, but I think I have the maps.cf files right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment