Audit configuration
ReadonlyREST can collect audit events containing information about a request and how the system has handled it and send them to configured outputs. Here is an example of the data points contained in each audit event. We can leverage all this information to build interesting Kibana dashboards, or any other visualization.
Configuration
The audit collecting by default is disabled. To enable it, you need to add audit.enabled: true
and optionally configure the audit.outputs
. In the outputs
array, you can define i.a. where the audit events should be sent. The currently supported output types are:
index
- similarly to Logstash it writes audit events in the documents stored in the ReadonlyREST audit indexlog
- it allows you to collect audit events using the Elasticsearch logs and format them with the help of features thatlog4j2
enables. You can configure multiple outputs for audit events. When the audit is enabled, at least one output has to to be defined. If you omitoutputs
definition, the defaultindex
output will be used.
Here is an example of how to enable audit events collecting with all defaults:
You can also use multiple audit outputs, e.g.
When you want to have more control over the audit outputs, the extended outputs
format is for you. For example, you can disable given output by adding enabled: false
to the output config:
The other settings, specific to the type of audit outputs, are mentioned in the next sections.
The 'index' output specific configurations
Custom audit indices name and time granularity
By default ReadonlyREST audit index name template is readonlyrest_audit-YYYY-MM-DD
. You can customize the name template using the index_template
settings.
Example: tell ROR to write on the monthly index.
⚠️IMPORTANT: notice the single quotes inside the double quoted expression. This is the same syntax used for Java's SimpleDateFormat.
Custom audit cluster
It's possible to set a custom audit cluster responsible for audit events storage. When a custom cluster is specified, items will be sent to defined cluster nodes instead of the local one.
Setting audit.cluster
is optional, it accepts non empty list of audit cluster nodes URIs.
The 'log' output specific configurations
The log
output uses a dedicated logger to write the audit events to the Elasticsearch log at INFO level.
To make ReadonlyREST start adding the audit events to the Elasticsearch log, all you have to do is add "log" as one of the outputs, e.g:
Custom logging settings
If you want to control the logging process of audit events, you can do it via the $ES_PATH_CONF/config/log4j2.properties
. Here is an example config with the default logger name, with a separate log file, and configured rolling:
All settings are up to you. The only required entry is the logger name logger.{your-logger-name}.name = {your-logger-name}
. The default logger name is the readonlyrest_audit
.
If you want to set a custom logger name for the log
output, add the logger_name
setting for the given output:
Extending audit events
The audit events are JSON documents describing incoming requests and how the system has handled them. To create such events, we use a serializer
, which is responsible for the event's serialization and filtering. The example event is in default format and was produced by the default serializer (tech.beshu.ror.audit.instances.DefaultAuditLogSerializer
). You can use any of the predefined serializers or use a custom one.
For example, if you want to add the request content to the audit event then an additional serializer is provided. This will add the entire user request within the content field of the audit event. To enable, configure the serializer
parameter as below.
Custom audit event serializer
You can write your own custom audit events serializer class, add it to the ROR plugin class path and configure it through the YAML settings.
We provided 2 project examples with custom serializers (in Scala and Java). You can use them as an example to write yours in one of those languages.
Create custom audit event serializer in Scala
Checkout https://github.com/sscarduzio/elasticsearch-readonlyrest-plugin
git clone git@github.com:sscarduzio/elasticsearch-readonlyrest-plugin.git
Install SBT
https://www.scala-sbt.org/download.html
Find and go to:
elasticsearch-readonlyrest-plugin/custom-audit-examples/ror-custom-scala-serializer/
Create own serializer:
from scratch (example can be found in class
ScalaCustomAuditLogSerializer
)extending default one (example can be found in class
ScalaCustomAuditLogSerializer
)
Build serializer JAR:
sbt assembly
Jar can be find in:
elasticsearch-readonlyrest-plugin/custom-audit-examples/ror-custom-scala-serializer/target/scala-2.13/ror-custom-scala-serializer-1.0.0.jar
Create custom audit event serializer in Java
Checkout https://github.com/sscarduzio/elasticsearch-readonlyrest-plugin
git clone git@github.com:sscarduzio/elasticsearch-readonlyrest-plugin.git
Install Maven
https://maven.apache.org/install.html
Find and go to:
elasticsearch-readonlyrest-plugin/custom-audit-examples/ror-custom-java-serializer/
Create own serializer:
from scratch (example can be found in class
JavaCustomAuditLogSerializer
)extending default one (example can be found in class
JavaCustomAuditLogSerializer
)
Build serializer JAR:
mvn package
Jar can be find in:
elasticsearch-readonlyrest-plugin/custom-audit-examples/ror-custom-java-serializer/target/ror-custom-java-serializer-1.0.0.jar
Configuration
mv ror-custom-java-serializer-1.0.0.jar plugins/readonlyrest/
Your config/readonlyrest.yml should start like this
Start elasticsearch (with ROR installed) and grep for:
Last updated