Skip to content

Commit 3f1fec1

Browse files
[Docs] audit logfile structured format (#34584)
Documents the new structured logfile format for auditing that was introduced by #31931. Most changes herein are for 6.x . In 7.0 the deprecated format is gone and a follow-up PR is in order.
1 parent c42f350 commit 3f1fec1

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

docs/reference/settings/audit-settings.asciidoc

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ Set to `true` to enable auditing on the node. The default value is `false`.
1818
`xpack.security.audit.outputs`::
1919
Specifies where audit logs are output. For example: `[ index, logfile ]`. The
2020
default value is `logfile`, which puts the auditing events in a dedicated
21-
`<clustername>_access.log` file on the node. You can also specify `index`, which
22-
puts the auditing events in an {es} index that is prefixed with
23-
`.security_audit_log`. The index can reside on the same cluster or a separate
24-
cluster.
21+
file named `<clustername>_audit.log` on each node.
22+
You can also specify `index`, which puts the auditing events in an {es} index
23+
that is prefixed with `.security_audit_log`. The index can reside on the same
24+
cluster or a separate cluster.
25+
26+
For backwards compatibility reasons, if you use the logfile output type, a
27+
`<clustername>_access.log` file is also created. It contains the same
28+
information, but it uses the older (pre-6.5.0) formatting style.
29+
If the backwards compatible format is not required, it should be disabled.
30+
To do that, change its logger level to `off` in the `log4j2.properties` file.
31+
For more information, see <<configuring-logging-levels>>.
32+
2533
+
2634
--
2735
TIP: If the index is unavailable, it is possible for auditing events to
@@ -57,17 +65,27 @@ audited in plain text when including the request body in audit events.
5765
[[node-audit-settings]]
5866
==== Local Node Info Settings
5967

60-
`xpack.security.audit.logfile.prefix.emit_node_name`::
61-
Specifies whether to include the node's name in the local node info. The
62-
default value is `true`.
63-
64-
`xpack.security.audit.logfile.prefix.emit_node_host_address`::
65-
Specifies whether to include the node's IP address in the local node info. The
66-
default value is `false`.
67-
68-
`xpack.security.audit.logfile.prefix.emit_node_host_name`::
69-
Specifies whether to include the node's host name in the local node info. The
70-
default value is `false`.
68+
`xpack.security.audit.logfile.emit_node_name`::
69+
Specifies whether to include the <<node.name,node name>> as a field in
70+
each audit event.
71+
The default value is `true`.
72+
73+
`xpack.security.audit.logfile.emit_node_host_address`::
74+
Specifies whether to include the node's IP address as a field in each audit event.
75+
The default value is `false`.
76+
77+
`xpack.security.audit.logfile.emit_node_host_name`::
78+
Specifies whether to include the node's host name as a field in each audit event.
79+
The default value is `false`.
80+
81+
`xpack.security.audit.logfile.emit_node_id`::
82+
Specifies whether to include the node id as a field in each audit event.
83+
This is available for the new format only. That is to say, this information
84+
does not exist in the `<clustername>_access.log` file.
85+
Unlike <<node.name,node name>>, whose value might change if the administrator
86+
changes the setting in the config file, the node id will persist across cluster
87+
restarts and the administrator cannot change it.
88+
The default value is `true`.
7189

7290
[[index-audit-settings]]
7391
==== Audit Log Indexing Configuration Settings

x-pack/docs/en/security/auditing/output-logfile.asciidoc

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,41 @@
33
=== Logfile audit output
44

55
The `logfile` audit output is the default output for auditing. It writes data to
6-
the `<clustername>_access.log` file in the logs directory.
6+
the `<clustername>_audit.log` file in the logs directory. To maintain
7+
compatibility with releases prior to 6.5.0, a `<clustername>_access.log` file
8+
is also generated. They differ in the output format but the contents
9+
are similar. For systems that are not ingesting the audit file for search or
10+
analytics it is strongly recommended to only keep the newer format.
11+
Turning off the deprecated output format can be achieved by disabling the logger
12+
in the `log4j2.properties` file (hint: there is a config comment
13+
about it).
14+
For more information, see {ref}/logging.html#configuring-logging-levels[configuring-logging].
15+
716

817
[float]
918
[[audit-log-entry-format]]
1019
=== Log entry format
1120

12-
The format of a log entry is:
21+
The log entries in the `<clustername>_audit.log` file
22+
have the following format:
23+
24+
- Each log entry is a one line JSON document and each one is printed on a separate line.
25+
- The fields of a log entry are ordered. However, if a field does not have a value it
26+
will not be printed. The precise line pattern, together with the complete field
27+
order, are specified in the `log4j2.properties` config file.
28+
- The log entry does not contain nested inner JSON objects, i.e. the doc is flat.
29+
- The field names follow a dotted notation to flatten inner objects.
30+
- A field's value can be a string, a number or an array of strings.
31+
- A field's value, a request body as well, will be escaped as per the JSON RFC 4627.
32+
33+
There is a list of <<audit-event-types, audit event types>> specifying the
34+
set of fields for each sog entry type.
35+
36+
[float]
37+
[[deprecated-audit-log-entry-format]]
38+
=== Deprecated log entry format
39+
40+
The log entries in the `<clustername>_access.log` file have the following format:
1341

1442
[source,txt]
1543
----------------------------------------------------------------------------
@@ -48,8 +76,14 @@ audited in plain text when including the request body in audit events.
4876
[[logging-file]]
4977
You can also configure how the logfile is written in the `log4j2.properties`
5078
file located in `ES_PATH_CONF`. By default, audit information is appended to the
51-
`<clustername>_access.log` file located in the standard Elasticsearch `logs` directory
79+
`<clustername>_audit.log` file located in the standard Elasticsearch `logs` directory
5280
(typically located at `$ES_HOME/logs`). The file rolls over on a daily basis.
81+
The deprecated logfile audit format (`<clustername>_access.log`) can be disabled
82+
from the same `log4j2.properties` file (hint: look for the comment
83+
instructing to set the log level to `off`). The deprecated format is a duplication
84+
of information that is in place to assure backwards compatibility. If you are
85+
not strict about the audit format it is strongly recommended to only use the
86+
`<clustername>_audit.log` log appender.
5387

5488
[float]
5589
[[audit-log-ignore-policy]]

x-pack/docs/en/security/auditing/overview.asciidoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ must set `xpack.security.audit.enabled` to `true` in `elasticsearch.yml`.
1616
{Security} provides two ways to persist audit logs:
1717

1818
* The <<audit-log-output, `logfile`>> output, which persists events to
19-
a dedicated `<clustername>_access.log` file on the host's file system.
20-
* The <<audit-index, `index`>> output, which persists events to an Elasticsearch index.
21-
The audit index can reside on the same cluster, or a separate cluster.
19+
a dedicated `<clustername>_audit.log` file on the host's file system.
20+
For backwards compatibility reasons, a file named `<clustername>_access.log`
21+
is also generated.
22+
* The <<audit-index, `index`>> output, which persists events to an Elasticsearch
23+
index. The audit index can reside on the same cluster, or a separate cluster.
2224

23-
By default, only the `logfile` output is used when enabling auditing.
25+
By default, only the `logfile` output is used when enabling auditing,
26+
implicitly outputing to both `<clustername>_audit.log` and `<clustername>_access.log`.
2427
To facilitate browsing and analyzing the events, you can also enable
2528
indexing by setting `xpack.security.audit.outputs` in `elasticsearch.yml`:
2629

0 commit comments

Comments
 (0)