From: Randy Terbush Date: Thu, 5 Jun 1997 20:07:19 +0000 (+0000) Subject: Update suexec docs. X-Git-Tag: 1.2.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18089b56128835529e43aa2d76f38105a9260c40;p=thirdparty%2Fapache%2Fhttpd.git Update suexec docs. Reviewed by: Ken Coar, Randy Terbush Submitted by: Jason Dour git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@78245 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/suexec.html b/docs/manual/suexec.html index 2b32aa950d6..7806bc8f55c 100644 --- a/docs/manual/suexec.html +++ b/docs/manual/suexec.html @@ -1,8 +1,8 @@ - -Apache SetUserID Support - - + + +Apache suEXEC Support + -

Apache suEXEC Support

- -
- -

What is suEXEC?

-The suEXEC feature, introduced in Apache 1.2 provides -the ability to run CGI programs under user IDs -different from the user ID of the calling web-server. Used properly, -this feature can reduce considerably the insecurity of allowing users to -run CGI programs. At the same time, improperly configured, this facility -can crash your computer, burn your house down and steal all the money -from your retirement fund. :-) If you aren't familiar -with managing setuid root programs and the security issues they -present, we highly recommend that you not consider using this feature.

- -


- -

Enabling suEXEC Support

-Having said all that, enabling this feature is purposefully difficult with -the intent that it will only be installed by users determined to use it and -is not part of the normal install/compile process.

- -

Configuring the suEXEC wrapper

-From the top-level of the Apache source tree, -type:  cd support [ENTER]

+ +

Apache suEXEC Support

+ +

+

    + CONTENTS +
  1. What is suEXEC?
  2. +
  3. Before we begin.
  4. +
  5. suEXEC Security Model.
  6. +
  7. Configuring & Installing suEXEC
  8. +
  9. Enabling & Disabling suEXEC
  10. +
  11. Debugging suEXEC
  12. +
  13. Beware the Jabberwock: Warnings & Examples
  14. +
+

+ +

What is suEXEC?

+

+The suEXEC feature -- introduced in Apache 1.2 -- provides +Apache users the ability to run CGI and SSI +programs under user IDs different from the user ID of the calling web-server. +Normally, when a CGI or SSI program executes, it runs as the same user who is +running the web server. +

+ +

+Used properly, this feature can reduce considerably the security risks involved +with allowing users to develop and run private CGI or SSI programs. However, +if suEXEC is improperly configured, it can cause any number of problems and +possibly create new holes in your computer's security. If you aren't familiar +with managing setuid root programs and the security issues they present, we +highly recommend that you not consider using suEXEC. +

+ +

+BACK TO CONTENTS +

+ +

Before we begin.

+

+Before jumping head-first into this document, you should be aware of the +assumptions made on the part of the Apache Group and this document. +

+ +

+First, it is assumed that you are using a UNIX derivate operating system that +is capable of setuid and setgid operations. +All command examples are given in this regard. Other platforms, if they are +capable of supporting suEXEC, may differ in their configuration. +

+ +

+Second, it is assumed you are familiar with some basic concepts of your +computer's security and its administration. This involves an understanding +of setuid/setgid operations and the various effects they +may have on your system and its level of security. +

+ +

+Third, it is assumed that you are using an unmodified +version of suEXEC code. All code for suEXEC has been carefully scrutinized and +tested by the developers as well as numerous beta testers. Every precaution has +been taken to ensure a simple yet solidly safe base of code. Altering this +code can cause unexpected problems and new security risks. It is +highly recommended you not alter the suEXEC code unless you +are well versed in the particulars of security programming and are willing to +share your work with the Apache Group for consideration. +

+ +

+Fourth, and last, it has been the decision of the Apache Group to +NOT make suEXEC part of the default installation of Apache. +To this end, suEXEC configuration is a manual process requiring of the +administrator careful attention to details. It is through this process +that the Apache Group hopes to limit suEXEC installation only to those +who are determined to use it. +

