| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD: Controls</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center><h2><b>ProFTPD: Controls and <code>mod_ctrls</code></b></h2></center> |
| 11 | <hr> |
| 12 | |
| 13 | <p> |
| 14 | <b>What Controls Are</b><br> |
| 15 | ProFTPD version 1.2.10rc1 introduced a new capability: Controls. Controls |
| 16 | are a way to communicate directly with a standalone <code>proftpd</code> daemon |
| 17 | while it is running. This provides administrators a way to alter the |
| 18 | daemon's behavior in real time, without having to restart the daemon and |
| 19 | have it re-read its configuration. Changing log levels, kicking connected |
| 20 | clients, disabling individual virtual servers, <i>etc.</i> are all possible. |
| 21 | The Controls functionality includes an API that third-party modules can |
| 22 | use to add new control actions. |
| 23 | |
| 24 | <p> |
| 25 | The functionality involves a client and a server communicating over a Unix |
| 26 | domain socket, using a simple text-based protocol. A new program, |
| 27 | <code>ftpdctl</code>, is distributed with ProFTPD; <code>ftpdctl</code> is a |
| 28 | Controls client. The server side of the Controls functionality is the |
| 29 | <a href="../modules/mod_ctrls.html"><code>mod_ctrls</code></a> module, which is |
| 30 | compiled into a <code>proftpd</code> daemon when the <em>--enable-ctrls</em> |
| 31 | configure option is used. Note, however, that the Controls functionality only |
| 32 | works for <code>proftpd</code> daemons whose <code>ServerType</code> is |
| 33 | <code>standalone</code>; <code>proftpd</code> daemons run via inetd/xinetd |
| 34 | cannot support Controls and the <code>ftpdctl</code> program. |
| 35 | |
| 36 | <p> |
| 37 | <b>Configuring <code>mod_ctrls</code></b><br> |
| 38 | Here's an example configuration for <code>mod_ctrls</code>: |
| 39 | <pre> |
| 40 | <IfModule mod_ctrls.c> |
| 41 | ControlsEngine on |
| 42 | ControlsACLs all allow group ftpadm |
| 43 | ControlsMaxClients 2 |
| 44 | ControlsLog /var/log/proftpd/controls.log |
| 45 | ControlsInterval 5 |
| 46 | ControlsSocket /tmp/ctrls.sock |
| 47 | ControlsSocketOwner ftpd ftpd |
| 48 | ControlsSocketACL allow group ftpadm |
| 49 | </IfModule> |
| 50 | </pre> |
| 51 | The first configuration directive you will want to use is the |
| 52 | <code>ControlsEngine</code> directive, which enables the processing of |
| 53 | Controls requests by the engine within the <code>mod_ctrls</code> |
| 54 | engine. |
| 55 | |
| 56 | <p> |
| 57 | When first configuring <code>mod_ctrls</code> and its modules, you will |
| 58 | probably want to configure a <code>ControlsLog</code>. The |
| 59 | <code>mod_ctrls</code> modules will log any errors they have to this |
| 60 | file (unless the module has its own module-specific log), as well as all |
| 61 | control requests made using <code>ftpdctl</code>. Like most |
| 62 | <code>proftpd</code> log files, the directive should use the full |
| 63 | path to the log file, and the file cannot be in a world-writeable directory. |
| 64 | |
| 65 | <p> |
| 66 | The <code>ControlsInterval</code> directive configures how often |
| 67 | <code>mod_ctrls</code> checks for connecting clients such as |
| 68 | <code>ftpdctl</code>. Often when using <code>ftpdctl</code>, the system |
| 69 | administrator may notice a long pause before <code>ftpdct</code> responds. |
| 70 | This delay is probably caused by the configured <code>ControlsInterval</code>. |
| 71 | A related directive is <code>ControlsMaxClients</code>, which sets how |
| 72 | many clients are handled at one time. If more than the configured maximum |
| 73 | number of clients are attempting to send control requests, |
| 74 | <code>mod_ctrls</code> will wait to handle the remaining clients until its |
| 75 | next check. |
| 76 | |
| 77 | <p> |
| 78 | The <code>ControlsSocket</code> directive is used to configure the path |
| 79 | to the Unix domain socket on which <code>mod_ctrls</code> should listen. |
| 80 | This path should be in a place where <code>ftpdctl</code> users have |
| 81 | access to it, and should have read and write permissions. The |
| 82 | <code>ControlsSocketOwner</code> directive explicitly configures the |
| 83 | ownership the created Unix domain socket file should have. This means |
| 84 | that the configuration above: |
| 85 | <pre> |
| 86 | ControlsSocket /tmp/ctrls.sock |
| 87 | ControlsSocketOwner ftpd ftpd |
| 88 | </pre> |
| 89 | overrides the default location of the Unix domain socket, and tells |
| 90 | <code>mod_ctrls</code> to use <code>/tmp/ctrls.sock</code>, and to make |
| 91 | the socket owned by user <code>ftpd</code> and group <code>ftpd</code>. |
| 92 | The default ownership of the socket is user <code>root</code>, group |
| 93 | <code>root</code>. |
| 94 | |
| 95 | <p><a name="ACLs"></a> |
| 96 | <b>Controls Access Control Lists</b><br> |
| 97 | Communicating with the daemon process allows for some great features, but |
| 98 | it also allows the potential to easily abuse the system. Thus, by default, |
| 99 | all users <b>including user <code>root</code></b> are denied access to all |
| 100 | <code>ftpdctl</code> actions. <b>Access for control actions must be |
| 101 | explicitly granted.</b> Also, be aware that the users and groups configured |
| 102 | in these ACLs are <b>system</b> users and groups, not the virtual users |
| 103 | and groups that <code>proftpd</code> may have been configured to use. |
| 104 | The group will be only the primary group of the user; supplemental group |
| 105 | memberships are currently ignored. |
| 106 | |
| 107 | <p> |
| 108 | The <code>mod_ctrls</code> first checks whether the connecting client has |
| 109 | been granted the ability to use the Unix domain socket itself. This access |
| 110 | list is controlled by the <code>ControlsSocketACL</code> directive. By |
| 111 | default, every Controls client can use the socket. Thus, in the example |
| 112 | configuration above: |
| 113 | <pre> |
| 114 | ControlsSocketACL allow group ftpadm |
| 115 | </pre> |
| 116 | only the system group <code>ftpadm</code> would be allowed to send Controls |
| 117 | requests to the Unix domain socket; all other users and groups will be |
| 118 | denied. |
| 119 | |
| 120 | <p> |
| 121 | Next, ACLs on the specific control action requested by the connecting |
| 122 | client will be check. Most modules that use the Controls API will have their |
| 123 | own module-specific directives for setting ACLs on the specific actions |
| 124 | implemented by that module. For <code>mod_ctrls</code>, the |
| 125 | <code>ControlsACLs</code> configuration directive is used. In the |
| 126 | example configuration we see: |
| 127 | <pre> |
| 128 | ControlsACLs all allow group ftpadm |
| 129 | </pre> |
| 130 | which allows only the system group <code>ftpadm</code> to use all of the |
| 131 | control actions provided by <code>mod_ctrls</code>. If one wanted to |
| 132 | allow all users to use all of the control actions, it would be: |
| 133 | <pre> |
| 134 | ControlsACLs all allow user * |
| 135 | </pre> |
| 136 | However, if one wanted to specify separate ACLs for separate actions, then |
| 137 | the <code>ControlsACLs</code> directive would be used multiple times, like |
| 138 | so: |
| 139 | <pre> |
| 140 | ControlsACLs insctrl allow group wheel |
| 141 | ControlsACLs lsctrl allow user * |
| 142 | ControlsACLs rmctrl deny group ftp |
| 143 | </pre> |
| 144 | |
| 145 | <p> |
| 146 | Why is there such complexity for a simple client/server interaction? The |
| 147 | primary answer is that the running <code>proftpd</code> daemon has a lot of |
| 148 | privileges, and access to the running daemon should be strictly controlled. |
| 149 | Allow few people to have access via control actions; those few should be able |
| 150 | to use only the control actions necessary. |
| 151 | |
| 152 | <p> |
| 153 | <b>What Controls Do</b><br> |
| 154 | The <code>mod_ctrls</code> module provides basic control <em>actions</em>, |
| 155 | or commands that <code>ftpdctl</code> can send to the daemon: |
| 156 | <ul> |
| 157 | <li><code>help</code><br> |
| 158 | Lists all registered control actions and a brief description for each |
| 159 | </li> |
| 160 | |
| 161 | <p> |
| 162 | <li><code>insctrl</code><br> |
| 163 | Reenable a disabled control action |
| 164 | </li> |
| 165 | |
| 166 | <p> |
| 167 | <li><code>lsctrl</code><br> |
| 168 | Lists all enabled control actions and the modules providing them |
| 169 | </li> |
| 170 | |
| 171 | <p> |
| 172 | <li><code>rmctrl</code><br> |
| 173 | Disable a control action |
| 174 | </li> |
| 175 | </ul> |
| 176 | |
| 177 | <p> |
| 178 | <b>Denied Actions Versus Disabled Actions</b><br> |
| 179 | What is the difference between an action that has been denied via an ACL |
| 180 | versus an action that has been disabled using the <code>rmctrl</code> action? |
| 181 | A disabled action cannot be used by any client, regardless of any ACLs that |
| 182 | have been configured for that action. Thus if a system administrator |
| 183 | deemed that a particular control action should not be used by anyone, that |
| 184 | action can be disabled. The <code>rmctrl</code> action can disable <i>any</i> |
| 185 | action implemented by any module using the Controls API, not just actions |
| 186 | provided by <code>mod_ctrls</code>. Once disabled, a given action can be |
| 187 | re-enabled using the <code>insctrl</code> action. The <code>insctrl</code> |
| 188 | and <code>rmctrl</code> actions, in addition to <code>lsctrl</code>, cannot |
| 189 | themselves be disabled. For example, to disable an action called |
| 190 | <code>foo</code>: |
| 191 | <pre> |
| 192 | # ftpdctl rmctrl foo |
| 193 | ftpdctl: 'foo' control disabled |
| 194 | # ftpdctl lsctrl |
| 195 | ftpdctl: help (mod_ctrls.c) |
| 196 | ftpdctl: insctrl (mod_ctrls.c) |
| 197 | ftpdctl: lsctrl (mod_ctrls.c) |
| 198 | ftpdctl: rmctrl (mod_ctrls.c) |
| 199 | </pre> |
| 200 | Note that the <code>foo</code> action is not listed by <code>lsctrl</code>. |
| 201 | Now, re-enable that action: |
| 202 | <pre> |
| 203 | # ftpdctl insctrl foo |
| 204 | ftpdctl: 'foo' control enabled |
| 205 | # ftpdctl lsctrl |
| 206 | ftpdctl: foo (mod_foo.c) |
| 207 | ftpdctl: help (mod_ctrls.c) |
| 208 | ftpdctl: insctrl (mod_ctrls.c) |
| 209 | ftpdctl: lsctrl (mod_ctrls.c) |
| 210 | ftpdctl: permit (mod_ban.c) |
| 211 | ftpdctl: rmctrl (mod_ctrls.c) |
| 212 | </pre> |
| 213 | And now the <code>foo</code> action, provided by the module |
| 214 | <code>mod_foo.c</code>, appears in the <code>lsctrl</code> listing. |
| 215 | |
| 216 | <p> |
| 217 | The following shows an example of attempting to disable the <code>lsctrl</code> |
| 218 | action. It demonstrates the use of the <code>-v</code> command-line |
| 219 | option for <code>ftpdctl</code>, for showing a verbose interaction with |
| 220 | <code>mod_ctrls</code>: |
| 221 | <pre> |
| 222 | # ftpdctl -v lsctrl |
| 223 | ftpdctl: adding "lsctrl" to reqargv |
| 224 | ftpdctl: contacting server |
| 225 | ftpdctl: sending control request |
| 226 | ftpdctl: receiving control response |
| 227 | ftpdctl: debug (mod_ctrls_admin.c) |
| 228 | ... |
| 229 | |
| 230 | # ftpdctl rmctrl lsctrl |
| 231 | |
| 232 | # ftpdctl -v lsctrl |
| 233 | ftpdctl: adding "lsctrl" to reqargv |
| 234 | ftpdctl: contacting server |
| 235 | ftpdctl: sending control request |
| 236 | ftpdctl: receiving control response |
| 237 | ftpdctl: access denied |
| 238 | </pre> |
| 239 | The "access denied" message happens because of the special status |
| 240 | of the <code>lsctrl</code> action which keeps it from being disablable. |
| 241 | |
| 242 | <p> |
| 243 | <b>Admin Controls</b><br> |
| 244 | The <code>mod_ctrls</code> module, by itself, is rather unexciting. Other |
| 245 | modules, such as <code>mod_ctrls_admin</code>, provide more interesting |
| 246 | and useful control actions, including: |
| 247 | <ul> |
| 248 | <li><code>debug</code> |
| 249 | <li><code>dump</code> |
| 250 | <li><code>kick</code> |
| 251 | <li><code>restart</code> |
| 252 | <li><code>shutdown</code> |
| 253 | <li><code>start</code> |
| 254 | <li><code>status</code> |
| 255 | <li><code>stop</code> |
| 256 | <li><code>trace</code> |
| 257 | </ul> |
| 258 | These actions provide basic administrative control over the running |
| 259 | <code>proftpd</code> daemon; see the <code>mod_ctrls_admin</code> |
| 260 | <a href="../contrib/mod_ctrls_admin.html">documentation</a> for more details. |
| 261 | |
| 262 | <p> |
| 263 | A basic <code>mod_ctrls_admin</code> configuration is: |
| 264 | <pre> |
| 265 | <IfModule mod_ctrls_admin.c> |
| 266 | AdminControlsACLs all allow user * |
| 267 | </IfModule> |
| 268 | </pre> |
| 269 | will allows anyone to use any <code>mod_ctrls_admin</code> control action. |
| 270 | |
| 271 | <p> |
| 272 | Here is another configuration, encompassing both <code>mod_ctrls</code> |
| 273 | and <code>mod_ctrls_admin</code>: |
| 274 | <pre> |
| 275 | <IfModule mod_ctrls.c> |
| 276 | ControlsEngine on |
| 277 | ControlsACLs all allow group ftpadm |
| 278 | ControlsMaxClients 2 |
| 279 | ControlsLog /var/log/proftpd/controls.log |
| 280 | ControlsInterval 5 |
| 281 | ControlsSocketACL allow group ftpadm |
| 282 | ControlsSocket /tmp/ctrls.sock |
| 283 | ControlsSocketOwner ftpd ftpd |
| 284 | |
| 285 | <IfModule mod_ctrls_admin.c> |
| 286 | AdminControlsACLs all allow user dave,bob,lisa |
| 287 | </IfModule> |
| 288 | </IfModule> |
| 289 | </pre> |
| 290 | In this configuration, users <code>dave</code>, <code>bob</code>, and |
| 291 | <code>lisa</code> are allowed to use all of the control actions supplied |
| 292 | by <code>mod_ctrls_admin</code>. However, unless these users are members |
| 293 | of group <code>ftpadm</code>, access will be denied. Only group |
| 294 | <code>ftpadm</code> has been allowed access to the <code>mod_ctrls</code> |
| 295 | socket itself by the <code>ControlsSocketACL</code> directive. |
| 296 | |
| 297 | <p> |
| 298 | What about configuring an ACL for a given control that includes both |
| 299 | users <i>and</i> groups? Use: |
| 300 | <pre> |
| 301 | AdminControlsACLs restart allow user dave,lisa |
| 302 | AdminControlsACLs restart allow group ftpadm |
| 303 | </pre> |
| 304 | What if user <code>dave</code> is not a member of group <code>ftpadm</code>? |
| 305 | If configured, <b>both</b> user <b>and</b> group ACLs must deny the client. |
| 306 | If either allows access, the client can use that control action. |
| 307 | |
| 308 | <p> |
| 309 | <hr> |
| 310 | <font size=2><b><i> |
| 311 | © Copyright 2017-2019 The ProFTPD Project<br> |
| 312 | All Rights Reserved<br> |
| 313 | </i></b></font> |
| 314 | <hr> |
| 315 | |
| 316 | </body> |
| 317 | </html> |