question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to implement a PatternMaskingLayout for a LoggingEventCompositeJsonEncoder

See original GitHub issue

Hi. I have the following problem. I’m using the LoggingEventCompositeJsonEncoder to generate JSON logs, but I found out that we have lots of confidential information that we want to filter out (basically just put *** in the corresponding key).

https://www.schibsted.pl/blog/logback-pattern-gdpr/

One idea here is to use this:

      <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
           <layout class="com.schibsted.payment.logback.PatternMaskingLayout">

However, this will not log everything nicely in JSON.

Is there a way to accomplish what I want?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
rusucosmincommented, Nov 7, 2019

I’ve written a simple version which worked for my specific needs: https://github.com/logstash/logstash-logback-encoder/pull/375.

However, I don’t feel like it’s yet great. I might need some feedback from @phasebash.

The problem is that if I try to log some specific objects (for example, I wanted to log JSONObject s and JSONArrays. I ended up doing something like this in the writeObject method:

    } else if (JSONObject.class.isAssignableFrom(cls)) { // sub-class
      return sanitize((JSONObject) ob);
    } else if (JSONArray.class.isAssignableFrom(cls)) { // sub-class
      return sanitize((JSONArray) ob);

This is clearly not a generic use and you’ll have to implement overloaded sanitize methods. I’m wondering what would be an alternative to this?

1reaction
philsttrcommented, Oct 30, 2019

Yes definitely!

And I’d love if the logic to detect what should be masked would be customizable. And logstash-logback-encoder provided some detectors for standard use cases, I can think of three cases:

  1. by field name, where if a field name in any object at any path matches a list of global field names to mask, then mask it
  2. by sub path, where if the path of a field matches a list subpaths to mask, then mask it
  3. by field value, where if a value matches a regex of values to mask

1 and 2 could potentially be combined if it’s coded such that a single field name is just a subpath with one element.

Probably need to handle masking any type of field value (e.g. number fields, string fields, array fields, and object fields.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement a PatternMaskingLayout for a ... - GitHub
I'm using the LoggingEventCompositeJsonEncoder to generate JSON logs, but I found out that we have lots of confidential information that we want ...
Read more >
Mask sensitive data in logs with logback - Stack Overflow
Try this one. 1. First of all, we should create a class for handling our logs (each row) public class PatternMaskingLayout extends PatternLayout...
Read more >
Anonymizing logs for GDPR using Logback pattern layout
The idea behind the configuration is to extend every logback appender you need with custom layout, in our case it is: PatternMaskingLayout which ......
Read more >
Logging configuration - Puppet
By configuring logback appropriately, you get JSON-formatted log messages with event-specific fields in each message. Common fields. If you use the recommended ...
Read more >
Mask Sensitive Data in Logs With Logback - Baeldung
Learn how to use the PatternLayout feature to mask sensitive data in application logs with Logback.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found