+ +

+Still with us? Yes? Good. Let's move on! +

+ +

+BACK TO CONTENTS +

+ +

suEXEC Security Model

+

+Before we begin configuring and installing suEXEC, we will first discuss +the security model you are about to implement. By doing so, you may +better understand what exactly is going on inside suEXEC and what precautions +are taken to ensure your system's security. +

+ +

+suEXEC is based on a setuid "wrapper" program that is +called by the main Apache web server. This wrapper is called when an HTTP +request is made for a CGI or SSI program that the administrator has designated +to run as a userid other than that of the main server. When such a request +is made, Apache provides the suEXEC wrapper with the program's name and the +user and group IDs under which the program is to execute. +

+ +

+The wrapper then employs the following process to determine success or +failure -- if any one of these conditions fail, the program logs the failure +and exits with an error, otherwise it will continue: +

    +
  1. Was the wrapper called with the proper number of arguments? +
    + The wrapper will only execute if it is given the proper number of arguments. + The proper argument format is known to the Apache web server. If the wrapper + is not receiving the proper number of arguments, it is either being hacked, or + there is something wrong with the suEXEC portion of your Apache binary. +
    +
  2. +
  3. Is the user executing this wrapper a valid user of this system? +
    + This is to ensure that the user executing the wrapper is truly a user of the system. +
    +
  4. +
  5. Is this valid user allowed to run the wrapper? +
    + Is this user the user allowed to run this wrapper? Only one user (the Apache + user) is allowed to execute this program. +
    +
  6. +
  7. Does the target program have an unsafe hierarchical reference? +
    + Does the target program contain a leading '/' or have a '..' backreference? These + are not allowed; the target program must reside within the Apache webspace. +
    +
  8. +
  9. Is the target user name valid? +
    + Does the target user exist? +
    +
  10. +
  11. Is the target group name valid? +
    + Does the target group exist? +
    +
  12. +
  13. Is the target user NOT superuser? +
    + Presently, suEXEC does not allow 'root' to execute CGI/SSI programs. +
    +
  14. +
  15. Is the target userid ABOVE the minimum ID number? +
    + The minimum user ID number is specified during configuration. This allows you + to set the lowest possible userid that will be allowed to execute CGI/SSI programs. + This is useful to block out "system" accounts. +
    +
  16. +
  17. Is the target group NOT the superuser group? +
    + Presently, suEXEC does not allow the 'root' group to execute CGI/SSI programs. +
    +
  18. +
  19. Is the target groupid ABOVE the minimum ID number? +
    + The minimum group ID number is specified during configuration. This allows you + to set the lowest possible groupid that will be allowed to execute CGI/SSI programs. + This is useful to block out "system" groups. +
    +
  20. +
  21. Can the wrapper successfully become the target user and group? +
    + 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. +
    +
  22. +
  23. Does the directory in which the program resides exist? +
    + If it doesn't exist, it can't very well contain files. +
    +
  24. +
  25. Is the directory within the Apache webspace? +
    + 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? +
    +
  26. +
  27. Is the directory NOT writable by anyone else? +
    + We don't want to open up the directory to others; only the owner user may be able + to alter this directories contents. +
    +
  28. +
  29. Does the target program exist? +
    + If it doesn't exists, it can't very well be executed. +
    +
  30. +
  31. Is the target program NOT writable by anyone else? +
    + We don't want to give anyone other than the owner the ability to change the program. +
    +
  32. +
  33. Is the target program NOT setuid or setgid? +
    + We do not want to execute programs that will then change our UID/GID again. +
    +
  34. +
  35. Is the target user/group the same as the program's user/group? +
    + Is the user the owner of the file? +
    +
  36. +
  37. Can we successfully clean the process environment to ensure safe operations? +
    + 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). +
    +
  38. +
  39. Can we successfully become the target program and execute? +
    + Here is where suEXEC ends and the target program begins. +
    +
  40. +
