| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Configuring <Limits></title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Configuring <code><Limits></code></b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | ProFTPD's <code><Limit></code> configuration sections allow for |
| 15 | powerful fine-grained control over who is allowed to use which FTP commands. |
| 16 | This power comes at the price of complexity, however. This document |
| 17 | describes some of the things to keep in mind when writing |
| 18 | <code><Limit></code> sections. |
| 19 | |
| 20 | <p> |
| 21 | <b>Precedence</b><br> |
| 22 | Perhaps the hardest part of using <code><Limit></code> is understanding |
| 23 | its rules of precedence, which dictate which <code><Limit></code>'s |
| 24 | restrictions apply when. Precedence is discussed in the directive |
| 25 | documentation, and will be mentioned here. First, there are three types |
| 26 | of parameters in a <code><Limit></code> directive: "raw" |
| 27 | FTP commands, FTP command groups, and the <code>ALL</code> keyword. |
| 28 | |
| 29 | <p> |
| 30 | "Raw" FTP commands are listed <a href="FTP.html">here</a>, including |
| 31 | the RFC-mandated <a href="FTP.html#XCUP">X-variant</a> FTP commands, which are |
| 32 | often missing from a thorough <code><Limit></code> configuration. |
| 33 | |
| 34 | <p> |
| 35 | The FTP command groups are: |
| 36 | <ul> |
| 37 | <li>ALL<br> |
| 38 | <i>Covering</i>: all FTP commands (but <b>not</b> <code>LOGIN</code>) |
| 39 | |
| 40 | <p> |
| 41 | <li>DIRS<br> |
| 42 | <i>Covering</i>: CDUP, CWD, LIST, MDTM, MLSD, MLST, NLST, PWD, RNFR, STAT, XCUP, XCWD, XPWD |
| 43 | |
| 44 | <p> |
| 45 | <li>LOGIN<br> |
| 46 | <i>Covering</i>: client logins |
| 47 | |
| 48 | <p> |
| 49 | <li>READ<br> |
| 50 | <i>Covering</i>: RETR, SIZE |
| 51 | |
| 52 | <p> |
| 53 | <li>WRITE<br> |
| 54 | <i>Covering</i>: APPE, DELE, MKD, RMD, RNTO, STOR, STOU, XMKD, XRMD |
| 55 | </ul> |
| 56 | |
| 57 | <p> |
| 58 | <code><Limit></code>s that use "raw" FTP commands have |
| 59 | the highest precedence, followed by <code><Limit></code>s that use |
| 60 | the command groups, and, having the lowest precedence, the <code>ALL</code> |
| 61 | keyword. If a <code><Limit></code> has both "raw" commands |
| 62 | and command groups, then it boils down to the order of appearance of |
| 63 | <code><Limit></code> sections in <code>proftpd.conf</code> that |
| 64 | use the "raw" command in question. |
| 65 | |
| 66 | <p> |
| 67 | <b><code>SITE</code> Commands</b><br> |
| 68 | To apply a <code><Limit></code> to a <code>SITE</code> command, combine |
| 69 | "SITE" and the command (<i>e.g.</i> "CHMOD") by an |
| 70 | underscore ("_"), like so: |
| 71 | <pre> |
| 72 | <Limit SITE_<i>command</i>> |
| 73 | </pre> |
| 74 | Thus, in order to place a limit on <code>SITE CHMOD</code>, one would have: |
| 75 | <pre> |
| 76 | <Limit SITE_CHMOD> |
| 77 | DenyAll |
| 78 | </Limit> |
| 79 | </pre> |
| 80 | |
| 81 | <p> |
| 82 | <b>Inheritance</b><br> |
| 83 | Most <code><Limit></code> sections appear within |
| 84 | <code><Directory></code> sections in <code>proftpd.conf</code>. This |
| 85 | means that, like the other <code><Directory></code> configuration |
| 86 | effects, the <code><Limit></code>s will be inherited by all subdirectories |
| 87 | that appear in the <code><Directory></code> path, unless explicitly |
| 88 | overridden by a "closer" <code><Limit></code> section. |
| 89 | This means that one could configure a <code><Limit></code> section |
| 90 | denying all FTP commands for all directories, and then explicitly allow |
| 91 | the <code>READ</code> or <code>WRITE</code> FTP command groups in appropriate |
| 92 | subdirectories (<i>e.g.</i> <code>pub/</code> or <code>incoming/</code> |
| 93 | directories). |
| 94 | |
| 95 | <p> |
| 96 | <b>Using <code>AllowUser</code> and <code>DenyUser</code></b><br> |
| 97 | There is a catch to using the <code>AllowUser</code> configuration directive |
| 98 | that causes confusion, primarily when a single <code>AllowUser</code> |
| 99 | directive is being used to allow access to some FTP commands only to |
| 100 | certain users. ProFTPD uses the same function for parsing the |
| 101 | <code>AllowUser</code> and <code>AllowGroup</code> (and other) directives. |
| 102 | This function parses the list of names for such directives as a |
| 103 | Boolean AND list, which means that each name on the list must evaluate to |
| 104 | TRUE (must match) for the current user in order for the directive to apply. |
| 105 | For <code>AllowGroup</code>, this makes sense, and allows a great deal |
| 106 | of flexibility. However, it does not make sense for <code>AllowUser</code>, |
| 107 | because a user may not be multiple users at the same time. This is a known |
| 108 | issue, and a proper, thorough solution is being developed. In the meantime, |
| 109 | however, there is a workaround for allowing multiple users via the |
| 110 | <code>AllowUser</code> directive. Rather than listing the users using |
| 111 | a single <code>AllowUser</code>, using a separate <code>AllowUser</code> |
| 112 | for each user. For example, instead of: |
| 113 | <pre> |
| 114 | AllowUser bob,dave,wendy |
| 115 | </pre> |
| 116 | try using: |
| 117 | <pre> |
| 118 | AllowUser bob |
| 119 | AllowUser dave |
| 120 | AllowUser wendy |
| 121 | </pre> |
| 122 | All of this applies to the <code>DenyUser</code> directive as well. |
| 123 | |
| 124 | <p> |
| 125 | Another important item to keep in mind is that the names used in |
| 126 | <code><Limit></code> sections, <i>e.g.</i> using <code>AllowUser</code>, |
| 127 | <code>DenyUser</code>, <code>AllowGroup</code>, and <code>DenyGroup</code>, |
| 128 | are <b>not</b> resolved to an ID and then applied; the limits are applied |
| 129 | only to the names. Why is this important? Consider the case where the site |
| 130 | is using virtual users, where two different user names are assigned the |
| 131 | same UID. Different limits can be applied to each name separately. Do not |
| 132 | assume that the limits are applied to the underlying IDs. |
| 133 | |
| 134 | <p> |
| 135 | <b>Using <code>Order</code></b><br> |
| 136 | One thing that sometimes trips up some administrators is the difference |
| 137 | between ProFTPD's and Apache's <code>Order</code> configuration directives. |
| 138 | For Apache, an <code>Order</code> of "Allow,Deny" means that |
| 139 | access is <b>denied</b> by default, unless an <code>Allow</code> directive |
| 140 | explicitly allows access; an <code>Order</code> of "Deny,Allow" |
| 141 | means that access is <b>allowed</b> by default, unless a <code>Deny</code> |
| 142 | directive explicitly denies access. This is different from ProFTPD, where |
| 143 | an <code>Order</code> of "Allow,Deny" <b>allows</b> access by |
| 144 | default, unless denied by a <code>Deny</code> directive; "Deny,Allow" |
| 145 | <b>denies</b> access by default, unless explicitly granted by an |
| 146 | <code>Allow</code> directive. The developers of ProFTPD felt their |
| 147 | interpretation to be the more "common sense" interpretation, even |
| 148 | though it does not match Apache's interpretation. |
| 149 | |
| 150 | <p><a name="Examples"></a> |
| 151 | <b>Examples</b><br> |
| 152 | Here are examples to help illustrate the use of <code><Limit></code>. |
| 153 | First, a common configuration: an upload-only directory. |
| 154 | <pre> |
| 155 | <Directory /path/to/uploads> |
| 156 | <Limit ALL> |
| 157 | DenyAll |
| 158 | </Limit> |
| 159 | |
| 160 | <Limit CDUP CWD PWD XCWD XCUP> |
| 161 | AllowAll |
| 162 | </Limit> |
| 163 | |
| 164 | <Limit STOR STOU> |
| 165 | AllowAll |
| 166 | </Limit> |
| 167 | </Directory> |
| 168 | </pre> |
| 169 | The first <code><Limit ALL></code> section blocks use of <i>all</i> FTP |
| 170 | commands within the <code>/path/to/uploads</code> directory. Having denied |
| 171 | use of all commands, we then proceed to define which commands <i>can</i> be |
| 172 | used. The <code>CDUP</code> and <code>CWD</code> commands (and their X |
| 173 | variants) should be allowed so that clients can change into and out of the |
| 174 | directory. Next, <code>STOR</code> and <code>STOU</code> are allowed, so that |
| 175 | clients can actually upload files into the directory (assuming that the |
| 176 | filesystem permissions allow for the client to write files in the directory |
| 177 | as well). The <code>WRITE</code> command group might have been used, but |
| 178 | that also allows things like creating and deleting subdirectories, which |
| 179 | is usually not wanted in an upload-only configuration. |
| 180 | |
| 181 | <p> |
| 182 | This next example shows a "blind" directory, where clients can |
| 183 | upload and download files from the directory, but they cannot see what is |
| 184 | in the directory: |
| 185 | <pre> |
| 186 | <Directory /path/to/dir> |
| 187 | <Limit LIST NLST MLSD MLST STAT> |
| 188 | DenyAll |
| 189 | </Limit> |
| 190 | </Directory> |
| 191 | </pre> |
| 192 | That's it. By default, all commands are allowed in a directory. By blocking |
| 193 | the FTP commands used to list a directory's contents (<i>i.e.</i> |
| 194 | <code>LIST</code>, <code>MLSD</code>, <code>MLST</code>, and <code>NLST</code>), |
| 195 | we have effectively blocked the client from seeing anything in the directory. |
| 196 | Not many clients use the <code>STAT</code> command, but it also needs to |
| 197 | be limited, as it can return information about files in a directory as well. |
| 198 | |
| 199 | <p> |
| 200 | Cautious system administrators may want only a few select system users to be |
| 201 | able to connect to their <code>proftpd</code> server--all other users are |
| 202 | to be denied access. The <code>LOGIN</code> command group is designed for |
| 203 | just this scenario: |
| 204 | <pre> |
| 205 | <Limit LOGIN> |
| 206 | AllowUser barb |
| 207 | AllowUser dave |
| 208 | AllowGroup ftpuser |
| 209 | DenyAll |
| 210 | </Limit> |
| 211 | </pre> |
| 212 | This allows the users <code>barb</code> and <code>dave</code>, as well as |
| 213 | any user in the <code>ftpuser</code> group, to login. All other users will |
| 214 | be denied. |
| 215 | |
| 216 | <p> |
| 217 | What if a site wished to allow <b>only</b> anonymous access? This would be |
| 218 | configured using the <code>LOGIN</code> command group, as above: |
| 219 | <pre> |
| 220 | <Limit LOGIN> |
| 221 | DenyAll |
| 222 | </Limit> |
| 223 | |
| 224 | <Anonymous ~ftp> |
| 225 | <Limit LOGIN> |
| 226 | AllowAll |
| 227 | </Limit> |
| 228 | ... |
| 229 | </Anonymous> |
| 230 | </pre> |
| 231 | |
| 232 | The <code><Limit></code> section outside of the |
| 233 | <code><Anonymous></code> section denies logins to everyone. However, |
| 234 | the <code><Anonymous></code> section has a <code><Limit></code> |
| 235 | that allows everyone to login; anonymous logins are allowed, and non-anonymous |
| 236 | logins are denied. |
| 237 | |
| 238 | <p> |
| 239 | Another related question often asked is "How can I limit a user to only |
| 240 | being able to login from a specific range of IP addresses?" The |
| 241 | <code><Limit LOGIN></code> can be used, in conjunction with the |
| 242 | <a href="../../contrib/mod_ifsession.html">mod_ifsession</a> module and a |
| 243 | <a href="Classes.html">Class</a>, to configure this: |
| 244 | <pre> |
| 245 | <Class friends> |
| 246 | From 1.2.3.4/8 |
| 247 | </Class> |
| 248 | |
| 249 | <IfUser dave> |
| 250 | <Limit LOGIN> |
| 251 | AllowClass friends |
| 252 | DenyAll |
| 253 | </Limit> |
| 254 | </IfUser> |
| 255 | </pre> |
| 256 | |
| 257 | <p> |
| 258 | Or if you want to have a specific IP address, rather than a range, you can |
| 259 | do this without classes (but still requiring <code>mod_ifsession</code>): |
| 260 | <pre> |
| 261 | <IfUser dave> |
| 262 | <Limit LOGIN> |
| 263 | Deny from 1.2.3.4 |
| 264 | </Limit> |
| 265 | </IfUser> |
| 266 | </pre> |
| 267 | Note that the same effect can be achieved by using the |
| 268 | <a href="../../contrib/mod_wrap2.html">mod_wrap2</a> module to configure |
| 269 | user-specific allow/deny files. |
| 270 | |
| 271 | <p> |
| 272 | One issue that you should avoid is having multiple different |
| 273 | <code><Limit LOGIN></code> sections in your config |
| 274 | <i>for the same vhost</i>. Consider a config like this: |
| 275 | <pre> |
| 276 | <VirtualHost 1.2.3.4> |
| 277 | ... |
| 278 | <Limit LOGIN> |
| 279 | Order allow, deny |
| 280 | Allow from 192.168.0.0/16 |
| 281 | DenyAll |
| 282 | </Limit> |
| 283 | ... |
| 284 | <Limit LOGIN> |
| 285 | Order deny, allow |
| 286 | Deny from 192.168.0.0/16 |
| 287 | </Limit> |
| 288 | ... |
| 289 | </VirtualHost> |
| 290 | </pre> |
| 291 | The two <code><Limit LOGIN></code> sections conflict; which one will |
| 292 | <code>proftpd</code> actually use for deciding whether to allow a connection |
| 293 | to that <code><VirtualHost></code>? Answer: the <b>last</b> |
| 294 | <code><Limit LOGIN></code> section defined. To avoid confusion, then, |
| 295 | it is best to consolidate all of your <code><Limit LOGIN></code> rules |
| 296 | into a single section for a given vhost. |
| 297 | |
| 298 | <p> |
| 299 | In Apache, it is possible to configure password-protected directories. |
| 300 | Some sysadmins attempt to configure <code>proftpd</code> similarly, by |
| 301 | unsuccessfully attempting something like this in the |
| 302 | <code>proftpd.conf</code> file: |
| 303 | <pre> |
| 304 | <Directory /some/path> |
| 305 | <Limit LOGIN> |
| 306 | DenyUser foo |
| 307 | </Limit> |
| 308 | </Directory> |
| 309 | </pre> |
| 310 | The above will <b>not</b> work. FTP clients (unlike HTTP clients) login |
| 311 | to the <i>server</i>, not into specific directories. |
| 312 | |
| 313 | <p> |
| 314 | One situation that often arises is one where the administrator would like |
| 315 | to give users the ability to upload and dowload files from a given directory, |
| 316 | but not to be able to delete files from that directory. This cannot be |
| 317 | accomplished using normal Unix filesystem permissions, for if a user has |
| 318 | write permission on a directory (necessary for uploading files to that |
| 319 | directory) they also have delete permissions. In Unix, a directory file |
| 320 | serves as a sort of "table of contents", tracking the files in |
| 321 | the directory. Adding or removing a file are thus changes on the directory |
| 322 | file, and do not involve checking the permissions on the file being added |
| 323 | or removed. This is also how a non-root user can delete files that are owned |
| 324 | by root and only have user-write permissions. So how then can a site |
| 325 | be configured to allow writes but not deletes? By using a configuration |
| 326 | similar to the following: |
| 327 | <pre> |
| 328 | <Directory /path/to/dir> |
| 329 | <Limit DELE> |
| 330 | AllowUser ftpadm |
| 331 | DenyAll |
| 332 | </Limit> |
| 333 | </Directory> |
| 334 | </pre> |
| 335 | This will allow the user <code>ftpadm</code> to delete files in the |
| 336 | <code>/path/to/dir</code>, but no other users. |
| 337 | |
| 338 | <p> |
| 339 | The FTP protocol has two types of data transfers: active and passive. In |
| 340 | some configurations, only one type of transfer is allowed by the network |
| 341 | (<i>e.g.</i> active transfers should be denied because clients are sending |
| 342 | the wrong IP addresses). The ability to place a <code><Limit></code> |
| 343 | on the FTP commands response for active and passive data transfers was |
| 344 | added to ProFTPD in 1.2.10rc1. If you are using that version or later, |
| 345 | you can use the following to block active transfers: |
| 346 | <pre> |
| 347 | <Limit EPRT PORT> |
| 348 | DenyAll |
| 349 | </Limit> |
| 350 | </pre> |
| 351 | Or, conversely, to block passive data transfers: |
| 352 | <pre> |
| 353 | <Limit EPSV PASV> |
| 354 | DenyAll |
| 355 | </Limit> |
| 356 | </pre> |
| 357 | |
| 358 | <p> |
| 359 | Another common question is: "How can I create a read-only account using |
| 360 | <code><Limit></code> sections"? Here's how: |
| 361 | <pre> |
| 362 | # Assumes that the user is chrooted into their home directory |
| 363 | <Directory ~<i>user</i>> |
| 364 | <Limit CWD PWD DIRS READ> |
| 365 | AllowUser <i>user</i> |
| 366 | </Limit> |
| 367 | |
| 368 | <Limit ALL> |
| 369 | DenyUser <i>user</i> |
| 370 | </Limit> |
| 371 | </Directory> |
| 372 | </pre> |
| 373 | |
| 374 | <p> |
| 375 | What if you want to prevent a certain directory from being deleted, but |
| 376 | you <i>do</i> want to allow sub-directories in that directory to be deletable? |
| 377 | Using two <code><Directory></code> sections with |
| 378 | <code><Limit></code> sections, you can do this, <i>e.g.</i>: |
| 379 | <pre> |
| 380 | <Directory /path/to/dir> |
| 381 | <Limit RMD XRMD> |
| 382 | DenyAll |
| 383 | </Limit> |
| 384 | </Directory> |
| 385 | |
| 386 | <Directory /path/to/dir/*> |
| 387 | <Limit RMD XRMD> |
| 388 | AllowAll |
| 389 | </Limit< |
| 390 | >/Directory> |
| 391 | </pre> |
| 392 | Note the trailing "/*" suffix in the second <code><Directory></code> |
| 393 | section; this means that the second <code><Directory></code> section |
| 394 | configuration applies to the sub-directories, but <i>not</i> to the parent |
| 395 | directory itself (which is covered by the first <code><Directory></code> |
| 396 | section). |
| 397 | |
| 398 | <p> |
| 399 | What if you want to make sure the directory cannot be renamed, in addition to |
| 400 | ensuring that it cannot be deleted? Simply include the <code>RNFR</code> and |
| 401 | <code>RNTO</code> FTP commands in the list of denied commands, <i>e.g.</i>: |
| 402 | <pre> |
| 403 | <Directory /path/to/dir> |
| 404 | <Limit RMD RNFR RNTO XRMD> |
| 405 | DenyAll |
| 406 | </Limit> |
| 407 | </Directory> |
| 408 | </pre> |
| 409 | |
| 410 | <p> |
| 411 | <hr> |
| 412 | <font size=2><b><i> |
| 413 | © Copyright 2000-2016 The ProFTPD Project<br> |
| 414 | All Rights Reserved<br> |
| 415 | </i></b></font> |
| 416 | <hr> |
| 417 | |
| 418 | </body> |
| 419 | </html> |