Debian Codegraph @

doc/sources/admin/logs.rst

raw
1 Logs
2 ====
3
4 Presentation
5 ------------
6
7 Main settings:
8
9 - **REMOTE_USER**: session attribute used for logging user access
10 - **REMOTE_CUSTOM**: can be used for logging an another user attribute or a macro
11 (optional)
12 - **Hidden attributes**: session attributes never displayed or sent.
13
14 .. versionchanged:: 2.17.0
15
16 Since version 2.17.0 hidden attributes parameter supports regular expressions.
17 You can hide attributes by listing them or by providing one or more regexps.
18 By example: ``_password, _session_id, /^notification_/ /^real\d+$/ _oidcConsents``
19
20 .. attention::
21
22 Regexp must start and end with a slash ``/`` character.
23
24 LemonLDAP::NG provides 5 levels of error and has two kinds of logs:
25
26 - technical logs
27 - user actions logs
28
29 Each category can be handle by a different logging framework. You can
30 choose between:
31
32 - **Lemonldap::NG::Common::Logger::Std**: standard output (mapped in
33 web server logs, see below)
34 - **Lemonldap::NG::Common::Logger::Syslog**: syslog logging
35 - **Lemonldap::NG::Common::Logger::Apache2**: use Apache2 logging,
36 levels are stored in Apache2 logs and the log level is defined by
37 ``LogLevel`` Apache parameter
38 - **Lemonldap::NG::Common::Logger::Log4perl**: use ``Log4perl``
39 framework to log *(inspired by Java Log4J)*
40 - **Lemonldap::NG::Common::Logger::Loki**: push logs into a
41 `Loki server <https://github.com/grafana/loki#readme>`__
42 - **Lemonldap::NG::Common::Logger::Sentry (experimental)**: use
43 `Sentry <https://sentry.io>`__ to store logs
44 - **Lemonldap::NG::Common::Logger::Dispatch**: dispatch logs in other
45 backends depending on log level
46
47
48 .. attention::
49
50 Except for Apache2 and Log4Perl, log level is defined
51 by ``logLevel`` parameter set in ``lemonldap-ng.ini`` file. Logger
52 configurations are defined in lemonldap-ng.ini. Example:
53
54 .. code-block:: ini
55
56 [all]
57 logger = Lemonldap::NG::Common::Logger::Log4perl
58 userLogger = Lemonldap::NG::Common::Logger::Syslog
59 logLevel = notice
60
61 You can also modify these values in each lemonldap-ng.ini section to
62 have different values for portal, manager and handlers.
63
64 Therefore, LLNG provides a username that can be used by web servers in
65 their access logs. To configure the user identifier to write into access
66 logs, go to Manager, ``General Parameters`` > ``Logging`` >
67 ``REMOTE_USER``.
68
69 User log samples
70 ----------------
71
72 .. note::
73
74 The user name set in user log messages is set with `whatToTrace` parameter, except
75 for messages corresponding to failed authentifications, when the user name logged is the
76 login used by the user.
77
78 Authentication:
79
80 ::
81
82 [info] User dwho successfully authenticated at level 2
83 [info] User dwho connected from LDAP (81.20.13.21)
84
85 Failed authentication:
86
87 ::
88
89 [warn] foo.bar was not found in LDAP directory (81.20.13.21)
90 [warn] Bad password for dwho (81.20.13.21)
91
92 Failed authentication with Combination module:
93
94 ::
95
96 [warn] All schemes failed for user dwho (81.20.13.21)
97
98 Logout:
99
100 ::
101
102 [notice] User dwho has been disconnected from LDAP (81.20.13.21)
103
104 Password change:
105
106 ::
107
108 [notice] Password changed for dwho (81.20.13.21)
109
110 Access to a CAS application non registered in configuration (when CAS server is open):
111
112 ::
113
114 [notice] User dwho is redirected to https://cas.service.url
115
116 Access to a CAS application whose configuration key is ``app-example``:
117
118 ::
119
120 [notice] User dwho is authorized to access to app-example
121
122 Access to an SAML SP whose configuration key is ``sp-example``:
123
124 ::
125
126 [notice] User dwho is authorized to access to sp-example
127
128 Access to an OIDC RP whose configuration key is ``rp-example``:
129
130 ::
131
132 [notice] User dwho is authorized to access to rp-example
133
134 Access to a Get application whose vhost configuration key is ``host.example.com``:
135
136 ::
137
138 [notice] User dwho is authorized to access to host.example.com
139
140
141 Default loggers
142 ---------------
143
144 - Apache handlers use by default Apache2 logger. This logger can not be
145 used for other LLNG components
146 - Except when launched by LLNG FastCGI server *(used by Nginx)*, Portal
147 and Manager use Std logger by default
148 - All components launched by LLNG FastCGI server use Syslog by default
149
150 Log levels
151 ----------
152
153 Technical log levels
154 ~~~~~~~~~~~~~~~~~~~~
155
156 - **error** is used for problems that must be reported to administrator
157 and needs an action. In this case, some features may not work
158 - **warn** is used for problems that do not block LLNG features but
159 should be solved
160 - **notice** is used for actions that must be logged
161 - **info** displays some technical information
162 - **debug** generates lot of debugging logs
163
164 Log levels for user actions
165 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
166
167 - **error** is used for logging bad user actions that seem malicious
168 - **warn** is used for logging some errors like "bad password"
169 - **notice** is used for actions that must be logged for
170 accounting (connections, logout and so on)
171 - **info** displays some useful information like handler authorizations
172 (at least one for each HTTP hit)
173 - **debug** not relevant
174
175 Logger configuration
176 --------------------
177
178 Std logger
179 ~~~~~~~~~~
180
181 Nothing to configure except logLevel.
182
183 Apache2 logger
184 ~~~~~~~~~~~~~~
185
186 The log level can be set with Apache ``LogLevel`` parameter. It can be
187 configured globally, or inside a virtual host.
188
189 See http://httpd.apache.org/docs/current/mod/core.html#loglevel for more
190 information.
191
192 Syslog
193 ~~~~~~
194
195 You can choose facility in lemonldap-ng.ini file. Default values:
196
197 .. code-block:: ini
198
199 syslogFacility = daemon
200 userSyslogFacility = auth
201
202 You can also override options. Default values:
203
204 .. code-block:: ini
205
206 syslogOptions = cons,pid,ndelay
207 userSyslogOptions = cons,pid,ndelay
208
209
210 .. tip:: You can find more information on Syslog options in
211 `Sys::Syslog <https://metacpan.org/pod/Sys::Syslog>`__ Perl
212 module.
213
214 And you can add additional options. Example to send log to another host:
215
216 .. code-block:: ini
217
218 syslogSockOptions = { host => "remote.com", port => 6514 }
219
220 See `setlogsock() <https://metacpan.org/pod/Sys::Syslog#setlogsock()>`_ for more.
221
222 Log4perl
223 ~~~~~~~~
224
225 You can define the Log4perl configuration file and classes to use.
226 Default values:
227
228 .. code-block:: ini
229
230 log4perlConfFile = /etc/log4perl.conf
231 log4perlLogger = LLNG
232 log4perlUserLogger = LLNGuser
233
234
235 Sample ``log4perl.conf`` file
236
237 .. code::
238
239 log4perl.logger.LLNG = DEBUG, Syslog
240 log4perl.logger.LLNGuser = INFO, Syslog
241 log4perl.appender.Syslog = Log::Dispatch::Syslog
242 log4perl.appender.Syslog.ident = LLNG
243 log4perl.appender.Syslog.layout = PatternLayout
244 log4perl.appender.Syslog.layout.ConversionPattern = [%p] %m
245
246 For additional information, please read the `Log4Perl documentation <https://metacpan.org/pod/Log::Log4perl>`__
247
248 .. versionadded:: 2.0.14
249
250 The following special formatters have been added to standard `PatternLayout placeholders <https://metacpan.org/pod/Log::Log4perl::Layout::PatternLayout>`__
251
252 * ``%Q{address}``: IP address of the request
253 * ``%Q{user}``: Username of the current user
254 * ``%Q{id}``: Session ID of the current user
255 * ``%E{ENV_VAR}``: content of the ``ENV_VAR`` variable
256
257 .. versionadded:: 2.17
258
259 * ``%S{mail}``: content of the ``mail`` session variable
260
261 .. versionadded:: 2.19
262
263 * ``%Q{request_id}``: Unique request ID, from ``UNIQUE_ID`` environment
264 variable, or generated by LemonLDAP::NG if ``UNIQUE_ID`` is not found.
265
266
267 .. versionadded:: 2.21.0
268
269 Loki
270 ~~~~
271
272 Here are the configuration parameters with their default values:
273
274 ===================== ================================================================================================================================================= ==========================================
275 Parameter Comment Default value
276 ===================== ================================================================================================================================================= ==========================================
277 ``lokiUrl`` URL of Loki API ``http://localhost:3100/loki/api/v1/push``
278 ``lokiLabel`` Value of ``label`` field ``llng``
279 ``lokiInstance`` Value of ``instance`` field *(hostname command result)*
280 ``lokiEnv`` Value of ``env`` field ``prod``
281 ``lokiService`` Value of "service" when used as technical logger ``llng``
282 ``lokiUserService`` Value of "service" when used as userLogger ``auth``
283 ``lokiTenant`` Used to populate ``X-Scope-OrgID`` header
284 ``lokiTenantHeader`` Used to change default tenant header ``X-Scope-OrgID``
285 ``lokiAuthorization`` Set here the whole value to put in the ``Authorization`` header. For example: ``Basic dXNlcjpwYXNzd29yZA==`` *(Base64 encoding of user:password)*
286 ``lokiDeferDir`` Temporary directory to store logs (see :ref:`async options <async-opts>`)
287 ``lokiProxy`` Buffer-Proxy to be used (see :ref:`async options <async-opts>`)
288 ===================== ================================================================================================================================================= ==========================================
289
290 Is it recommended to combine this logger with the :ref:`auditLogger <auditlogs>`
291 "``Lemonldap::NG::Common::AuditLogger::UserLoggerJSON``" to have useful logs
292 for Grafana. Example of ``lemonldap-ng.ini`` file:
293
294 .. code-block:: ini
295
296 [ all ]
297 logger = Lemonldap::NG::Common::Logger::Loki
298 auditLogger = Lemonldap::NG::Common::AuditLogger::UserLoggerJSON
299 lokiUrl = http://10.1.2.3/loki/api/v1/push
300
301
302 .. _async-opts:
303
304 Async options
305 ^^^^^^^^^^^^^
306
307 .. attention::
308
309 This logger uses synchronous process, so it can cause latency in
310 heavily loaded systems. To avoid this, you can use an asynchronous
311 mechanism.
312
313 LLNG proposes 2 options:
314
315 * use a :ref:`transitional directory to store logs formated for Loki<lokideferdir>`.
316
317 * use a :ref:`reverse-proxy that will bufferize messages<lokiproxy>`.
318
319 .. _lokideferdir:
320
321 **Using a transitional directory**
322 """"""""""""""""""""""""""""""""""
323
324 When option ``lokiDeferDir`` is set, the Loki logger no more send directly logs
325 to Loki API but write them into this transitional directory. You can use the
326 `lokiSender <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/-/blob/v2.0/lemonldap-ng-common/eg/lokiSender>`_
327 program to pick logs from the transitional directory and push then to Loki
328 API. It can be used as daemon or as cron task.
329
330 .. _lokiproxy:
331
332 **Using a custom reverse-proxy**
333 """"""""""""""""""""""""""""""""
334
335 When using ``lokiProxy`` optiion, Loki logger simply send Loki requests to this
336 URL instead of using ``lokiUrl`` value but keeps ``Host`` header. This permits
337 one to write a simple proxy, faster than loki API which will group message to
338 send them asynchronously.
339
340 Sentry
341 ~~~~~~
342
343 You just have to give your DSN:
344
345 .. code-block:: ini
346
347 sentryDsn = https://...
348
349
350 .. attention::
351
352 This experimental logger requires
353 `Sentry::Raven <https://metacpan.org/pod/Sentry::Raven>`__ Perl
354 module.
355
356 Dispatch
357 ~~~~~~~~
358
359 Use it to enable more than one logger. Example:
360
361 .. code-block:: ini
362
363 logger = Lemonldap::NG::Common::Logger::Dispatch
364 userLogger = Lemonldap::NG::Common::Logger::Dispatch
365 logDispatchError = Lemonldap::NG::Common::Logger::Sentry
366 logDispatchNotice = Lemonldap::NG::Common::Logger::Syslog
367 userLogDispatchError = Lemonldap::NG::Common::Logger::Sentry
368 ; Other parameters
369 syslogFacility = daemon
370 sentryDsn = https://...
371
372
373 .. attention::
374
375 At least ``logDispatchError`` (or ``userLogDispatchError`` for user logs)
376 must be defined. All sub level will be dispatched on it,
377 until another lever is declared. In the above example,
378 Sentry collects ``error`` and ``warn`` levels and all user
379 actions, while syslog stores technical ``notice``, ``info`` and ``debug`` logs.
380
381 .. _auditlogs:
382
383 Audit logs
384 ----------
385
386 .. versionadded:: 2.19
387
388 |beta| This feature may change in a future version, event codes and format should not be considered stable.
389
390 LemonLDAP::NG user logs (see above) are being replaced with a new facility: :ref:`auditlogs`.
391
392 Audit logs are structured logs that are meant to be easier to process than the current log messages.
393
394 At the moment, audit logs are transmitted by default to the configured
395 ``userLogger``. But you can plug-in your own custom implementation.
396
397 .. code:: ini
398
399 auditLogger=My::Logger::Class
400
401 Your logger class can look something like this:
402
403 .. code:: perl
404
405 package My::Logger::Class;
406 use Scalar::Util qw(weaken);
407
408 sub new {
409 my ( $class, $psgi_or_handler ) = @_;
410 my $self = bless {}, $class;
411
412 # Populate $self with options read from $psgi_or_handler
413 # ...
414
415 return $self;
416 }
417
418 sub log {
419 my ( $self, $req, %fields ) = @_;
420
421 # Your logging actions here. %fields is the structured
422 # data from the logging context, which you can enrich with
423 # data from the HTTP request ($req).
424 # The "code" field generally contains an upper case event code such as
425 # AUTHENTICATED or 2FA_REQUIRED
426
427 # my $code = $fields{code};
428 # ...
429 };
430
431 1;
432
433 .. |beta| image:: /documentation/beta.png