suexec.html revision 091caae3b2ebdb760c98575d0d5e349cd686f913
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<HTML>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<HEAD>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<TITLE>Apache suEXEC Support</TITLE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</HEAD>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<BODY
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen BGCOLOR="#FFFFFF"
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen TEXT="#000000"
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen LINK="#0000FF"
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen VLINK="#000080"
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen ALINK="#FF0000"
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<!--#include virtual="header.html" -->
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<H1 ALIGN="CENTER">Apache suEXEC Support</H1>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<OL>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><BIG><STRONG>CONTENTS</STRONG></BIG></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#what">What is suEXEC?</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#before">Before we begin.</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#model">suEXEC Security Model.</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#install">Configuring &amp; Installing suEXEC</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#enable">Enabling &amp; Disabling suEXEC</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#debug">Debugging suEXEC</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><A HREF="#jabberwock">Beware the Jabberwock: Warnings &amp;
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Examples</A></LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</OL>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<H3><A NAME="what">What is suEXEC?</A></H3>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenThe <STRONG>suEXEC</STRONG> feature -- introduced in Apache 1.2 -- provides
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenApache users the ability to run <STRONG>CGI</STRONG> and <STRONG>SSI</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenprograms under user IDs different from the user ID of the calling web-server.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenNormally, when a CGI or SSI program executes, it runs as the same user who is
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenrunning the web server.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenUsed properly, this feature can reduce considerably the security risks involved
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenwith allowing users to develop and run private CGI or SSI programs. However,
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenif suEXEC is improperly configured, it can cause any number of problems and
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenpossibly create new holes in your computer's security. If you aren't familiar
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenwith managing setuid root programs and the security issues they present, we
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenhighly recommend that you not consider using suEXEC.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="CENTER">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<H3><A NAME="before">Before we begin.</A></H3>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenBefore jumping head-first into this document, you should be aware of the
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenassumptions made on the part of the Apache Group and this document.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenFirst, it is assumed that you are using a UNIX derivate operating system that
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenis capable of <STRONG>setuid</STRONG> and <STRONG>setgid</STRONG> operations.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenAll command examples are given in this regard. Other platforms, if they are
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersencapable of supporting suEXEC, may differ in their configuration.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenSecond, it is assumed you are familiar with some basic concepts of your
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersencomputer's security and its administration. This involves an understanding
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenof <STRONG>setuid/setgid</STRONG> operations and the various effects they
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenmay have on your system and its level of security.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenThird, it is assumed that you are using an <STRONG>unmodified</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenversion of suEXEC code. All code for suEXEC has been carefully scrutinized and
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersentested by the developers as well as numerous beta testers. Every precaution
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenhas been taken to ensure a simple yet solidly safe base of code. Altering this
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersencode can cause unexpected problems and new security risks. It is
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<STRONG>highly</STRONG> recommended you not alter the suEXEC code unless you
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenare well versed in the particulars of security programming and are willing to
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenshare your work with the Apache Group for consideration.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
129881b9d52cbe45ed1e2529da980fa231c4e97eStéphane Graber<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenFourth, and last, it has been the decision of the Apache Group to
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<STRONG>NOT</STRONG> make suEXEC part of the default installation of Apache.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenTo this end, suEXEC configuration requires of the administrator careful
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenattention to details. After due consideration has been given to the various
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersensettings for suEXEC, the administrator may install suEXEC through normal
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Anderseninstallation methods. The values for these settings need to be carefully
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersendetermined and specified by the administrator to properly maintain system
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersensecurity during the use of suEXEC functionality. It is through this detailed
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenprocess that the Apache Group hopes to limit suEXEC installation only to those
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenwho are careful and determined enough to use it.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenStill with us? Yes? Good. Let's move on!
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="CENTER">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<H3><A NAME="model">suEXEC Security Model</A></H3>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenBefore we begin configuring and installing suEXEC, we will first discuss
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenthe security model you are about to implement. By doing so, you may
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenbetter understand what exactly is going on inside suEXEC and what precautions
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenare taken to ensure your system's security.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<STRONG>suEXEC</STRONG> is based on a setuid "wrapper" program that is
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersencalled by the main Apache web server. This wrapper is called when an HTTP
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenrequest is made for a CGI or SSI program that the administrator has designated
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersento run as a userid other than that of the main server. When such a request
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenis made, Apache provides the suEXEC wrapper with the program's name and the
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenuser and group IDs under which the program is to execute.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen</P>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<P ALIGN="LEFT">
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho AndersenThe wrapper then employs the following process to determine success or
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenfailure -- if any one of these conditions fail, the program logs the failure
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersenand exits with an error, otherwise it will continue:
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen<OL>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Was the wrapper called with the proper number of
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen arguments?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen The wrapper will only execute if it is given the proper number of arguments.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen The proper argument format is known to the Apache web server. If the
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen wrapper
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen is not receiving the proper number of arguments, it is either being hacked,
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen or
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen there is something wrong with the suEXEC portion of your Apache binary.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the user executing this wrapper a valid user of this
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen system?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen This is to ensure that the user executing the wrapper is truly a user of the
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen system.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is this valid user allowed to run the wrapper?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Is this user the user allowed to run this wrapper? Only one user (the
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Apache user) is allowed to execute this program.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Does the target program have an unsafe hierarchical
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen reference?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Does the target program contain a leading '/' or have a '..' backreference?
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen These are not allowed; the target program must reside within the Apache
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen webspace.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target user name valid?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Does the target user exist?
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target group name valid?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Does the target group exist?
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target user <EM>NOT</EM> superuser?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Presently, suEXEC does not allow 'root' to execute CGI/SSI programs.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target userid <EM>ABOVE</EM> the minimum ID
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen number?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen The minimum user ID number is specified during configuration. This allows
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen you
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen to set the lowest possible userid that will be allowed to execute CGI/SSI
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen programs. This is useful to block out "system" accounts.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target group <EM>NOT</EM> the superuser group?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen Presently, suEXEC does not allow the 'root' group to execute CGI/SSI
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen programs.
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen </LI>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <LI><STRONG>Is the target groupid <EM>ABOVE</EM> the minimum ID
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen number?</STRONG>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen <BLOCKQUOTE>
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen The minimum group ID number is specified during configuration. This allows
735f2c6e504a541cbb2592a3f94858bf337a24ffTycho Andersen you
to set the lowest possible groupid that will be allowed to execute CGI/SSI
programs. This is useful to block out "system" groups.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Can the wrapper successfully become the target user and
group?</STRONG>
<BLOCKQUOTE>
Here is where the program becomes the target user and group via setuid and
setgid
calls. The group access list is also initialized with all of the groups
of which
the user is a member.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Does the directory in which the program resides exist?</STRONG>
<BLOCKQUOTE>
If it doesn't exist, it can't very well contain files.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Is the directory within the Apache webspace?</STRONG>
<BLOCKQUOTE>
If the request is for a regular portion of the server, is the requested
directory
within the server's document root? If the request is for a UserDir, is
the requested
directory within the user's document root?
</BLOCKQUOTE>
</LI>
<LI><STRONG>Is the directory <EM>NOT</EM> writable by anyone else?</STRONG>
<BLOCKQUOTE>
We don't want to open up the directory to others; only the owner user
may be able
to alter this directories contents.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Does the target program exist?</STRONG>
<BLOCKQUOTE>
If it doesn't exists, it can't very well be executed.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Is the target program <EM>NOT</EM> writable by anyone
else?</STRONG>
<BLOCKQUOTE>
We don't want to give anyone other than the owner the ability to
change the program.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Is the target program <EM>NOT</EM> setuid or setgid?</STRONG>
<BLOCKQUOTE>
We do not want to execute programs that will then change our UID/GID again.
</BLOCKQUOTE>
</LI>
<LI><STRONG>Is the target user/group the same as the program's
user/group?</STRONG>
<BLOCKQUOTE>
Is the user the owner of the file?
</BLOCKQUOTE>
</LI>
<LI><STRONG>Can we successfully clean the process environment to
ensure safe operations?</STRONG>
<BLOCKQUOTE>
suEXEC cleans the process' environment by establishing a safe
execution PATH (defined
during configuration), as well as only passing through those
variables whose names
are listed in the safe environment list (also created during
configuration).
</BLOCKQUOTE>
</LI>
<LI><STRONG>Can we successfully become the target program and
execute?</STRONG>
<BLOCKQUOTE>
Here is where suEXEC ends and the target program begins.
</BLOCKQUOTE>
</LI>
</OL>
</P>
<P ALIGN="LEFT">
This is the standard operation of the the suEXEC wrapper's security model.
It is somewhat stringent and can impose new limitations and guidelines for
CGI/SSI design, but it was developed carefully step-by-step with security
in mind.
</P>
<P ALIGN="LEFT">
For more information as to how this security model can limit your possibilities
in regards to server configuration, as well as what security risks can be
avoided with a proper suEXEC setup, see the
<A HREF="#beware">"Beware the Jabberwock"</A>
section of this document.
</P>
<P ALIGN="CENTER">
<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
</P>
<H3><A NAME="install">Configuring &amp; Installing suEXEC</A></H3>
<P ALIGN="LEFT">
Here's where we begin the fun. The configuration and installation of suEXEC is
a four step process: edit the suEXEC header file, compile suEXEC, place the
suEXEC binary in its proper location, and configure Apache for use with suEXEC.
</P>
<P ALIGN="LEFT">
<STRONG>EDITING THE SUEXEC HEADER FILE</STRONG><BR>
- From the top-level of the Apache source tree, type:&nbsp;&nbsp;
<STRONG><CODE>cd support [ENTER]</CODE></STRONG>
</P>
<P ALIGN="LEFT">
Edit the <CODE>suexec.h</CODE> file and change the following macros to
match your local Apache installation.
</P>
<P ALIGN="LEFT">
<EM>From support/suexec.h</EM>
<PRE>
/*
* HTTPD_USER -- Define as the username under which Apache normally
* runs. This is the only user allowed to execute
* this program.
*/
#define HTTPD_USER "www"
/*
* UID_MIN -- Define this as the lowest UID allowed to be a target user
* for suEXEC. For most systems, 500 or 100 is common.
*/
#define UID_MIN 100
/*
* GID_MIN -- Define this as the lowest GID allowed to be a target group
* for suEXEC. For most systems, 100 is common.
*/
#define GID_MIN 100
/*
* USERDIR_SUFFIX -- Define to be the subdirectory under users'
* home directories where suEXEC access should
* be allowed. All executables under this directory
* will be executable by suEXEC as the user so
* they should be "safe" programs. If you are
* using a "simple" UserDir directive (ie. one
* without a "*" in it) this should be set to
* the same value. suEXEC will not work properly
* in cases where the UserDir directive points to
* a location that is not the same as the user's
* home directory as referenced in the passwd file.
*
* If you have VirtualHosts with a different
* UserDir for each, you will need to define them to
* all reside in one parent directory; then name that
* parent directory here. IF THIS IS NOT DEFINED
* PROPERLY, ~USERDIR CGI REQUESTS WILL NOT WORK!
* See the suEXEC documentation for more detailed
* information.
*/
#define USERDIR_SUFFIX "public_html"
/*
* LOG_EXEC -- Define this as a filename if you want all suEXEC
* transactions and errors logged for auditing and
* debugging purposes.
*/
#define LOG_EXEC "/usr/local/apache/logs/cgi.log" /* Need me? */
/*
* DOC_ROOT -- Define as the DocumentRoot set for Apache. This
* will be the only hierarchy (aside from UserDirs)
* that can be used for suEXEC behavior.
*/
#define DOC_ROOT "/usr/local/apache/htdocs"
/*
* SAFE_PATH -- Define a safe PATH environment to pass to CGI executables.
*
*/
#define SAFE_PATH "/usr/local/bin:/usr/bin:/bin"
</PRE>
</P>
<P ALIGN="LEFT">
<STRONG>COMPILING THE SUEXEC WRAPPER</STRONG><BR>
You now need to compile the suEXEC wrapper. At the shell command prompt,
type:&nbsp;&nbsp;<STRONG><CODE>cc suexec.c -o suexec [ENTER]</CODE></STRONG>.
This should create the <STRONG><EM>suexec</EM></STRONG> wrapper executable.
</P>
<P ALIGN="LEFT">
<STRONG>COMPILING APACHE FOR USE WITH SUEXEC</STRONG><BR>
By default, Apache is compiled to look for the suEXEC wrapper in the following
location.
</P>
<P ALIGN="LEFT">
<EM>From src/httpd.h</EM>
<PRE>
/* The path to the suEXEC wrapper */
#define SUEXEC_BIN "/usr/local/apache/sbin/suexec"
</PRE>
</P>
<P ALIGN="LEFT">
If your installation requires location of the wrapper program in a different
directory, edit src/httpd.h and recompile your Apache server.
See <A HREF="install.html">Compiling and Installing Apache</A> for more
info on this process.
</P>
<P ALIGN="LEFT">
<STRONG>COPYING THE SUEXEC BINARY TO ITS PROPER LOCATION</STRONG><BR>
Copy the <STRONG><EM>suexec</EM></STRONG> executable created in the
exercise above to the defined location for <STRONG>SUEXEC_BIN</STRONG>.
</P>
<P ALIGN="LEFT">
<STRONG><CODE>cp suexec /usr/local/apache/sbin/suexec [ENTER]</CODE></STRONG>
</P>
<P ALIGN="LEFT">
In order for the wrapper to set the user ID, it must me installed as owner
<STRONG><EM>root</EM></STRONG> and must have the setuserid execution bit
set for file modes. If you are not running a <STRONG><EM>root</EM></STRONG>
user shell, do so now and execute the following commands.
</P>
<P ALIGN="LEFT">
<STRONG><CODE>chown root /usr/local/apache/sbin/suexec [ENTER]</CODE></STRONG>
<BR>
<STRONG><CODE>chmod 4711 /usr/local/apache/sbin/suexec [ENTER]</CODE></STRONG>
</P>
<P ALIGN="CENTER">
<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
</P>
<H3><A NAME="enable">Enabling &amp; Disabling suEXEC</A></H3>
<P ALIGN="LEFT">
After properly installing the <STRONG>suexec</STRONG> wrapper
executable, you must kill and restart the Apache server. A simple
<STRONG><CODE>kill -1 `cat httpd.pid`</CODE></STRONG> will not be enough.
Upon startup of the web-server, if Apache finds a properly configured
<STRONG>suexec</STRONG> wrapper, it will print the following message to
the console:
</P>
<P ALIGN="LEFT">
<CODE>Configuring Apache for use with suexec wrapper.</CODE>
</P>
<P ALIGN="LEFT">
If you don't see this message at server startup, the server is most
likely not finding the wrapper program where it expects it, or the
executable is not installed <STRONG><EM>setuid root</EM></STRONG>. Check
your installation and try again.
</P>
<P ALIGN="LEFT">
One way to use <STRONG>suEXEC</STRONG> is through the
<A HREF="mod/core.html#user"><STRONG>User</STRONG></A> and
<A HREF="mod/core.html#group"><STRONG>Group</STRONG></A> directives in
<A HREF="mod/core.html#virtualhost"><STRONG>VirtualHost</STRONG></A>
definitions. By setting these directives to values different from the
main server user ID, all requests for CGI resources will be executed as
the <STRONG>User</STRONG> and <STRONG>Group</STRONG> defined for that
<STRONG>&lt;VirtualHost&gt;</STRONG>. If only one or
neither of these directives are specified for a
<STRONG>&lt;VirtualHost&gt;</STRONG> then the main
server userid is assumed.<P>
<STRONG>suEXEC</STRONG> can also be used to to execute CGI programs as
the user to which the request is being directed. This is accomplished by
using the <STRONG>~</STRONG> character prefixing the user ID for whom
execution is desired.
The only requirement needed for this feature to work is for CGI
execution to be enabled for the user and that the script must meet the
scrutiny of the <A HREF="#model">security checks</A> above.
<P ALIGN="CENTER">
<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
</P>
<H3><A NAME="debug">Debugging suEXEC</A></H3>
<P ALIGN="LEFT">
The suEXEC wrapper will write log information to the location defined in
the <CODE>suexec.h</CODE> as indicated above. If you feel you have
configured and installed the wrapper properly, have a look at this log
and the error_log for the server to see where you may have gone astray.
</P>
<P ALIGN="CENTER">
<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
</P>
<H3>
<A NAME="jabberwock">Beware the Jabberwock: Warnings &amp; Examples</A>
</H3>
<P ALIGN="LEFT">
<STRONG>NOTE!</STRONG> This section may not be complete. For the latest
revision of this section of the documentation, see the Apache Group's
<A HREF="http://www.apache.org/docs/suexec.html">Online Documentation</A>
version.
</P>
<P ALIGN="LEFT">
There are a few points of interest regarding the wrapper that can cause
limitations on server setup. Please review these before submitting any
"bugs" regarding suEXEC.
<UL>
<LI><STRONG>suEXEC Points Of Interest</STRONG></LI>
<LI>Hierarchy limitations
<BLOCKQUOTE>
For security and efficiency reasons, all suexec requests must
remain within either a top-level document root for virtual
host requests, or one top-level personal document root for
userdir requests. For example, if you have four VirtualHosts
configured, you would need to structure all of your VHosts'
document roots off of one main Apache document hierarchy to
take advantage of suEXEC for VirtualHosts. (Example forthcoming.)
</BLOCKQUOTE>
</LI>
<LI>suEXEC's PATH environment variable
<BLOCKQUOTE>
This can be a dangerous thing to change. Make certain every
path you include in this define is a <STRONG>trusted</STRONG>
directory. You don't want to open people up to having someone
from across the world running a trojan horse on them.
</BLOCKQUOTE>
</LI>
<LI>Altering the suEXEC code
<BLOCKQUOTE>
Again, this can cause <STRONG>Big Trouble</STRONG> if you try
this without knowing what you are doing. Stay away from it
if at all possible.
</BLOCKQUOTE>
</LI>
</UL>
<P ALIGN="CENTER">
<STRONG><A HREF="suexec.html">BACK TO CONTENTS</A></STRONG>
</P>
<!--#include virtual="footer.html" -->
</BODY>
</HTML>