Topic: Allow login to Dovecot/Roundcube only from specific ip address/network
============ Required information ====
- iRedMail version: 0.9.0
- Store mail accounts in which backend (MySQL):
- Linux/BSD distribution name and version: CentOS 7
- Related log if you're reporting an issue:
====
Hi all,
I just want to share with you what to do to allow specific users to login in Dovecot IMAP and Roundcube Webmail only from a specific ip address or network.
First of all we add a new field on the mailbox table to manage the IP address/network of the user client.
Dovecot allow connection from the remote IP in the extra-field "allow_nets", so i just added a field with that name.
Please refer to this page for more informations: http://wiki2.dovecot.org/PasswordDataba … /AllowNets
Here is the sql command on vmail db: (depends on your need you can change the lenght of this field)
ALTER TABLE `mailbox` ADD `allow_nets` VARCHAR(18) NULL DEFAULT NULL ;
Second we need to modify the password_query sql in /etc/dovecot/dovecot-mysql.conf so we can check the new field like this:
password_query = SELECT password, allow_nets FROM mailbox WHERE username='%u' AND enable%Ls%Lc=1 AND active='1'
At this point we can specify an ip address or a network in the "allow_nets" field and Dovecot will check for it.
Please note that NULL value will allow login from any ip address.
In iRedMail environment, Dovecot receive connections from the webserver IP address as remote IP ("rip:" in the dovecot.log) when a user login from Roundcube Webmail.
If we want to check the user client IP address we need to enable a plugin in Roundcube that identify users with their client IP address and override the webserver IP address when connecting to Dovecot.
To do this we need to download the plugin "dovecot-ident" for Roundcube, unzip the content to Roundcube plugins folder as follow.
# wget https://github.com/corbosman/dovecot_id … master.zip
# unzip master.zip -d /var/www/roundcubemail/plugins/
# mv /var/www/roundcubemail/plugins/dovecot_ident-master /var/www/roundcubemail/plugins/dovecot_ident
Now edit /var/www/roundcubemail/config/config.inc.php to enable the plugin:
// PLUGINS
$config['plugins'] = array('managesieve', 'password', 'dovecot_ident');
Last, we need to allow the webserver IP to override the remote IP address when attempting to login in Dovecot via Roundcube.
Add this line to /etc/dovecot/dovecot.conf
login_trusted_networks = 127.0.0.1
Finish! I hope this will be usefull for the iRedMail community.
PS: Since the new field is not present in iRedMail release I think someone can provide a better solution to integrate the "allow_nets" field in a separated table to preserve it after iRedMail major updates.
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.