+

+ +

+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. +

+ +

+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 "Beware the Jabberwock" +section of this document. +

+ +

+BACK TO CONTENTS +

+ +

Configuring & Installing suEXEC

+

+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. +

+ +

+EDITING THE SUEXEC HEADER FILE
+- From the top-level of the Apache source tree, type:   +cd support [ENTER] +

+ +

Edit the suexec.h file and change the following macros to -match your local Apache installation.

+match your local Apache installation. +

+ +

From support/suexec.h -

-/*
- * 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"
-
-/*
- * 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/etc/httpd/logs/cgi.log"
-
-/*
- * 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/etc/httpd/htdocs"
-
-/*
- * SAFE_PATH -- Define a safe PATH environment to pass to CGI executables.
- *
- */
-#define SAFE_PATH "/usr/local/bin:/usr/bin:/bin"
-
- -

Compiling the suEXEC wrapper

-At the shell command prompt, type:  cc suexec.c --o suexec [ENTER].

+

+     /*
+      * 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/etc/httpd/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/etc/httpd/htdocs"
+
+     /*
+      * SAFE_PATH -- Define a safe PATH environment to pass to CGI executables.
+      *
+      */
+     #define SAFE_PATH "/usr/local/bin:/usr/bin:/bin"
+
+

+ +

+COMPILING THE SUEXEC WRAPPER
+You now need to compile the suEXEC wrapper. At the shell command prompt, +type:  cc suexec.c -o suexec [ENTER]. This should create the suexec wrapper executable. +

-

Compiling Apache for suEXEC support

+

+COMPILING APACHE FOR USE WITH SUEXEC
By default, Apache is compiled to look for the suEXEC wrapper in the following -location.

+location. +

+ +

From src/httpd.h -

-/* The path to the suEXEC wrapper */
-#ifndef SUEXEC_BIN
-#define SUEXEC_BIN "/usr/local/etc/httpd/sbin/suexec"
-#endif
-
-

+

+     /* The path to the suEXEC wrapper */
+     #define SUEXEC_BIN "/usr/local/etc/httpd/sbin/suexec"
+
+

+ +

If your installation requires location of the wrapper program in a different directory, edit src/httpd.h and recompile your Apache server. -See Compiling and Installing Apache for more -info on this process.

+See Compiling and Installing Apache for more +info on this process. +

-

Installing the suEXEC wrapper

+

+COPYING THE SUEXEC BINARY TO ITS PROPER LOCATION
Copy the suexec executable created in the -exercise above to the defined location for SUEXEC_BIN.

-In order for the wrapper to set the user ID for execution requests it -must me installed as owner root and must have -the setuserid execution bit set for file modes. -If you are not running a root user shell, do -so now and execute the following commands.

- -chown root /usr/local/etc/httpd/sbin/suexec [ENTER]

-chmod 4711 /usr/local/etc/httpd/sbin/suexec [ENTER]

- -Change the path to the suEXEC wrapper to match your system -installation. - -


- -

Security Model of suEXEC

-The suEXEC wrapper supplied with Apache performs the -following security checks before it will execute any program passed to -it for execution. -
    -
  1. User executing the wrapper must be a valid user on this - system. -
  2. User executing the wrapper must be the compiled in - HTTPD_USER. -
  3. The command that the request wishes to execute must not - contain a leading / or ../, or the string "/../" anywhere. -
  4. The command being executed must reside under the compiled in - DOC_ROOT. -
  5. The current working directory must be a directory. -
  6. The current working directory must not be writable by - group or other. -
  7. The command being executed cannot be a symbolic link. -
  8. The command being executed cannot be writable by - group or other. -
  9. The command being executed cannot be a setuid or - setgid program. -
  10. The target UID and GID must be a valid user and group on - this system. -
  11. The target UID and GID to execute as, must match the UID and - GID of the directory. -
  12. The target execution UID and GID must not be the privileged - ID 0. -
