1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
6 <meta name="generator" content="HTML Tidy, see www.w3.org" />
8 <title>Apache suEXEC Support</title>
10 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
12 <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
13 vlink="#000080" alink="#FF0000">
14 <!--#include virtual="header.html" -->
16 <h1 align="CENTER">Apache suEXEC Support</h1>
19 <li><big><strong>CONTENTS</strong></big></li>
21 <li><a href="#what">What is suEXEC?</a></li>
23 <li><a href="#before">Before we begin.</a></li>
25 <li><a href="#model">suEXEC Security Model.</a></li>
27 <li><a href="#install">Configuring & Installing
30 <li><a href="#enable">Enabling & Disabling
33 <li><a href="#usage">Using suEXEC</a></li>
35 <li><a href="#debug">Debugging suEXEC</a></li>
37 <li><a href="#jabberwock">Beware the Jabberwock: Warnings
38 & Examples</a></li>
44 <h3><a id="what" name="what">What is suEXEC?</a></h3>
46 <p align="LEFT">The <strong>suEXEC</strong> feature --
47 introduced in Apache 1.2 -- provides Apache users the ability
48 to run <strong>CGI</strong> and <strong>SSI</strong> programs
49 under user IDs different from the user ID of the calling
50 web-server. Normally, when a CGI or SSI program executes, it
51 runs as the same user who is running the web server.</p>
53 <p align="LEFT">Used properly, this feature can reduce
54 considerably the security risks involved with allowing users to
55 develop and run private CGI or SSI programs. However, if suEXEC
56 is improperly configured, it can cause any number of problems
57 and possibly create new holes in your computer's security. If
58 you aren't familiar with managing setuid root programs and the
59 security issues they present, we highly recommend that you not
60 consider using suEXEC.</p>
62 <p align="CENTER"><strong><a href="suexec.html">BACK TO
63 CONTENTS</a></strong></p>
65 <h3><a id="before" name="before">Before we begin.</a></h3>
67 <p align="LEFT">Before jumping head-first into this document,
68 you should be aware of the assumptions made on the part of the
69 Apache Group and this document.</p>
71 <p align="LEFT">First, it is assumed that you are using a UNIX
72 derivate operating system that is capable of
73 <strong>setuid</strong> and <strong>setgid</strong> operations.
74 All command examples are given in this regard. Other platforms,
75 if they are capable of supporting suEXEC, may differ in their
78 <p align="LEFT">Second, it is assumed you are familiar with
79 some basic concepts of your computer's security and its
80 administration. This involves an understanding of
81 <strong>setuid/setgid</strong> operations and the various
82 effects they may have on your system and its level of
85 <p align="LEFT">Third, it is assumed that you are using an
86 <strong>unmodified</strong> version of suEXEC code. All code
87 for suEXEC has been carefully scrutinized and tested by the
88 developers as well as numerous beta testers. Every precaution
89 has been taken to ensure a simple yet solidly safe base of
90 code. Altering this code can cause unexpected problems and new
91 security risks. It is <strong>highly</strong> recommended you
92 not alter the suEXEC code unless you are well versed in the
93 particulars of security programming and are willing to share
94 your work with the Apache Group for consideration.</p>
96 <p align="LEFT">Fourth, and last, it has been the decision of
97 the Apache Group to <strong>NOT</strong> make suEXEC part of
98 the default installation of Apache. To this end, suEXEC
99 configuration requires of the administrator careful attention
100 to details. After due consideration has been given to the
101 various settings for suEXEC, the administrator may install
102 suEXEC through normal installation methods. The values for
103 these settings need to be carefully determined and specified by
104 the administrator to properly maintain system security during
105 the use of suEXEC functionality. It is through this detailed
106 process that the Apache Group hopes to limit suEXEC
107 installation only to those who are careful and determined
108 enough to use it.</p>
110 <p align="LEFT">Still with us? Yes? Good. Let's move on!</p>
112 <p align="CENTER"><strong><a href="suexec.html">BACK TO
113 CONTENTS</a></strong></p>
115 <h3><a id="model" name="model">suEXEC Security Model</a></h3>
117 <p align="LEFT">Before we begin configuring and installing
118 suEXEC, we will first discuss the security model you are about
119 to implement. By doing so, you may better understand what
120 exactly is going on inside suEXEC and what precautions are
121 taken to ensure your system's security.</p>
123 <p align="LEFT"><strong>suEXEC</strong> is based on a setuid
124 "wrapper" program that is called by the main Apache web server.
125 This wrapper is called when an HTTP request is made for a CGI
126 or SSI program that the administrator has designated to run as
127 a userid other than that of the main server. When such a
128 request is made, Apache provides the suEXEC wrapper with the
129 program's name and the user and group IDs under which the
130 program is to execute.</p>
132 <p align="LEFT">The wrapper then employs the following process
133 to determine success or failure -- if any one of these
134 conditions fail, the program logs the failure and exits with an
135 error, otherwise it will continue:</p>
139 <strong>Was the wrapper called with the proper number of
143 The wrapper will only execute if it is given the proper
144 number of arguments. The proper argument format is known
145 to the Apache web server. If the wrapper is not receiving
146 the proper number of arguments, it is either being
147 hacked, or there is something wrong with the suEXEC
148 portion of your Apache binary.
153 <strong>Is the user executing this wrapper a valid user of
154 this system?</strong>
157 This is to ensure that the user executing the wrapper is
158 truly a user of the system.
163 <strong>Is this valid user allowed to run the
167 Is this user the user allowed to run this wrapper? Only
168 one user (the Apache user) is allowed to execute this
174 <strong>Does the target program have an unsafe hierarchical
178 Does the target program contain a leading '/' or have a
179 '..' backreference? These are not allowed; the target
180 program must reside within the Apache webspace.
185 <strong>Is the target user name valid?</strong>
188 Does the target user exist?
193 <strong>Is the target group name valid?</strong>
196 Does the target group exist?
201 <strong>Is the target user <em>NOT</em> superuser?</strong>
205 Presently, suEXEC does not allow 'root' to execute
211 <strong>Is the target userid <em>ABOVE</em> the minimum ID
215 The minimum user ID number is specified during
216 configuration. This allows you to set the lowest possible
217 userid that will be allowed to execute CGI/SSI programs.
218 This is useful to block out "system" accounts.
223 <strong>Is the target group <em>NOT</em> the superuser
227 Presently, suEXEC does not allow the 'root' group to
228 execute CGI/SSI programs.
233 <strong>Is the target groupid <em>ABOVE</em> the minimum ID
237 The minimum group ID number is specified during
238 configuration. This allows you to set the lowest possible
239 groupid that will be allowed to execute CGI/SSI programs.
240 This is useful to block out "system" groups.
245 <strong>Can the wrapper successfully become the target user
249 Here is where the program becomes the target user and
250 group via setuid and setgid calls. The group access list
251 is also initialized with all of the groups of which the
257 <strong>Does the directory in which the program resides
261 If it doesn't exist, it can't very well contain files.
266 <strong>Is the directory within the Apache
270 If the request is for a regular portion of the server, is
271 the requested directory within the server's document
272 root? If the request is for a UserDir, is the requested
273 directory within the user's document root?
278 <strong>Is the directory <em>NOT</em> writable by anyone
282 We don't want to open up the directory to others; only
283 the owner user may be able to alter this directories
289 <strong>Does the target program exist?</strong>
292 If it doesn't exists, it can't very well be executed.
297 <strong>Is the target program <em>NOT</em> writable by
298 anyone else?</strong>
301 We don't want to give anyone other than the owner the
302 ability to change the program.
307 <strong>Is the target program <em>NOT</em> setuid or
311 We do not want to execute programs that will then change
317 <strong>Is the target user/group the same as the program's
321 Is the user the owner of the file?
326 <strong>Can we successfully clean the process environment
327 to ensure safe operations?</strong>
330 suEXEC cleans the process' environment by establishing a
331 safe execution PATH (defined during configuration), as
332 well as only passing through those variables whose names
333 are listed in the safe environment list (also created
334 during configuration).
339 <strong>Can we successfully become the target program and
343 Here is where suEXEC ends and the target program begins.
351 <p align="LEFT">This is the standard operation of the the
352 suEXEC wrapper's security model. It is somewhat stringent and
353 can impose new limitations and guidelines for CGI/SSI design,
354 but it was developed carefully step-by-step with security in
357 <p align="LEFT">For more information as to how this security
358 model can limit your possibilities in regards to server
359 configuration, as well as what security risks can be avoided
360 with a proper suEXEC setup, see the <a
361 href="#jabberwock">"Beware the Jabberwock"</a> section of this
364 <p align="CENTER"><strong><a href="suexec.html">BACK TO
365 CONTENTS</a></strong></p>
367 <h3><a id="install" name="install">Configuring & Installing
370 <p align="LEFT">Here's where we begin the fun. If you use
371 Apache 1.2 or prefer to configure Apache 1.3 with the
372 "<code>src/Configure</code>" script you have to edit the suEXEC
373 header file and install the binary in its proper location
374 manually. The following sections describe the configuration and
375 installation for Apache 1.3 with the AutoConf-style interface
378 <p align="LEFT"><strong>APACI's suEXEC configuration
379 options</strong><br />
383 <dt><code>--enable-suexec</code></dt>
385 <dd>This option enables the suEXEC feature which is never
386 installed or activated by default. At least one
387 --with-suexec-xxxxx option has to be provided together with the
388 --enable-suexec option to let APACI accept your request for
389 using the suEXEC feature.</dd>
391 <dt><code>--with-suexec-caller=<em>UID</em></code></dt>
393 <dd>The <a href="mod/mpm_common.html#user">username</a> under which
394 Apache normally runs. This is the only user allowed to
395 execute this program.</dd>
397 <dt><code>--with-suexec-docroot=<em>DIR</em></code></dt>
399 <dd>Define as the DocumentRoot set for Apache. This will be
400 the only hierarchy (aside from UserDirs) that can be used for
401 suEXEC behavior. The default directory is the --datadir value
402 with the suffix "/htdocs", <em>e.g.</em> if you configure
403 with "<code>--datadir=/home/apache</code>" the directory
404 "/home/apache/htdocs" is used as document root for the suEXEC
407 <dt><code>--with-suexec-logfile=<em>FILE</em></code></dt>
409 <dd>This defines the filename to which all suEXEC
410 transactions and errors are logged (useful for auditing and
411 debugging purposes). By default the logfile is named
412 "suexec_log" and located in your standard logfile directory
415 <dt><code>--with-suexec-userdir=<em>DIR</em></code></dt>
417 <dd>Define to be the subdirectory under users' home
418 directories where suEXEC access should be allowed. All
419 executables under this directory will be executable by suEXEC
420 as the user so they should be "safe" programs. If you are
421 using a "simple" UserDir directive (ie. one without a "*" in
422 it) this should be set to the same value. suEXEC will not
423 work properly in cases where the UserDir directive points to
424 a location that is not the same as the user's home directory
425 as referenced in the passwd file. Default value is
427 If you have virtual hosts with a different UserDir for each,
428 you will need to define them to all reside in one parent
429 directory; then name that parent directory here. <strong>If
430 this is not defined properly, "~userdir" cgi requests will
431 not work!</strong></dd>
433 <dt><code>--with-suexec-uidmin=<em>UID</em></code></dt>
435 <dd>Define this as the lowest UID allowed to be a target user
436 for suEXEC. For most systems, 500 or 100 is common. Default
439 <dt><code>--with-suexec-gidmin=<em>GID</em></code></dt>
441 <dd>Define this as the lowest GID allowed to be a target
442 group for suEXEC. For most systems, 100 is common and
443 therefore used as default value.</dd>
445 <dt><code>--with-suexec-safepath=<em>PATH</em></code></dt>
447 <dd>Define a safe PATH environment to pass to CGI
448 executables. Default value is
449 "/usr/local/bin:/usr/bin:/bin".</dd>
455 <p align="LEFT"><strong>Checking your suEXEC
457 Before you compile and install the suEXEC wrapper you can
458 check the configuration with the --layout option.<br />
462 suexec binary: /usr/local/apache/sbin/suexec
463 document root: /usr/local/apache/share/htdocs
464 userdir suffix: public_html
465 logfile: /usr/local/apache/var/log/suexec_log
466 safe path: /usr/local/bin:/usr/bin:/bin
469 minimum group ID: 100
475 <p align="LEFT"><strong>Compiling and installing the suEXEC
476 wrapper</strong><br />
477 If you have enabled the suEXEC feature with the
478 --enable-suexec option the suexec binary (together with Apache
479 itself) is automatically built if you execute the command
481 After all components have been built you can execute the
482 command "make install" to install them. The binary image
483 "suexec" is installed in the directory defined by the --sbindir
484 option. Default location is
485 "/usr/local/apache/sbin/suexec".<br />
486 Please note that you need <strong><em>root
487 privileges</em></strong> for the installation step. In order
488 for the wrapper to set the user ID, it must be installed as
489 owner <code><em>root</em></code> and must have the setuserid
490 execution bit set for file modes.</p>
492 <p align="CENTER"><strong><a href="suexec.html">BACK TO
493 CONTENTS</a></strong></p>
495 <h3><a id="enable" name="enable">Enabling & Disabling
498 <p align="LEFT">Upon startup of Apache, it looks for the file
499 "suexec" in the "sbin" directory (default is
500 "/usr/local/apache/sbin/suexec"). If Apache finds a properly
501 configured suEXEC wrapper, it will print the following message
502 to the error log:</p>
504 [notice] suEXEC mechanism enabled (wrapper: <em>/path/to/suexec</em>)
506 If you don't see this message at server startup, the server is
507 most likely not finding the wrapper program where it expects
508 it, or the executable is not installed <em>setuid root</em>.
510 If you want to enable the suEXEC mechanism for the first time
511 and an Apache server is already running you must kill and
512 restart Apache. Restarting it with a simple HUP or USR1 signal
513 will not be enough. <br />
514 If you want to disable suEXEC you should kill and restart
515 Apache after you have removed the "suexec" file. <br />
519 <p align="CENTER"><strong><a href="suexec.html">BACK TO
520 CONTENTS</a></strong></p>
522 <h3><a id="usage" name="usage">Using suEXEC</a></h3>
524 <p align="LEFT"><strong>Virtual Hosts:</strong><br />
525 One way to use the suEXEC wrapper is through the <a
526 href="mod/mpm_common.html#user">User</a> and <a
527 href="mod/mpm_common.html#group">Group</a> directives in <a
528 href="mod/core.html#virtualhost">VirtualHost</a> definitions.
529 By setting these directives to values different from the main
530 server user ID, all requests for CGI resources will be executed
531 as the <em>User</em> and <em>Group</em> defined for that
532 <code><VirtualHost></code>. If only one or neither of
533 these directives are specified for a
534 <code><VirtualHost></code> then the main server userid is
537 <p><strong>User directories:</strong><br />
538 The suEXEC wrapper can also be used to execute CGI programs as
539 the user to which the request is being directed. This is
540 accomplished by using the "<strong><code>~</code></strong>"
541 character prefixing the user ID for whom execution is desired.
542 The only requirement needed for this feature to work is for CGI
543 execution to be enabled for the user and that the script must
544 meet the scrutiny of the <a href="#model">security checks</a>
547 <p align="CENTER"><strong><a href="suexec.html">BACK TO
548 CONTENTS</a></strong></p>
550 <h3><a id="debug" name="debug">Debugging suEXEC</a></h3>
552 <p align="LEFT">The suEXEC wrapper will write log information
553 to the file defined with the --with-suexec-logfile option as
554 indicated above. If you feel you have configured and installed
555 the wrapper properly, have a look at this log and the error_log
556 for the server to see where you may have gone astray.</p>
558 <p align="CENTER"><strong><a href="suexec.html">BACK TO
559 CONTENTS</a></strong></p>
561 <h3><a id="jabberwock" name="jabberwock">Beware the Jabberwock:
562 Warnings & Examples</a></h3>
564 <p align="LEFT"><strong>NOTE!</strong> This section may not be
565 complete. For the latest revision of this section of the
566 documentation, see the Apache Group's <a
567 href="http://www.apache.org/docs/suexec.html">Online
568 Documentation</a> version.</p>
570 <p align="LEFT">There are a few points of interest regarding
571 the wrapper that can cause limitations on server setup. Please
572 review these before submitting any "bugs" regarding suEXEC.</p>
575 <li><strong>suEXEC Points Of Interest</strong></li>
578 Hierarchy limitations
581 For security and efficiency reasons, all suexec requests
582 must remain within either a top-level document root for
583 virtual host requests, or one top-level personal document
584 root for userdir requests. For example, if you have four
585 VirtualHosts configured, you would need to structure all
586 of your VHosts' document roots off of one main Apache
587 document hierarchy to take advantage of suEXEC for
588 VirtualHosts. (Example forthcoming.)
593 suEXEC's PATH environment variable
596 This can be a dangerous thing to change. Make certain
597 every path you include in this define is a
598 <strong>trusted</strong> directory. You don't want to
599 open people up to having someone from across the world
600 running a trojan horse on them.
605 Altering the suEXEC code
608 Again, this can cause <strong>Big Trouble</strong> if you
609 try this without knowing what you are doing. Stay away
610 from it if at all possible.
615 <p align="CENTER"><strong><a href="suexec.html">BACK TO
616 CONTENTS</a></strong></p>
617 <!--#include virtual="footer.html" -->