I am trying to create a Pipeline rule that replaces sensitive information. Im running into issues with using '[^&]*.
For example i am trying to filter out the following password: ‘#p54_L35’. It works well if i replace '[^&]* with ‘#p54_L35’. So what am i doing wrong here? Is there an alternative way of filtering out sensitive information?
See code below
rule “Hide sensitive information”
when
has_field(“message”)
then
let message = to_string($message.message);
let filteredMessage = replace(message, “password: '[^&]'", “password: '[redacted]'”, -1);
let filteredMessage2 = replace(filteredMessage, "token: ''[^&]'”, “password: '[redacted]'”, -1);
let filteredMessage3 = replace(filteredMessage2, “token=[^&]*”, “token=[redacted]”, -1);
set_field(“message”, filteredMessage3);
end
The first one will parse the first part of our log, the rest you can build on your own.
create a rule in a pipeline attached to your logs:
rule "parsing: apache Logs"
when
true // or better condition if you have
then
set_fields(
grok(
pattern:"^%{ApacheLogs}",
value:to_string($message.message),
only_named_captures:true
)
);
end
This pipeline will set the stuff you need in different fields. There is the pattern for DATA_ALL_BUT_SPACE, you can create a similar one to make the “,” not beeing captured.
create rules redacting the fields you don’t want to have with full values:
rule "redacting"
when
has_field("secret_values")
then
set_field(
field:"secret_values",
value:
abbreviate(
value:sha256(
to_string($message.secret_values)
),
width:to_long("10")
)
);
end
This will replace the field secret_values with the first 10 signs of the sha256 hash of the value of that field.
and also redacting the full-message:
rule "redacting"
when
has_field("message")
then
set_field("message", "bogus-content");
end