-If any of these issues are too restrictive, or do not seem restrictive -enough, you are welcome to install your own version of the wrapper. -We've given you the rope, now go have fun with it. :-) - -
- -

Using suEXEC

+exercise above to the defined location for SUEXEC_BIN. +

+ +

+cp suexec /usr/local/etc/httpd/sbin/suexec [ENTER] +

+ +

+In order for the wrapper to set the user ID, it must me installed as owner +root and must have the setuserid execution bit +set for file modes. If you are not running a root +user shell, do so now and execute the following commands. +

+ +

+chown root /usr/local/etc/httpd/sbin/suexec [ENTER]
+chmod 4711 /usr/local/etc/httpd/sbin/suexec [ENTER] +

+ +

+BACK TO CONTENTS +

+ +

Enabling & Disabling suEXEC

+

After properly installing the suexec wrapper -executable, you must kill and restart the Apache server. A simple -kill -1 `cat httpd.pid` will not be enough. +executable, you must kill and restart the Apache server. A simple +kill -1 `cat httpd.pid` will not be enough. Upon startup of the web-server, if Apache finds a properly configured suexec wrapper, it will print the following message to -the console:

+the console: +

-Configuring Apache for use with suexec wrapper.

+

+Configuring Apache for use with suexec wrapper. +

+

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 setuid root. Check -your installation and try again.

+executable is not installed setuid root. Check +your installation and try again. +

+

One way to use suEXEC is through the User and Group directives in @@ -176,15 +438,68 @@ 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 security checks above. -


+

+BACK TO CONTENTS +

-

Debugging suEXEC

+

Debugging suEXEC

+

The suEXEC wrapper will write log information to the location defined in the suexec.h 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. - +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. +

+

+BACK TO CONTENTS +

+ +

Beware the Jabberwock: Warnings & Examples

+

+NOTE! This section may not be complete. For the latest +revision of this section of the documentation, see the Apache Group's +Online Documentation +version. +

+ +

+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. +

+ +

+BACK TO CONTENTS +

+ + diff --git a/docs/manual/suexec.html.en b/docs/manual/suexec.html.en index 2b32aa950d6..7806bc8f55c 100644 --- a/docs/manual/suexec.html.en +++ b/docs/manual/suexec.html.en @@ -1,8 +1,8 @@ - -Apache SetUserID Support - - + + +Apache suEXEC Support + -

Apache suEXEC Support

- -
- -

What is suEXEC?

-The suEXEC feature, introduced in Apache 1.2 provides -the ability to run CGI programs under user IDs -different from the user ID of the calling web-server. Used properly, -this feature can reduce considerably the insecurity of allowing users to -run CGI programs. At the same time, improperly configured, this facility -can crash your computer, burn your house down and steal all the money -from your retirement fund. :-) If you aren't familiar -with managing setuid root programs and the security issues they -present, we highly recommend that you not consider using this feature.

- -


- -

Enabling suEXEC Support

-Having said all that, enabling this feature is purposefully difficult with -the intent that it will only be installed by users determined to use it and -is not part of the normal install/compile process.

- -

Configuring the suEXEC wrapper

-From the top-level of the Apache source tree, -type:  cd support [ENTER]

+ +

Apache suEXEC Support

+ +

+

    + CONTENTS +
  1. What is suEXEC?
  2. +
  3. Before we begin.
  4. +
  5. suEXEC Security Model.
  6. +
  7. Configuring & Installing suEXEC
  8. +
  9. Enabling & Disabling suEXEC
  10. +
  11. Debugging suEXEC
  12. +
  13. Beware the Jabberwock: Warnings & Examples
  14. +
+

+ +

What is suEXEC?

+

