| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_cap</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_cap</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | Linux capabilities is a project aimed at providing the POSIX.1e security |
| 17 | model under Linux. Documentation for this project can be found here: |
| 18 | <pre> |
| 19 | <a href="ftp://ftp.kernel.org/pub/linux/libs/security/linux-privs">ftp://ftp.kernel.org/pub/linux/libs/security/linux-privs</a> |
| 20 | </pre> |
| 21 | Without going into gory detail, POSIX.1e basically specifies an interface to |
| 22 | such goodies as capabilities, capability sets, access control lists, mandatory |
| 23 | access control and much, much more. The end result of this security model |
| 24 | allows compliant systems and daemons to have <b>very</b> fine-grained control |
| 25 | over what operations are allowed by which services on the system. |
| 26 | |
| 27 | <p> |
| 28 | The best part of the whole story is that Linux kernels (since 2.1) |
| 29 | already have two important facets of the security model in place, namely |
| 30 | capabilities and capability sets. Using these features allows a userland |
| 31 | program to specifically drop capabilities (which can be thought of as |
| 32 | "privileges") which it does not need. Once such capabilities are |
| 33 | completely dropped, neither the userland program <b>nor</b> any binary it |
| 34 | should spawn will be allowed to perform privileged operations, <i>regardless</i> |
| 35 | of whether the program is running as root or not. Essentially, this limits |
| 36 | the power of root to only those specific functions that are necessary, with |
| 37 | the end effect of making the program much more secure. |
| 38 | |
| 39 | <p> |
| 40 | A contributed module has been added in the <code>proftpd</code> distribution, |
| 41 | named <code>mod_cap</code>. It can be found in the <code>modules/</code> |
| 42 | directory. |
| 43 | |
| 44 | <p> |
| 45 | The <code>libcap</code> library provides the interface between |
| 46 | <code>mod_cap</code> and the capability syscalls present in Linux kernels. |
| 47 | (Note that this library can be found at |
| 48 | <a href="http://www.kernel.org">www.kernel.org</a> or <a href="http://sourceforge.net/projects/linux-privs">sourceforge.net/projects/linux-privs</a>). |
| 49 | |
| 50 | <p> |
| 51 | When <code>proftpd</code> runs with <code>mod_cap</code> installed, its |
| 52 | operation changes slightly: |
| 53 | <ul> |
| 54 | <li>The master <code>proftpd</code> process runs as normal, with full |
| 55 | capabilities. |
| 56 | </li> |
| 57 | |
| 58 | <p> |
| 59 | <li> |
| 60 | The child <code>proftpd</code> processes, the ones that handle FTP sessions, |
| 61 | drop <b>all</b> capabilities-except for <code>CAP_NET_BIND_SERVICE</code> |
| 62 | (which allows a process to bind to port less than 1024) and |
| 63 | <code>CAP_CHOWN</code> (which allows a process to change a file's |
| 64 | ownership)-<i>immediately</i> after a client has authenticated. |
| 65 | |
| 66 | <p> |
| 67 | Additionally, switching back and forth between root privileges and the |
| 68 | authenticated user's privileges is no longer possible. |
| 69 | </li> |
| 70 | </ul> |
| 71 | Installation instructions for <code>mod_cap</code> can be found |
| 72 | <a href="#Installation">here</a>. |
| 73 | |
| 74 | <p> |
| 75 | The most current version of <code>mod_cap</code> can be found in the |
| 76 | ProFTPD source distribution: |
| 77 | <pre> |
| 78 | <a href="http://www.proftpd.org/">http://www.proftpd.org/</a> |
| 79 | </pre> |
| 80 | |
| 81 | <h2>Directives</h2> |
| 82 | <ul> |
| 83 | <li><a href="#CapabilitiesEngine">CapabilitiesEngine</a> |
| 84 | <li><a href="#CapabilitiesRootRevoke">CapabilitiesRootRevoke</a> |
| 85 | <li><a href="#CapabilitiesSet">CapabilitiesSet</a> |
| 86 | </ul> |
| 87 | |
| 88 | <hr> |
| 89 | <h3><a name="CapabilitiesEngine">CapabilitiesEngine</a></h3> |
| 90 | <strong>Syntax:</strong> CapabilitiesEngine <em>on|off</em><br> |
| 91 | <strong>Default:</strong> on<br> |
| 92 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 93 | <strong>Module:</strong> mod_cap<br> |
| 94 | <strong>Compatibility:</strong> 1.2.8rc2 and later |
| 95 | |
| 96 | <p> |
| 97 | The <code>CapabilitesEngine</code> directive enables or disables the module's |
| 98 | runtime capabilities engine. If it is set to <em>off</em> this module does no |
| 99 | runtime capabilities processing at all. Use this directive to disable the |
| 100 | module. |
| 101 | |
| 102 | <p> |
| 103 | <hr> |
| 104 | <h3><a name="CapabilitiesRootRevoke">CapabilitiesRootRevoke</a></h3> |
| 105 | <strong>Syntax:</strong> CapabilitiesRootRevoke <em>on|off</em><br> |
| 106 | <strong>Default:</strong> CapabilitiesRootRevoke on<br> |
| 107 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 108 | <strong>Module:</strong> mod_cap<br> |
| 109 | <strong>Compatibility:</strong> 1.3.5rc1 and later |
| 110 | |
| 111 | <p> |
| 112 | By default, the <code>mod_cap</code> module will <em>revoke</em> (<i>i.e.</i> |
| 113 | drop) root privileges entirely, once the necessary capabilities have been |
| 114 | set. Use the <code>CapabilitiesRootRevoke</code> directive to change this |
| 115 | default behavior, <i>e.g.</i>: |
| 116 | <pre> |
| 117 | CapabilitiesRootRevoke off |
| 118 | </pre> |
| 119 | |
| 120 | <p> |
| 121 | <hr> |
| 122 | <h3><a name="CapabilitiesSet">CapabilitiesSet</a></h3> |
| 123 | <strong>Syntax:</strong> CapabilitiesSet <em>[+|- cap] ...</em><br> |
| 124 | <strong>Default:</strong> None<br> |
| 125 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 126 | <strong>Module:</strong> mod_cap<br> |
| 127 | <strong>Compatibility:</strong> 1.2.8rc2 and later |
| 128 | |
| 129 | <p> |
| 130 | The <code>CapabilitiesSet</code> directive is used to manipulate the set of |
| 131 | capabilities that <code>mod_cap</code> grants. |
| 132 | |
| 133 | <p> |
| 134 | By default, <code>mod_cap</code> removes all but a few capabilities |
| 135 | from the session-handling process: <code>CAP_NET_BIND_SERVICE</code>, for |
| 136 | binding to ports lower than 1024 (required for active data transfers), and |
| 137 | <code>CAP_CHOWN</code>, for allowing a process to change a file's ownership |
| 138 | to a different user. The <code>CAP_CHOWN</code> capability is only strictly |
| 139 | necessary if the <code>UserOwner</code> configuration directive is in use; if |
| 140 | not being used, the <code>CAP_CHOWN</code> capability is best removed. |
| 141 | Additionally, <code>CAP_AUDIT_WRITE</code> is retained if |
| 142 | the <code>mod_auth_pam</code> module is present, as this capability is needed |
| 143 | for some PAM modules such as <code>pam_loginuid</code>. |
| 144 | |
| 145 | <p> |
| 146 | To remove a capability, prefix the name with a '-'; to enable a capability, |
| 147 | use '+'. This directive supports the following capabilities: |
| 148 | <ul> |
| 149 | <li><code>CAP_CHOWN</code> |
| 150 | <li><code>CAP_DAC_OVERRIDE</code> (override all directory access controls) |
| 151 | <li><code>CAP_DAC_READ_SEARCH</code> (allow read and search directory access) |
| 152 | <li><code>CAP_FOWNER</code> |
| 153 | <li><code>CAP_FSETID</code> |
| 154 | <li><code>CAP_SETUID</code> |
| 155 | </ul> |
| 156 | |
| 157 | <p> |
| 158 | Example: |
| 159 | <pre> |
| 160 | <IfModule mod_cap.c> |
| 161 | CapabilitiesEngine on |
| 162 | CapabilitiesSet -CAP_CHOWN +CAP_DAC_READ_SEARCH +CAP_FOWNER |
| 163 | </IfModule> |
| 164 | </pre> |
| 165 | |
| 166 | <p> |
| 167 | <hr> |
| 168 | <h2><a name="Installation">Installation</a></h2> |
| 169 | The <code>mod_cap</code> module is automatically included when |
| 170 | <code>proftpd</code> is built on a Linux system that supports capabilities; to |
| 171 | disable this automatic inclusion, use the <code>--disable-cap</code> configure |
| 172 | option. |
| 173 | |
| 174 | <p> |
| 175 | <hr> |
| 176 | <h2><a name="FAQ">FAQ</a></h2> |
| 177 | |
| 178 | <p> |
| 179 | <font color=red>Question</font>: Why do I see the following in my system logs? |
| 180 | <pre> |
| 181 | warning: `proftpd' uses 32-bit capabilities (legacy support in use) |
| 182 | </pre> |
| 183 | <font color=blue>Answer</font>: This warning is coming from the use of the |
| 184 | libcap library. A newer version of the libcap library (called the |
| 185 | "libcap2" or "libcap2-dev" package on some Linux distributions) is now |
| 186 | available. |
| 187 | |
| 188 | <p> |
| 189 | To remove the above warning, you will need to update/install the newer libcap2 |
| 190 | or libcap2-dev package on your system, and re-build proftpd (using version |
| 191 | 1.3.2rc1 or later) in order to compile and link against the newer libcap |
| 192 | library. |
| 193 | |
| 194 | <p> |
| 195 | <font color=red>Question</font>: What does the following mean? |
| 196 | <pre> |
| 197 | chown() as root failed: Operation not permitted |
| 198 | </pre> |
| 199 | <font color=blue>Answer</font>: The purpose of the <code>mod_cap</code> |
| 200 | module is to restrict the capabilities of the all-powerful <code>root</code> |
| 201 | user. Thus when <code>mod_cap</code> is in effect, operations like |
| 202 | <code>chown()</code> are restricted. |
| 203 | |
| 204 | <p> |
| 205 | The message above usually happens when your configuration uses the |
| 206 | <code>UserOwner</code> or <code>GroupOwner</code> configuration directives. |
| 207 | To enable those directives to function and still use <code>mod_cap</code>, |
| 208 | you will need to use a configuration such as: |
| 209 | <pre> |
| 210 | <IfModule mod_cap.c> |
| 211 | # Allow root to use chown(2) |
| 212 | CapabilitiesSet -CAP_CHOWN |
| 213 | </IfModule> |
| 214 | </pre> |
| 215 | |
| 216 | <p> |
| 217 | <hr> |
| 218 | <font size=2><b><i> |
| 219 | © Copyright 2000-2013 TJ Saunders<br> |
| 220 | All Rights Reserved<br> |
| 221 | </i></b></font> |
| 222 | |
| 223 | <hr> |
| 224 | </body> |
| 225 | </html> |
| 226 |