Debian Codegraph @

doc/howto/Limit.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ProFTPD: Configuring &lt;Limits&gt;</title>
5 </head>
6
7 <body bgcolor=white>
8
9 <hr>
10 <center><h2><b>ProFTPD: Configuring <code>&lt;Limits&gt;</code></b></h2></center>
11 <hr>
12
13 <p>
14 ProFTPD's <code>&lt;Limit&gt;</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>&lt;Limit&gt;</code> sections.
19
20 <p>
21 <b>Precedence</b><br>
22 Perhaps the hardest part of using <code>&lt;Limit&gt;</code> is understanding
23 its rules of precedence, which dictate which <code>&lt;Limit&gt;</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>&lt;Limit&gt;</code> directive: &quot;raw&quot;
27 FTP commands, FTP command groups, and the <code>ALL</code> keyword.
28
29 <p>
30 &quot;Raw&quot; 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>&lt;Limit&gt;</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>&lt;Limit&gt;</code>s that use &quot;raw&quot; FTP commands have
59 the highest precedence, followed by <code>&lt;Limit&gt;</code>s that use
60 the command groups, and, having the lowest precedence, the <code>ALL</code>
61 keyword. If a <code>&lt;Limit&gt;</code> has both &quot;raw&quot; commands
62 and command groups, then it boils down to the order of appearance of
63 <code>&lt;Limit&gt;</code> sections in <code>proftpd.conf</code> that
64 use the &quot;raw&quot; command in question.
65
66 <p>
67 <b><code>SITE</code> Commands</b><br>
68 To apply a <code>&lt;Limit&gt;</code> to a <code>SITE</code> command, combine
69 &quot;SITE&quot; and the command (<i>e.g.</i> &quot;CHMOD&quot;) by an
70 underscore (&quot;_&quot;), like so:
71 <pre>
72 &lt;Limit SITE_<i>command</i>&gt;
73 </pre>
74 Thus, in order to place a limit on <code>SITE CHMOD</code>, one would have:
75 <pre>
76 &lt;Limit SITE_CHMOD&gt;
77 DenyAll
78 &lt;/Limit&gt;
79 </pre>
80
81 <p>
82 <b>Inheritance</b><br>
83 Most <code>&lt;Limit&gt;</code> sections appear within
84 <code>&lt;Directory&gt;</code> sections in <code>proftpd.conf</code>. This
85 means that, like the other <code>&lt;Directory&gt;</code> configuration
86 effects, the <code>&lt;Limit&gt;</code>s will be inherited by all subdirectories
87 that appear in the <code>&lt;Directory&gt;</code> path, unless explicitly
88 overridden by a &quot;closer&quot; <code>&lt;Limit&gt;</code> section.
89 This means that one could configure a <code>&lt;Limit&gt;</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>&lt;Limit&gt;</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 &quot;Allow,Deny&quot; 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 &quot;Deny,Allow&quot;
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 &quot;Allow,Deny&quot; <b>allows</b> access by
144 default, unless denied by a <code>Deny</code> directive; &quot;Deny,Allow&quot;
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 &quot;common sense&quot; 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>&lt;Limit&gt;</code>.
153 First, a common configuration: an upload-only directory.
154 <pre>
155 &lt;Directory /path/to/uploads&gt;
156 &lt;Limit ALL&gt;
157 DenyAll
158 &lt;/Limit&gt;
159
160 &lt;Limit CDUP CWD PWD XCWD XCUP&gt;
161 AllowAll
162 &lt;/Limit&gt;
163
164 &lt;Limit STOR STOU&gt;
165 AllowAll
166 &lt;/Limit&gt;
167 &lt;/Directory&gt;
168 </pre>
169 The first <code>&lt;Limit ALL&gt;</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 &quot;blind&quot; 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 &lt;Directory /path/to/dir&gt;
187 &lt;Limit LIST NLST MLSD MLST STAT&gt;
188 DenyAll
189 &lt;/Limit&gt;
190 &lt;/Directory&gt;
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 &lt;Limit LOGIN&gt;
206 AllowUser barb
207 AllowUser dave
208 AllowGroup ftpuser
209 DenyAll
210 &lt;/Limit&gt;
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 &lt;Limit LOGIN&gt;
221 DenyAll
222 &lt;/Limit&gt;
223
224 &lt;Anonymous ~ftp&gt;
225 &lt;Limit LOGIN&gt;
226 AllowAll
227 &lt;/Limit&gt;
228 ...
229 &lt;/Anonymous&gt;
230 </pre>
231
232 The <code>&lt;Limit&gt;</code> section outside of the
233 <code>&lt;Anonymous&gt;</code> section denies logins to everyone. However,
234 the <code>&lt;Anonymous&gt;</code> section has a <code>&lt;Limit&gt;</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 &quot;How can I limit a user to only
240 being able to login from a specific range of IP addresses?&quot; The
241 <code>&lt;Limit LOGIN&gt;</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 &lt;Class friends&gt;
246 From 1.2.3.4/8
247 &lt;/Class&gt;
248
249 &lt;IfUser dave&gt;
250 &lt;Limit LOGIN&gt;
251 AllowClass friends
252 DenyAll
253 &lt;/Limit&gt;
254 &lt;/IfUser&gt;
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 &lt;IfUser dave&gt;
262 &lt;Limit LOGIN&gt;
263 Deny from 1.2.3.4
264 &lt;/Limit&gt;
265 &lt;/IfUser&gt;
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>&lt;Limit LOGIN&gt;</code> sections in your config
274 <i>for the same vhost</i>. Consider a config like this:
275 <pre>
276 &lt;VirtualHost 1.2.3.4&gt;
277 ...
278 &lt;Limit LOGIN&gt;
279 Order allow, deny
280 Allow from 192.168.0.0/16
281 DenyAll
282 &lt;/Limit&gt;
283 ...
284 &lt;Limit LOGIN&gt;
285 Order deny, allow
286 Deny from 192.168.0.0/16
287 &lt;/Limit&gt;
288 ...
289 &lt;/VirtualHost&gt;
290 </pre>
291 The two <code>&lt;Limit LOGIN&gt;</code> sections conflict; which one will
292 <code>proftpd</code> actually use for deciding whether to allow a connection
293 to that <code>&lt;VirtualHost&gt;</code>? Answer: the <b>last</b>
294 <code>&lt;Limit LOGIN&gt;</code> section defined. To avoid confusion, then,
295 it is best to consolidate all of your <code>&lt;Limit LOGIN&gt;</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 &lt;Directory /some/path&gt;
305 &lt;Limit LOGIN&gt;
306 DenyUser foo
307 &lt;/Limit&gt;
308 &lt;/Directory&gt;
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 &quot;table of contents&quot;, 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 &lt;Directory /path/to/dir&gt;
329 &lt;Limit DELE&gt;
330 AllowUser ftpadm
331 DenyAll
332 &lt;/Limit&gt;
333 &lt;/Directory&gt;
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>&lt;Limit&gt;</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 &lt;Limit EPRT PORT&gt;
348 DenyAll
349 &lt;/Limit&gt;
350 </pre>
351 Or, conversely, to block passive data transfers:
352 <pre>
353 &lt;Limit EPSV PASV&gt;
354 DenyAll
355 &lt;/Limit&gt;
356 </pre>
357
358 <p>
359 Another common question is: "How can I create a read-only account using
360 <code>&lt;Limit&gt;</code> sections"? Here's how:
361 <pre>
362 # Assumes that the user is chrooted into their home directory
363 &lt;Directory ~<i>user</i>&gt;
364 &lt;Limit CWD PWD DIRS READ&gt;
365 AllowUser <i>user</i>
366 &lt;/Limit&gt;
367
368 &lt;Limit ALL&gt;
369 DenyUser <i>user</i>
370 &lt;/Limit&gt;
371 &lt;/Directory&gt;
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>&lt;Directory&gt;</code> sections with
378 <code>&lt;Limit&gt;</code> sections, you can do this, <i>e.g.</i>:
379 <pre>
380 &lt;Directory /path/to/dir&gt;
381 &lt;Limit RMD XRMD&gt;
382 DenyAll
383 &lt;/Limit&gt;
384 &lt;/Directory&gt;
385
386 &lt;Directory /path/to/dir/*&gt;
387 &lt;Limit RMD XRMD&gt;
388 AllowAll
389 &lt;/Limit&lt;
390 &gt;/Directory&gt;
391 </pre>
392 Note the trailing "/*" suffix in the second <code>&lt;Directory&gt;</code>
393 section; this means that the second <code>&lt;Directory&gt;</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>&lt;Directory&gt;</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 &lt;Directory /path/to/dir&gt;
404 &lt;Limit RMD RNFR RNTO XRMD&gt;
405 DenyAll
406 &lt;/Limit&gt;
407 &lt;/Directory&gt;
408 </pre>
409
410 <p>
411 <hr>
412 <font size=2><b><i>
413 &copy; Copyright 2000-2016 The ProFTPD Project<br>
414 All Rights Reserved<br>
415 </i></b></font>
416 <hr>
417
418 </body>
419 </html>