+The suEXEC feature -- introduced in Apache 1.2 -- provides +Apache users the ability to run CGI and SSI +programs under user IDs different from the user ID of the calling web-server. +Normally, when a CGI or SSI program executes, it runs as the same user who is +running the web server. +

+ +

+Used properly, this feature can reduce considerably the security risks involved +with allowing users to develop and run private CGI or SSI programs. However, +if suEXEC is improperly configured, it can cause any number of problems and +possibly create new holes in your computer's security. If you aren't familiar +with managing setuid root programs and the security issues they present, we +highly recommend that you not consider using suEXEC. +

+ +

+BACK TO CONTENTS +

+ +

Before we begin.

+

+Before jumping head-first into this document, you should be aware of the +assumptions made on the part of the Apache Group and this document. +

+ +

+First, it is assumed that you are using a UNIX derivate operating system that +is capable of setuid and setgid operations. +All command examples are given in this regard. Other platforms, if they are +capable of supporting suEXEC, may differ in their configuration. +

+ +

+Second, it is assumed you are familiar with some basic concepts of your +computer's security and its administration. This involves an understanding +of setuid/setgid operations and the various effects they +may have on your system and its level of security. +

+ +

+Third, it is assumed that you are using an unmodified +version of suEXEC code. All code for suEXEC has been carefully scrutinized and +tested by the developers as well as numerous beta testers. Every precaution has +been taken to ensure a simple yet solidly safe base of code. Altering this +code can cause unexpected problems and new security risks. It is +highly recommended you not alter the suEXEC code unless you +are well versed in the particulars of security programming and are willing to +share your work with the Apache Group for consideration. +

+ +

+Fourth, and last, it has been the decision of the Apache Group to +NOT make suEXEC part of the default installation of Apache. +To this end, suEXEC configuration is a manual process requiring of the +administrator careful attention to details. It is through this process +that the Apache Group hopes to limit suEXEC installation only to those +who are determined to use it. +

+ +

+Still with us? Yes? Good. Let's move on! +

+ +

+BACK TO CONTENTS +

+ +

suEXEC Security Model

+

+Before we begin configuring and installing suEXEC, we will first discuss +the security model you are about to implement. By doing so, you may +better understand what exactly is going on inside suEXEC and what precautions +are taken to ensure your system's security. +

+ +

+suEXEC is based on a setuid "wrapper" program that is +called by the main Apache web server. This wrapper is called when an HTTP +request is made for a CGI or SSI program that the administrator has designated +to run as a userid other than that of the main server. When such a request +is made, Apache provides the suEXEC wrapper with the program's name and the +user and group IDs under which the program is to execute. +

+ +

