How to add hash the whole content of an event in Logstash for OpenSearch?

321 Views Asked by At

the problem is the following: I'm investigating how to add some anti-tampering protection to events stored in OpenSearch that are parsed and sent there by Logstash. Info is composed of application logs collected from several hosts. The idea is to add a hashed field that's linked to the original content so that any modification of the fields break the hash result and can be detected.

Currently, we have in place some grok filters that extract information from the received log lines and store it into different fields using several patterns. To make it more difficult for an attacker who modifies these logs to cover their tracks, I'm thinking of adding an extra field where the whole line is hashed and salted before splitting.

Initial part of my filter config is like this. It was used primarily with ELK, but our project will be switching to OpenSearch:

filter {
  grok {
    match => { "message" => "%{TIMESTAMP_ISO8601:mytimestamp} (\[)*%{LOGLEVEL:loglevel}(\])* %{JAVACLASS:javaclass}(.)*(\[/])* %{DATA:component} %{DATA:version} - %{GREEDYDATA:message}"}
    overwrite => [ "message" ]
    overwrite => [ "version" ]
    break_on_match => false
    keep_empty_captures => true
  }
   // do more stuff

}

OpenSearch has some info on Field masking, but this is not exactly what I am after.

If any of you could help me with a pointer or an idea on how to do this. I don't know whether the hash fields available in ELK are also available in OpenSearch, or whether the Logstash plugin that does the hashing of fields would be usable without licensing issues. But maybe there are other and better options that I am not aware. I was looking for info on how to call an external script to do this during the filter execution, but I don't even know whether that is possible (apparently not, at least I couldn't find anything).

Any ideas? Thank you!

0

There are 0 best solutions below