[CentOS] restrict postfix to only certain users getting incoming mail
incoming-centos at rjl.com
Tue Mar 6 06:31:14 UTC 2012
On 03/05/2012 08:50 PM, Bob Hoffman wrote:
> Perhaps I am trying to do the impossible.
> centos6, spamassassin, procmail, dovecot, postfix.
> Postfix, by default, accepts all incoming mail to any user listed in the
> shadow/passwd and alias files.
> I cannot find a way to stop that without manually blocking each non
> wanted user (like nobody, apache) without killing local delivery.
> For most of the users listed in those files, who cares. However for one,
> root, this is a massive issue.
> Root gets a lot of mail from errors on the system. Preventing local
> delivery (or through the alias file, delivery through root to another
> user) makes root never receive those important mails.
> Not preventing root from incoming mails means root at example.com can be
> slammed with spam.
> Local and external mail all seem to go through all of the programs
> (postfix, procmail, spamassassin, dovecot).
> Local delivery of mails is needed for root.
> What I would like is to just tell postfix to only allow incoming mail
> for user1 and user2 and reject all...but only from external sources, not
> locally sent mail.
> Postfix does seem to allow you to limit who can send mail out of the
> server though...
> I have 2 books on postfix here and spent many days online but I do not
> see the solution short of /dev/null or reject of all mail, local or
> external, of root.
> CentOS mailing list
> CentOS at centos.org
Postfix is incredibly flexible in what it can do. Using virtual domains
gives you the most flexibility in terms of not tying local users
directly to mail users. You can setup a postgres or mysql database and
then define an sql query that determines dynamically what mail the smtp
server will accept. For example, I have in my smtpd_recipient_restrictions
Then, in vpm_recipient_access I have the following sql query which runs
dynamically each time an smtp message is transmitted:
(select 'DUNNO'::text from users u where u.domainsname=(select
from domains where name='%d' and active) and u.active),
(select 'REJECT No such domain "%d"'::text where '%d' NOT IN
me from domains where active)),
'REJECT No such user "%u" in domain "%d"'::text)
You can also define your own policy daemon, which I do as well, but the
advantage of the database query above is that it is very fast and works
well on a busy mail server. The policy daemon can be written in python
or perl, but then the decision making process is much slower. So I try
to weed out and reject as much spam using the fastest mechanisms and
save the slower mechanisms for whatever can't be handled in other ways.
This is all well documented on thehttp://www.postfix.org/
<http://www.postfix.org/>and if you install one of the many available
mail packages that include postfix, they will setup all of the virtual
domain stuff and provide you with a policy daemon that you can customize
to your needs.
Also, check out the postfix mailing list.
More information about the CentOS