+The wrapper then employs the following process to determine success or +failure -- if any one of these conditions fail, the program logs the failure +and exits with an error, otherwise it will continue: +

    +
  1. Was the wrapper called with the proper number of arguments? +
    + The wrapper will only execute if it is given the proper number of arguments. + The proper argument format is known to the Apache web server. If the wrapper + is not receiving the proper number of arguments, it is either being hacked, or + there is something wrong with the suEXEC portion of your Apache binary. +
    +
  2. +
  3. Is the user executing this wrapper a valid user of this system? +
    + This is to ensure that the user executing the wrapper is truly a user of the system. +
    +
  4. +
  5. Is this valid user allowed to run the wrapper? +
    + Is this user the user allowed to run this wrapper? Only one user (the Apache + user) is allowed to execute this program. +
    +
  6. +
  7. Does the target program have an unsafe hierarchical reference? +
    + Does the target program contain a leading '/' or have a '..' backreference? These + are not allowed; the target program must reside within the Apache webspace. +
    +
  8. +
  9. Is the target user name valid? +
    + Does the target user exist? +
    +
  10. +
  11. Is the target group name valid? +
    + Does the target group exist? +
    +
  12. +
  13. Is the target user NOT superuser? +
    + Presently, suEXEC does not allow 'root' to execute CGI/SSI programs. +
    +
  14. +
  15. Is the target userid ABOVE the minimum ID number? +
    + The minimum user ID number is specified during configuration. This allows you + to set the lowest possible userid that will be allowed to execute CGI/SSI programs. + This is useful to block out "system" accounts. +
    +
  16. +
  17. Is the target group NOT the superuser group? +
    + Presently, suEXEC does not allow the 'root' group to execute CGI/SSI programs. +
    +
  18. +
  19. Is the target groupid ABOVE the minimum ID number? +
    + The minimum group ID number is specified during configuration. This allows you + to set the lowest possible groupid that will be allowed to execute CGI/SSI programs. + This is useful to block out "system" groups. +
    +
  20. +
  21. Can the wrapper successfully become the target user and group? +
    + 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. +
    +
  22. +
  23. Does the directory in which the program resides exist? +
    + If it doesn't exist, it can't very well contain files. +
    +
  24. +
  25. Is the directory within the Apache webspace? +
    + 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? +
    +
  26. +
  27. Is the directory NOT writable by anyone else? +
    + We don't want to open up the directory to others; only the owner user may be able + to alter this directories contents. +
    +
  28. +
  29. Does the target program exist? +
    + If it doesn't exists, it can't very well be executed. +
    +
  30. +
  31. Is the target program NOT writable by anyone else? +
    + We don't want to give anyone other than the owner the ability to change the program. +
    +
  32. +
  33. Is the target program NOT setuid or setgid? +
    + We do not want to execute programs that will then change our UID/GID again. +
    +
  34. +
  35. Is the target user/group the same as the program's user/group? +
    + Is the user the owner of the file? +
    +
  36. +
  37. Can we successfully clean the process environment to ensure safe operations? +
    + 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). +
    +
  38. +
  39. Can we successfully become the target program and execute? +
    + Here is where suEXEC ends and the target program begins. +
    +
  40. +
+

+ +

+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. +

+ +

+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 "Beware the Jabberwock" +section of this document. +

+ +

+BACK TO CONTENTS +

+ +

Configuring & Installing suEXEC

+

+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. +

+ +

+EDITING THE SUEXEC HEADER FILE
+- From the top-level of the Apache source tree, type:   +cd support [ENTER] +

+ +

Edit the suexec.h file and change the following macros to -match your local Apache installation.

+match your local Apache installation. +

+ +

From support/suexec.h -

-/*
- * 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"
-
-/*
- * 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/etc/httpd/logs/cgi.log"
-
-/*
- * 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/etc/httpd/htdocs"
-
-/*
- * SAFE_PATH -- Define a safe PATH environment to pass to CGI executables.
- *
- */
-#define SAFE_PATH "/usr/local/bin:/usr/bin:/bin"
-
- -

Compiling the suEXEC wrapper

-At the shell command prompt, type:  cc suexec.c --o suexec [ENTER].

+

+     /*
+      * 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/etc/httpd/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/etc/httpd/htdocs"
+
+     /*
+      * SAFE_PATH -- Define a safe PATH environment to pass to CGI executables.
+      *
+      */
+     #define SAFE_PATH "/usr/local/bin:/usr/bin:/bin"
+
+

+ +

+COMPILING THE SUEXEC WRAPPER
+You now need to compile the suEXEC wrapper. At the shell command prompt, +type:  cc suexec.c -o suexec [ENTER]. This should create the suexec wrapper executable. +

-

Compiling Apache for suEXEC support

+

+COMPILING APACHE FOR USE WITH SUEXEC
By default, Apache is compiled to look for the suEXEC wrapper in the following -location.

+location. +

+ +

From src/httpd.h -

-/* The path to the suEXEC wrapper */
-#ifndef SUEXEC_BIN
-#define SUEXEC_BIN "/usr/local/etc/httpd/sbin/suexec"
-#endif
-
-

+

+     /* The path to the suEXEC wrapper */
+     #define SUEXEC_BIN "/usr/local/etc/httpd/sbin/suexec"
+
+

