-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_amqp.html
619 lines (528 loc) · 17.6 KB
/
mod_amqp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
<!DOCTYPE html>
<html>
<head>
<title>ProFTPD module mod_amqp</title>
</head>
<body bgcolor=white>
<hr>
<center>
<h2><b>ProFTPD module <code>mod_amqp</code></b></h2>
</center>
<hr><br>
<p>
The <code>mod_amqp</code> module enables ProFTPD support for sending log
messages, as JSON, to AMQP brokers such as
<a href="http://www.rabbitmq.com/">RabbitMQ</a>, using the
<a href="https://github.com/alanxz/rabbitmq-c">rabbitmq-c</a> client library.
<p>
This module is contained in the <code>mod_amqp</code> files for
ProFTPD 1.3.<i>x</i>, and is not compiled by default. Installation
instructions are discussed <a href="#Installation">here</a>. More examples
of <code>mod_amqp</code> usage can be found <a href="#Usage">here</a>.
<p>
The most current version of <code>mod_amqp</code> can be found at:
<pre>
<a href="https://github.com/Castaglia/proftpd-mod_amqp">https://github.com/Castaglia/proftpd-mod_amqp</a>
</pre>
<h2>Author</h2>
<p>
Please contact TJ Saunders <tj <i>at</i> castaglia.org> with any
questions, concerns, or suggestions regarding this module.
<h2>Directives</h2>
<ul>
<li><a href="#AMQPApplicationID">AMQPApplicationID</a>
<li><a href="#AMQPEngine">AMQPEngine</a>
<li><a href="#AMQPLog">AMQPLog</a>
<li><a href="#AMQPLogOnEvent">AMQPLogOnEvent</a>
<li><a href="#AMQMessageExpires">AMQPMessageExpires</a>
<li><a href="#AMQMessageType">AMQPMessageType</a>
<li><a href="#AMQPOptions">AMQPOptions</a>
<li><a href="#AMQPServer">AMQPServer</a>
<li><a href="#AMQPTimeout">AMQPTimeout</a>
</ul>
<p>
<hr>
<h3><a name="AMQPApplicationID">AMQPApplicationID</a></h3>
<strong>Syntax:</strong> AMQPApplicationID <em>name</em><br>
<strong>Default:</strong> AMQPApplicationID proftpd<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>mod_amqp</code> module automatically sets the <code>app_id</code>
property to "proftpd" on each message published. Use the
<code>AMQPApplicationID</code> directive to specify a different value to use,
<i>e.g.</i>:
<pre>
AMQPApplicationID mod_amqp
</pre>
<p>
<hr>
<h3><a name="AMQPEngine">AMQPEngine</a></h3>
<strong>Syntax:</strong> AMQPEngine <em>on|off</em><br>
<strong>Default:</strong> AMQPEngine off<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>AMQPEngine</code> directive enables or disables the
<code>mod_amqp</code> module, and thus the configuration of AMQP support for
the <code>proftpd</code> daemon.
<p>
<hr>
<h3><a name="AMQPLog">AMQPLog</a></h3>
<strong>Syntax:</strong> AMQPLog <em>path|"none"</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>AMQPLog</code> directive is used to specify a log file for
<code>mod_amqp</code>'s reporting on a per-server basis. The
<em>file</em> parameter given must be the full path to the file to use for
logging.
<p>
Note that this path must <b>not</b> be to a world-writable directory and,
unless <code>AllowLogSymlinks</code> is explicitly set to <em>on</em>
(generally a bad idea), the path must <b>not</b> be a symbolic link.
<p>
<hr>
<h3><a name="AMQPLogOnEvent">AMQPLogOnEvent</a></h3>
<strong>Syntax:</strong> AMQPLogOnEvent <em>"none"|events format-name [exchange ...] [routing ...]</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code>, <code><Anonymous></code>, <code><Directory></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.7rc1 and later
<p>
The <code>AMQPLogOnEvent</code> directive configures the use of AMQP for
<em>logging</em>. Whenever one of the comma-separated list of <em>events</em>
occurs, <code>mod_amqp</code> will compose a JSON object, using the
<a href="http://www.proftpd.org/docs/modules/mod_log.html#LogFormat"><code>LogFormat</code></a> named by
<em>format-name</em> as a <i>template</i> for the fields to include in the
JSON object. The JSON object of that event will then be published to an
AMQP <em>exchange</em> with the <em>routing</em> key. Multiple
<code>AMQPLogOnEvent</code> directives can be used, for different log formats
for different events.
<p>
The optional <em>exchange</em> parameter, if present, specifies the value to use
as the exchange name. This <em>exchange</em> parameter supports all of the
<code>LogFormat</code> variables, thus you can use <i>e.g.</i>:
<pre>
LogFormat amqp ...
AMQPLogOnEvent READ amqp exchange ftp.download.%u.%m:%f
</pre>
If the exchange name is not provided explicitly, the default exchange of the
AMQP broker is used.
<p>
The optional <em>routing</em> parameter, if present, specifies the value to use
as the routing key. This <em>routing</em> parameter supports all of the
<code>LogFormat</code> variables, thus you can use <i>e.g.</i>:
<pre>
LogFormat amqp ...
AMQPLogOnEvent READ amqp routing ftp.download.%u.%m:%f
</pre>
If the routing key is not provided explicitly, the configured
<em>format-name</em> is used.
<p>
More on the use of AMQP logging, including a table showing how
<code>LogFormat</code> variables are mapped to JSON object keys can be found
<a href="#Logging">here</a>.
<p>
Example:
<pre>
LogFormat sessions "%{iso8601} %a"
AMQPLogOnEvent CONNECT,DISCONNECT sessions
</pre>
<p>
In addition to specific FTP commands, the <em>events</em> list can specify
"ALL", for logging on <b>all</b> commands. Or it can <i>include</i> the
"CONNECT" and "DISCONNECT" <i>events</i>, which can be useful for logging the
start and end times of a session. <b>Note</b> that
<code>AMQPLogOnEvent</code> <i>does</i> support the logging <i>classes</i>
that the <code>ExtendedLog</code> directive supports.
<p>
<hr>
<h3><a name="AMQPMessageExpires">AMQPMessageExpires</a></h3>
<strong>Syntax:</strong> AMQPMessageExpires <em>ttl</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
<hr>
<h3><a name="AMQPMessageType">AMQPMessageType</a></h3>
<strong>Syntax:</strong> AMQPMessageType <em>type</em><br>
<strong>Default:</strong> AMQPMessageType log<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>mod_amqp</code> module automatically sets the <code>type</code>
property to "log" on each message published. Use the
<code>AMQPMessageType</code> directive to specify a different value to use,
<i>e.g.</i>:
<pre>
AMQPMessageType ftpd
</pre>
<p>
<hr>
<h3><a name="AMQPOptions">AMQPOptions</a></h3>
<strong>Syntax:</strong> AMQPOptions <em>opt1 ...</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.7rc1 and later
<p>
The <code>AMQPOptions</code> directive is used to configure various optional
behavior of <code>mod_amqp</code>.
<p>
Example:
<pre>
AMQPOptions PersistentDelivery
</pre>
<p>
The currently implemented options are:
<ul>
<li><code>PersistentDelivery</code><br>
<p>
Use this option to set the per-message deivery mode to "persistent",
which tells the AMQP broker to persist the message.
</li>
</ul>
<p>
<hr>
<h3><a name="AMQPServer">AMQPServer</a></h3>
<strong>Syntax:</strong> AMQPServer <em>host[:port] [vhost] [username] [password] [ssl-cert:...] [ssl-key:...] [ssl-ca:...] [ssl-verify:...] [ssl-verify-hostname:...] [ssl-verify-peer:...]</em><br>
<strong>Default:</strong> None<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>AMQPServer</code> directive is used to configure the IP address/port
of the AMQP broker that the <code>mod_amqp</code> module is to use. For
example:
<pre>
AMQPServer 1.2.3.4:5672
</pre>
or, for an IPv6 address, make sure the IPv6 address is enclosed in square
brackets:
<pre>
AMQPServer [::ffff:1.2.3.4]:5672
</pre>
<p>
The optional <em>vhost</em> parameter indicates which AMQP virtual host
should be used when <code>mod_amqp</code> logs into the AMQP server. If not
provided, a <em>vhost</em> value of "/" is used.
<p>
The optional <em>username</em> parameter indicates which username should be
used when <code>mod_amqp</code> logs into the AMQP server. If not
provided, a <em>username</em> value of "guest" is used.
<p>
The optional <em>password</em> parameter indicates which password should be
used when <code>mod_amqp</code> logs into the AMQP server. If not
provided, a <em>password</em> value of "guest" is used.
<p>
Example of using non-default login information:
<pre>
AMQPServer rabbit.example.com:55672 /myhost amqp passwd
</pre>
<p>
It is possible to configure SSL/TLS parameters for a given connection, which
tells <code>mod_amqp</code> to try to open an SSL session with the AMQP server.
Most of the time, all that is needed for the SSL session is the CA
(Certificate Authority) to use, for verifying the certificate presented by the
server. Thus:
<pre>
AMQPServer rabbit.example.com:5671 ... ssl-ca:/path/to/cacert.pem
</pre>
If your server is configured to require SSL/TLS mutual authentication
(also called "client auth"), you may need the <code>ssl-cert:</code> and
<code>ssl-key:</code> parameters as well:
<pre>
AMQPServer rabbit.example.com:5671 ... ssl-ca:/path/to/cacert.pem \
ssl-cert:/path/to/client-cert.pem \
ssl-key:/path/to/client-key.pem
</pre>
Finally, for testing purposes, you can tell <code>mod_amqp</code> to
<b>not</b> verify the AMQP server, like so:
<pre>
AMQPServer rabbit.example.com:5671 ... ssl-verify:false \
ssl-verify-hostname:false \
ssl-verify-peer:false
</pre>
This is <b>not recommended</b>, as it leaves the connection with the AMQP
server open to <i>man-in-the-middle</i> (MITM) attacks.
<p>
<hr>
<h3><a name="AMQPTimeout">AMQPTimeout</a></h3>
<strong>Syntax:</strong> AMQPTimeout <em>connect-milliseconds</em><br>
<strong>Default:</strong> 2000<br>
<strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br>
<strong>Module:</strong> mod_amqp<br>
<strong>Compatibility:</strong> 1.3.6rc5 and later
<p>
The <code>AMQPTimeout</code> directive configures the maximum number of
milliseconds for <code>mod_amqp</code> to connect to the
<a href="#AMQPServer"><code>AMQPServer</code></a>. The default is 2000ms
(2 seconds).
<p>
<hr>
<h2><a name="Installation">Installation</a></h2>
To install <code>mod_amqp</code>, copy the <code>mod_amqp</code> files into:
<pre>
<i>proftpd-dir</i>/contrib/
</pre>
after unpacking the latest proftpd-1.3.<i>x</i> source code. For including
<code>mod_amqp</code> as a staticly linked module:
<pre>
$ ./configure --with-modules=mod_amqp
</pre>
To build <code>mod_amqp</code> as a DSO module:
<pre>
$ ./configure --enable-dso --with-shared=mod_amqp
</pre>
Then follow the usual steps:
<pre>
$ make
$ make install
</pre>
<p>
You may also need to tell <code>configure</code> how to find the
<code>librabbitmq</code> header and library files:
<pre>
$ ./configure --with-modules=mod_amqp \
--with-includes=<i>/path/to/librabbitmq/include</i> \
--with-libraries=<i>/path/to/librabbitmq/lib</i>
</pre>
<p>
<hr>
<h2><a name="Usage">Usage</a></h2>
<p>
This example shows the use of AMQP logging for <em>all</em> commands:
<pre>
<IfModule mod_amqp.c>
AMQPEngine on
AMQPLog /var/log/ftpd/amqp.log
AMQPServer 127.0.0.1:5672
LogFormat amqp "%h %l %u %t \"%r\" %s %b"
AMQPLogOnEvent ALL amqp
</IfModule>
</pre>
<p><a name="Logging"></a>
<b>AMQP Logging</b><br>
When using AMQP logging, the following table shows how <code>mod_amqp</code>
converts a <code>LogFormat</code> variable into the key names in the JSON
logging objects:
<table border=1 summary="AMQP LogFormat Variables">
<tr>
<td><b><code>LogFormat</code> Variable</b></td>
<td><b>Key</b></td>
</tr>
<tr>
<td> <code>%A</code> </td>
<td>anon_password</td>
</tr>
<tr>
<td> <code>%a</code> </td>
<td>remote_ip</td>
</tr>
<tr>
<td> <code>%b</code> </td>
<td>bytes_sent</td>
</tr>
<tr>
<td> <code>%c</code> </td>
<td>connection_class</td>
</tr>
<tr>
<td> <code>%D</code> </td>
<td>dir_path</td>
</tr>
<tr>
<td> <code>%d</code> </td>
<td>dir_name</td>
</tr>
<tr>
<td> <code>%E</code> </td>
<td>session_end_reason</td>
</tr>
<tr>
<td> <code>%{epoch}</code> </td>
<td>Unix timestamp, in seconds since Jan 1 1970.</td>
</tr>
<tr>
<td> <code>%{<em>name</em>}e</code> </td>
<td>ENV:<em>name</em></td>
</tr>
<tr>
<td> <code>%F</code> </td>
<td>transfer_path</td>
</tr>
<tr>
<td> <code>%f</code> </td>
<td>file</td>
</tr>
<tr>
<td> <code>%{file-modified}</code> </td>
<td>file_modified</td>
</tr>
<tr>
<td> <code>%g</code> </td>
<td>group</td>
</tr>
<tr>
<td> <code>%{gid}</code> </td>
<td>gid</td>
</tr>
<tr>
<td> <code>%H</code> </td>
<td>server_ip</td>
</tr>
<tr>
<td> <code>%h</code> </td>
<td>remote_dns</td>
</tr>
<tr>
<td> <code>%I</code> </td>
<td>session_bytes_rcvd</td>
</tr>
<tr>
<td> <code>%{iso8601}</code> </td>
<td>timestamp</td>
</tr>
<tr>
<td> <code>%J</code> </td>
<td>command_params</td>
</tr>
<tr>
<td> <code>%L</code> </td>
<td>local_ip</td>
</tr>
<tr>
<td> <code>%l</code> </td>
<td>identd_user</td>
</tr>
<tr>
<td> <code>%m</code> </td>
<td>command</td>
</tr>
<tr>
<td> <code>%{microsecs}</code> </td>
<td>microsecs</td>
</tr>
<tr>
<td> <code>%{millisecs}</code> </td>
<td>millisecs</td>
</tr>
<tr>
<td> <code>%{note:<em>name</em>}</code> </td>
<td>NOTE:<em>name</em></td>
</tr>
<tr>
<td> <code>%O</code> </td>
<td>session_bytes_sent</td>
</tr>
<tr>
<td> <code>%P</code> </td>
<td>pid</td>
</tr>
<tr>
<td> <code>%p</code> </td>
<td>local_port</td>
</tr>
<tr>
<td> <code>%{protocol}</code> </td>
<td>protocol</td>
</tr>
<tr>
<td> <code>%r</code> </td>
<td>raw_command</td>
</tr>
<tr>
<td> <code>%S</code> </td>
<td>response_msg</td>
</tr>
<tr>
<td> <code>%s</code> </td>
<td>response_code</td>
</tr>
<tr>
<td> <code>%T</code> </td>
<td>transfer_secs</td>
</tr>
<tr>
<td> <code>%t</code> </td>
<td>local_time</td>
</tr>
<tr>
<td> <code>%{transfer-failure}</code> </td>
<td>transfer_failure</td>
</tr>
<tr>
<td> <code>%{transfer-status}</code> </td>
<td>transfer_status</td>
</tr>
<tr>
<td> <code>%U</code> </td>
<td>original_user</td>
</tr>
<tr>
<td> <code>%u</code> </td>
<td>user</td>
</tr>
<tr>
<td> <code>%{uid}</code> </td>
<td>uid</td>
</tr>
<tr>
<td> <code>%V</code> </td>
<td>server_dns</td>
</tr>
<tr>
<td> <code>%v</code> </td>
<td>server_name</td>
</tr>
<tr>
<td> <code>%{version}</code> </td>
<td>server_version</td>
</tr>
<tr>
<td> <code>%w</code> </td>
<td>rename_from</td>
</tr>
</table>
<p>
In addition to the standard <code>LogFormat</code> variables, the
<code>mod_amqp</code> module also adds a "connecting" key for events
generated when a client first connects, and a "disconnecting" key for events
generated when a client disconnects. These keys can be used for determining
the start/finish events for a given session.
<p>
Here is an example of the JSON-formatted records generated, using the above
example configuration:
<pre>
{"connecting":true,"timestamp":"2013-08-21 23:08:22,171"}
{"command":"USER","timestamp":"2013-08-21 23:08:22,278"}
{"user":"proftpd","command":"PASS","timestamp":"2013-08-21 23:08:22,305"}
{"user":"proftpd","command":"PASV","timestamp":"2013-08-21 23:08:22,317"}
{"user":"proftpd","command":"LIST","bytes_sent":432,"transfer_secs":4.211,"timestamp":"2013-08-21 23:08:22,329"}
{"user":"proftpd","command":"QUIT","timestamp":"2013-08-21 23:08:22,336"}
{"disconnecting":true,"user":"proftpd","timestamp":"2013-08-21 23:08:22,348"}
</pre>
Notice that for a given event, not <i>all</i> of the <code>LogFormat</code>
variables are filled in. If <code>mod_amqp</code> determines that a given
<code>LogFormat</code> variable has no value for the logged event, it will
simply omit that variable from the JSON object.
<p>
Another thing to notice is that the generated JSON object ignores the textual
delimiters configured by the <code>LogFormat</code> directive; all that
matters are the <code>LogFormat</code> variables which appear in the directive.
<p>
<hr>
<font size=2><b><i>
© Copyright 2017-2022 TJ Saunders<br>
All Rights Reserved<br>
</i></b></font>
<hr>
</body>
</html>