xref: /freebsd/contrib/sendmail/src/SECURITY (revision d39bd2c1388b520fcba9abed1932acacead60fba)
15dd76dd0SGregory Neil Shapiro# Copyright (c) 2000-2002 Proofpoint, Inc. and its suppliers.
240266059SGregory Neil Shapiro#	All rights reserved.
340266059SGregory Neil Shapiro#
440266059SGregory Neil Shapiro# By using this file, you agree to the terms and conditions set
540266059SGregory Neil Shapiro# forth in the LICENSE file which can be found at the top level of
640266059SGregory Neil Shapiro# the sendmail distribution.
740266059SGregory Neil Shapiro#
84313cc83SGregory Neil Shapiro#	$Id: SECURITY,v 1.52 2013-11-22 20:51:54 ca Exp $
940266059SGregory Neil Shapiro#
1040266059SGregory Neil Shapiro
1140266059SGregory Neil ShapiroThis file gives some hints how to configure and run sendmail for
1240266059SGregory Neil Shapiropeople who are very security conscious (you should be...).
1340266059SGregory Neil Shapiro
1440266059SGregory Neil ShapiroEven though sendmail goes through great lengths to assure that it
1540266059SGregory Neil Shapirocan't be compromised even if the system it is running on is
1640266059SGregory Neil Shapiroincorrectly or insecurely configured, it can't work around everything.
17*d39bd2c1SGregory Neil ShapiroThis has been demonstrated by OS problems which have subsequently
18*d39bd2c1SGregory Neil Shapirobeen used to compromise the root account using sendmail as a vector.
19*d39bd2c1SGregory Neil ShapiroOne way to minimize the possibility of such problems is to install
20*d39bd2c1SGregory Neil Shapirosendmail without set-user-ID root, which avoids local exploits.
21*d39bd2c1SGregory Neil ShapiroThis configuration, which is the default starting with 8.12, is
22*d39bd2c1SGregory Neil Shapirodescribed in the first section of this security guide.
2340266059SGregory Neil Shapiro
2440266059SGregory Neil Shapiro
2540266059SGregory Neil Shapiro*****************************************************
2640266059SGregory Neil Shapiro** sendmail configuration without set-user-ID root **
2740266059SGregory Neil Shapiro*****************************************************
2840266059SGregory Neil Shapiro
2940266059SGregory Neil Shapirosendmail needs to run as root for several purposes:
3040266059SGregory Neil Shapiro
3140266059SGregory Neil Shapiro- bind to port 25
3240266059SGregory Neil Shapiro- call the local delivery agent (LDA) as root (or other user) if the LDA
3340266059SGregory Neil Shapiro  isn't set-user-ID root (unless some other method of storing e-mail in
3440266059SGregory Neil Shapiro  local mailboxes is used).
3540266059SGregory Neil Shapiro- read .forward files
3640266059SGregory Neil Shapiro- write e-mail submitted via the command line to the queue directory.
3740266059SGregory Neil Shapiro
3840266059SGregory Neil ShapiroOnly the last item requires a set-user-ID/set-group-ID program to
3940266059SGregory Neil Shapiroavoid problems with a world-writable directory.  It is however
4040266059SGregory Neil Shapirosufficient to have a set-group-ID program and a group-writable
4140266059SGregory Neil Shapiroqueue directory.  The other requirements listed above can be
4240266059SGregory Neil Shapirofulfilled by a sendmail daemon that is started by root.  Hence this
4340266059SGregory Neil Shapirosection explains how to use two sendmail configurations to accomplish
4440266059SGregory Neil Shapirothe goal to have a sendmail binary that is not set-user-ID root,
4540266059SGregory Neil Shapiroand hence is not open to system configuration/OS problems or at
4640266059SGregory Neil Shapiroleast less problematic in presence of those.
4740266059SGregory Neil Shapiro
4840266059SGregory Neil ShapiroThe default configuration starting with sendmail 8.12 uses one
4940266059SGregory Neil Shapirosendmail binary which acts differently based on operation mode and
5040266059SGregory Neil Shapirosupplied options.
5140266059SGregory Neil Shapiro
5240266059SGregory Neil Shapirosendmail must be a set-group-ID (default group: smmsp, recommended
5340266059SGregory Neil Shapirogid: 25) program to allow for queueing mail in a group-writable
5440266059SGregory Neil Shapirodirectory.  Two .cf files are required:  sendmail.cf for the daemon
5540266059SGregory Neil Shapiroand submit.cf for the submission program.  The following permissions
5640266059SGregory Neil Shapiroshould be used:
5740266059SGregory Neil Shapiro
5840266059SGregory Neil Shapiro-r-xr-sr-x	root   smmsp	... /PATH/TO/sendmail
5940266059SGregory Neil Shapirodrwxrwx---	smmsp  smmsp	... /var/spool/clientmqueue
6040266059SGregory Neil Shapirodrwx------	root   wheel	... /var/spool/mqueue
6140266059SGregory Neil Shapiro-r--r--r--	root   wheel	... /etc/mail/sendmail.cf
6240266059SGregory Neil Shapiro-r--r--r--	root   wheel	... /etc/mail/submit.cf
6340266059SGregory Neil Shapiro
64605302a5SGregory Neil Shapiro[Notice: On some OS "wheel" is not used but "bin" or "root" instead,
65605302a5SGregory Neil Shapirohowever, this is not important here.]
66605302a5SGregory Neil Shapiro
6740266059SGregory Neil ShapiroThat is, the owner of sendmail is root, the group is smmsp, and
6840266059SGregory Neil Shapirothe binary is set-group-ID.  The client mail queue is owned by
6940266059SGregory Neil Shapirosmmsp with group smmsp and is group writable.  The client mail
7040266059SGregory Neil Shapiroqueue directory must be writable by smmsp, but it must not be
7140266059SGregory Neil Shapiroaccessible for others. That is, do not use world read or execute
7240266059SGregory Neil Shapiropermissions.  In submit.cf the option UseMSP must be set, and
7340266059SGregory Neil ShapiroQueueFileMode must be set to 0660.  submit.cf is available in
7440266059SGregory Neil Shapirocf/cf/, which has been built from cf/cf/submit.mc.  The file can
7540266059SGregory Neil Shapirobe used as-is, if you want to add more options, use cf/cf/submit.mc
7640266059SGregory Neil Shapiroas starting point and read cf/README:  MESSAGE SUBMISSION PROGRAM
7740266059SGregory Neil Shapirocarefully.
7840266059SGregory Neil Shapiro
7940266059SGregory Neil ShapiroThe .cf file is chosen based on the operation mode.  For -bm (default),
8040266059SGregory Neil Shapiro-bs, and -t it is submit.cf (if it exists) for all others it is
8140266059SGregory Neil Shapirosendmail.cf.  This selection can be changed by -Ac or -Am (alternative
8240266059SGregory Neil Shapiro.cf file: client or mta).
8340266059SGregory Neil Shapiro
8440266059SGregory Neil ShapiroThe daemon must be started by root as usual, e.g.,
8540266059SGregory Neil Shapiro
8640266059SGregory Neil Shapiro/PATH/TO/sendmail -L sm-mta -bd -q1h
8740266059SGregory Neil Shapiro
8840266059SGregory Neil Shapiro(replace /PATH/TO with the right path for your OS, e.g.,
8940266059SGregory Neil Shapiro/usr/sbin or /usr/lib).
9040266059SGregory Neil Shapiro
9140266059SGregory Neil ShapiroNotice: if you run sendmail from inetd (which in general is not a
9240266059SGregory Neil Shapirogood idea), you must specify -Am in addition to -bs.
9340266059SGregory Neil Shapiro
9440266059SGregory Neil ShapiroMail will end up in the client queue if the daemon doesn't accept
9540266059SGregory Neil Shapiroconnections or if an address is temporarily not resolvable.  The
9640266059SGregory Neil Shapirolatter problem can be minimized by using
9740266059SGregory Neil Shapiro
9840266059SGregory Neil Shapiro	FEATURE(`nocanonify', `canonify_hosts')
9940266059SGregory Neil Shapiro	define(`confDIRECT_SUBMISSION_MODIFIERS', `C')
10040266059SGregory Neil Shapiro
10140266059SGregory Neil Shapirowhich, however, may have undesired side effects.  See cf/README for
10240266059SGregory Neil Shapiroa discussion.  In general it is necessary to clean the queue either
10340266059SGregory Neil Shapirovia a cronjob or by running a daemon, e.g.,
10440266059SGregory Neil Shapiro
10540266059SGregory Neil Shapiro/PATH/TO/sendmail -L sm-msp-queue -Ac -q30m
10640266059SGregory Neil Shapiro
10740266059SGregory Neil ShapiroIf the option UseMSP is not set, sendmail will complain during
10840266059SGregory Neil Shapiroqueue runs about bogus file permission.  If you want a queue runner
10940266059SGregory Neil Shapirofor the client queue, you probably have to change OS specific
11040266059SGregory Neil Shapiroscripts to accomplish this (check the man pages of your OS for more
11140266059SGregory Neil Shapiroinformation.)  You can start this program as root, it will change
11240266059SGregory Neil Shapiroits user id to RunAsUser (smmsp by default, recommended uid: 25).
11340266059SGregory Neil ShapiroThis way smmsp does not need a valid shell.
11440266059SGregory Neil Shapiro
115*d39bd2c1SGregory Neil Shapiro
11640266059SGregory Neil ShapiroSummary
11740266059SGregory Neil Shapiro-------
11840266059SGregory Neil Shapiro
11940266059SGregory Neil ShapiroThis is a brief summary how the two configuration files are used:
12040266059SGregory Neil Shapiro
12140266059SGregory Neil Shapirosendmail.cf	For the MTA (mail transmission agent)
12240266059SGregory Neil Shapiro	The MTA is started by root as daemon:
12340266059SGregory Neil Shapiro
12440266059SGregory Neil Shapiro		/PATH/TO/sendmail -L sm-mta -bd -q1h
12540266059SGregory Neil Shapiro
12640266059SGregory Neil Shapiro	it accepts SMTP connections (on ports 25 and 587 by default);
12740266059SGregory Neil Shapiro	it runs the main queue (/var/spool/mqueue by default).
12840266059SGregory Neil Shapiro
12940266059SGregory Neil Shapirosubmit.cf	For the MSP (mail submission program)
13040266059SGregory Neil Shapiro	The MSP is used to submit e-mails, hence it is invoked
13140266059SGregory Neil Shapiro	by programs (and maybe users); it does not run as SMTP
13240266059SGregory Neil Shapiro	daemon; it uses /var/spool/clientmqueue by default; it
13340266059SGregory Neil Shapiro	can be started to run that queue periodically:
13440266059SGregory Neil Shapiro
13540266059SGregory Neil Shapiro		/PATH/TO/sendmail -L sm-msp-queue -Ac -q30m
13640266059SGregory Neil Shapiro
13740266059SGregory Neil Shapiro
13840266059SGregory Neil ShapiroHints and Troubleshooting
13940266059SGregory Neil Shapiro-------------------------
14040266059SGregory Neil Shapiro
14140266059SGregory Neil ShapiroRunAsUser: FEATURE(`msp') sets the option RunAsUser to smmsp.
14240266059SGregory Neil ShapiroThis user must have the group smmsp, i.e., the same group as the
14340266059SGregory Neil Shapiroclientmqueue directory.  If you specify a user whose primary group
14440266059SGregory Neil Shapirois not the same as that of the clientmqueue directory, then you
14540266059SGregory Neil Shapiroshould explicitly set the group, e.g.,
14640266059SGregory Neil Shapiro
14740266059SGregory Neil Shapiro	FEATURE(`msp')
14840266059SGregory Neil Shapiro	define(`confRUN_AS_USER', `mailmsp:smmsp')
14940266059SGregory Neil Shapiro
15040266059SGregory Neil ShapiroSTARTTLS: If sendmail is compiled with STARTTLS support on a platform
15140266059SGregory Neil Shapirothat does not have HASURANDOMDEV defined, you either need to specify
15240266059SGregory Neil Shapirothe RandFile option (as for the MTA), or you have to turn off
15340266059SGregory Neil ShapiroSTARTTLS in the MSP, e.g.,
15440266059SGregory Neil Shapiro
15540266059SGregory Neil Shapiro	DAEMON_OPTIONS(`Name=NoMTA, Addr=127.0.0.1, M=S')
15640266059SGregory Neil Shapiro	FEATURE(`msp')
15740266059SGregory Neil Shapiro	CLIENT_OPTIONS(`Family=inet, Address=0.0.0.0, M=S')
15840266059SGregory Neil Shapiro
15940266059SGregory Neil ShapiroThe first option is used to turn off STARTTLS when the MSP is
16040266059SGregory Neil Shapiroinvoked with -bs as some MUAs do.
16140266059SGregory Neil Shapiro
16240266059SGregory Neil Shapiro
16340266059SGregory Neil ShapiroWhat doesn't work anymore
16440266059SGregory Neil Shapiro-------------------------
16540266059SGregory Neil Shapiro
16640266059SGregory Neil ShapiroNormal users can't use mailq anymore to see the MTA mail queue.
16740266059SGregory Neil ShapiroThere are several ways around it, e.g., changing QueueFileMode
16840266059SGregory Neil Shapiroor giving users access via a program like sudo.
16940266059SGregory Neil Shapiro
17040266059SGregory Neil Shapirosendmail -bv may give misleading output for normal users since it
17140266059SGregory Neil Shapiromay not be able to access certain files, e.g., .forward files of
17240266059SGregory Neil Shapiroother users.
17340266059SGregory Neil Shapiro
17440266059SGregory Neil Shapiro
17540266059SGregory Neil ShapiroAlternative
17640266059SGregory Neil Shapiro-----------
17740266059SGregory Neil Shapiro
17840266059SGregory Neil ShapiroInstead of having one set-group-ID binary, it is possible to use
17940266059SGregory Neil Shapirotwo with different permissions: one for message submission
18040266059SGregory Neil Shapiro(set-group-ID), one acting as daemon etc, which is only executable
18140266059SGregory Neil Shapiroby root.  In that case it is possible to remove features from
18240266059SGregory Neil Shapirothe message submission program to have a smaller binary.
18340266059SGregory Neil ShapiroYou can use
18440266059SGregory Neil Shapiro
18540266059SGregory Neil Shapiro	sh ./Build install-sm-mta
18640266059SGregory Neil Shapiro
18740266059SGregory Neil Shapiroto install a sendmail program to act as daemon etc under the name
18840266059SGregory Neil Shapirosm-mta.
18940266059SGregory Neil Shapiro
190*d39bd2c1SGregory Neil Shapiro
19140266059SGregory Neil ShapiroSet-User-Id
19240266059SGregory Neil Shapiro-----------
19340266059SGregory Neil Shapiro
194605302a5SGregory Neil ShapiroIf you really have to install sendmail set-user-ID root, first build
195605302a5SGregory Neil Shapirothe sendmail package normally using
196605302a5SGregory Neil Shapiro
197605302a5SGregory Neil Shapiro	sh ./Build
198605302a5SGregory Neil Shapiro
199605302a5SGregory Neil ShapiroThen you can use
20040266059SGregory Neil Shapiro
20140266059SGregory Neil Shapiro	sh ./Build install-set-user-id
20240266059SGregory Neil Shapiro
203605302a5SGregory Neil Shapiroto install the package in the old (pre-8.12) way.  Make sure that
20413bd1963SGregory Neil Shapirono submit.cf file is installed.  See devtools/README about
20513bd1963SGregory Neil ShapiroconfSETUSERID_INSTALL which you need to define.
206