+ +

If your installation requires location of the wrapper program in a different directory, edit src/httpd.h and recompile your Apache server. -See Compiling and Installing Apache for more -info on this process.

+See Compiling and Installing Apache for more +info on this process. +

-

Installing the suEXEC wrapper

+

+COPYING THE SUEXEC BINARY TO ITS PROPER LOCATION
Copy the suexec executable created in the -exercise above to the defined location for SUEXEC_BIN.

-In order for the wrapper to set the user ID for execution requests it -must me installed as owner root and must have -the setuserid execution bit set for file modes. -If you are not running a root user shell, do -so now and execute the following commands.

- -chown root /usr/local/etc/httpd/sbin/suexec [ENTER]

-chmod 4711 /usr/local/etc/httpd/sbin/suexec [ENTER]

- -Change the path to the suEXEC wrapper to match your system -installation. - -


- -

Security Model of suEXEC

-The suEXEC wrapper supplied with Apache performs the -following security checks before it will execute any program passed to -it for execution. -
    -
  1. User executing the wrapper must be a valid user on this - system. -
  2. User executing the wrapper must be the compiled in - HTTPD_USER. -
  3. The command that the request wishes to execute must not - contain a leading / or ../, or the string "/../" anywhere. -
  4. The command being executed must reside under the compiled in - DOC_ROOT. -
  5. The current working directory must be a directory. -
  6. The current working directory must not be writable by - group or other. -
  7. The command being executed cannot be a symbolic link. -
  8. The command being executed cannot be writable by - group or other. -
  9. The command being executed cannot be a setuid or - setgid program. -
  10. The target UID and GID must be a valid user and group on - this system. -
  11. The target UID and GID to execute as, must match the UID and - GID of the directory. -
  12. The target execution UID and GID must not be the privileged - ID 0. -
-If any of these issues are too restrictive, or do not seem restrictive -enough, you are welcome to install your own version of the wrapper. -We've given you the rope, now go have fun with it. :-) - -
- -

Using suEXEC

+exercise above to the defined location for SUEXEC_BIN. +

+ +

+cp suexec /usr/local/etc/httpd/sbin/suexec [ENTER] +

+ +

+In order for the wrapper to set the user ID, it must me installed as owner +root and must have the setuserid execution bit +set for file modes. If you are not running a root +user shell, do so now and execute the following commands. +

+ +

+chown root /usr/local/etc/httpd/sbin/suexec [ENTER]
+chmod 4711 /usr/local/etc/httpd/sbin/suexec [ENTER] +

+ +

+BACK TO CONTENTS +

+ +

Enabling & Disabling suEXEC

+

After properly installing the suexec wrapper -executable, you must kill and restart the Apache server. A simple -kill -1 `cat httpd.pid` will not be enough. +executable, you must kill and restart the Apache server. A simple +kill -1 `cat httpd.pid` will not be enough. Upon startup of the web-server, if Apache finds a properly configured suexec wrapper, it will print the following message to -the console:

+the console: +

-Configuring Apache for use with suexec wrapper.

+

+Configuring Apache for use with suexec wrapper. +

+

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 setuid root. Check -your installation and try again.

+executable is not installed setuid root. Check +your installation and try again. +

+

One way to use suEXEC is through the User and Group directives in @@ -176,15 +438,68 @@ 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 security checks above. -


+

+BACK TO CONTENTS +

-

Debugging suEXEC

+

Debugging suEXEC

+

The suEXEC wrapper will write log information to the location defined in the suexec.h 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. - +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. +

+

+BACK TO CONTENTS +

+ +

Beware the Jabberwock: Warnings & Examples

+

+NOTE! This section may not be complete. For the latest +revision of this section of the documentation, see the Apache Group's +Online Documentation +version. +

+ +

+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. +

+ +

+BACK TO CONTENTS +

+ +