-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easily mask sensitive headers from request logs by adding HeadersSanitizer
#5188
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #5188 +/- ##
===========================================
+ Coverage 0 74.01% +74.01%
- Complexity 0 20744 +20744
===========================================
Files 0 1799 +1799
Lines 0 76422 +76422
Branches 0 9728 +9728
===========================================
+ Hits 0 56561 +56561
- Misses 0 15258 +15258
- Partials 0 4603 +4603 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a preliminary comment 🙇
core/src/main/java/com/linecorp/armeria/common/logging/AbstractLogFormatterBuilder.java
Outdated
Show resolved
Hide resolved
76e2dcc
to
6e5df41
Compare
maskHeaders
, maskRequestHeaders
, maskResponseHeaders
for LogFormatter
HeadersSanitizer
core/src/main/java/com/linecorp/armeria/common/logging/TextLogFormatterBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/logging/AbstractLogFormatterBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/JsonHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/JsonHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/TextHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/TextHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/TextHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/TextHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
Sorry for the late reply. I will work on the issue again 🙇 |
The Git history looks messed up. Changes of |
e690150
to
e8ee73d
Compare
e8ee73d
to
3c163cb
Compare
core/src/main/java/com/linecorp/armeria/common/JsonHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/JsonHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/TextHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
/** | ||
* Sets the {@link Set} which includes headers to mask before logging. | ||
*/ | ||
public AbstractHeadersSanitizerBuilder<T> maskHeaders(String... headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The headers defined in
HttpHeaderNames
should be compatible without additional casting. maskingHeaders
orsensitiveHeaders
is preferred overmaskHeaders
because this function sets the headers to be masked, not the actual action.
public AbstractHeadersSanitizerBuilder<T> maskHeaders(String... headers) { | |
public AbstractHeadersSanitizerBuilder<T> maskingHeaders(CharSequence... headers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I'll apply as below
maskHeaders
->maskingHeaders
mask
->maskingFunction
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/HeadersSanitizer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/HeadersSanitizer.java
Outdated
Show resolved
Hide resolved
@ikhoon , should the masking function be case insensitive? For example, if user set |
- Fix naming - Mask sensitive headers by default
f35a31e
to
0904f65
Compare
HTTP header names are case-insensitive as per https://www.rfc-editor.org/rfc/rfc2616#section-4.2 |
core/src/main/java/com/linecorp/armeria/common/JsonHeadersSanitizer.java
Outdated
Show resolved
Hide resolved
I pushed changes that fix some style issued. PTAL. 😉 |
@minwoox Thanks for cleaning up the mess I've made 🙇 . The PR seems ready 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice! Thanks @seonwoo960000 🙇 👍 🙇
@jrhee17 Sorry, I've made some changes after your review. PTAL tomorrow. 🙇♂️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, looks good to me. Thanks! 😉
- A header name is necessary to dynamically mask header values. - Handle a null value returned by masking functions. - Replace Function<String,String` with `HeaderMaskingFunction`. - `HeaderSanitizer` their builders are moved to `common.logging` from `common`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks @ikhoon 🙇 👍 🙇
core/src/test/java/com/linecorp/armeria/common/logging/TextLogFormatterTest.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/logging/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/common/logging/AbstractHeadersSanitizerBuilder.java
Outdated
Show resolved
Hide resolved
…tHeadersSanitizerBuilder.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thanks, @seonwoo960000 🙇♂️🚀
Motivation: `HeadersSanitizer` was added in line#5188. If no `HeadersSanitizer` is set, the default santizer masks `Authorization`, `Cookie` `Set-Cookie` and `Proxy-Authorization` with `****`. In addition to `HeadersSantizer`, other new features are added to `LoggingDecoratorBuilder` and the code became messy to maintain backward compatibility. `LoggingDecoratorBuilder`, `LogWriterBuilder`, and `LogFormatterBuilder` each have their own properties, so it was not easy to make the overall operation consistent. As a result, while `LoggingClient.newDecorator()` santizes sensitive headers, LoggingClient.builder().requestLogLevel(...).newDecorator()` did not work. Neither code set a sanitizer, so a default sanitizer should have been set, but it didn't. Modifications: - Refactor `LoggingDecoratorBuilder` to delegate all builder properties to either `LogWriterBuilder` or `LogFormatterBuilder`. - Add missing `@Deprecated` annotation to `LoggingClientBuilder` and `LoggingRpcClientBuilder` and `LoggingServiceBuilder`. - `@Deprecated` in the super method aren't inspected by IntelliJ line#5395 - Breaking) Change the signature of `LogWriterBuilder.responseCauseFilter()` to have `RequestContext` as the first parameter. - It may be a bug or a mistake when adding the API. Our APIs usually provide `RequestContext` for predicates or handlers. Result: `LoggingClient` and `LoggingService` now correctly mask sensitive headers by default.
…ng decorators (#5519) Motivation: `HeadersSanitizer` was added in #5188. If no `HeadersSanitizer` is set, the default sanitizer masks `Authorization`, `Cookie` `Set-Cookie`, and `Proxy-Authorization` with `****`. In addition to `HeadersSantizer`, other new features were added to `LoggingDecoratorBuilder` and the code became messy to maintain backward compatibility. `LoggingDecoratorBuilder`, `LogWriterBuilder`, and `LogFormatterBuilder` each have their own properties, so making the overall operation consistent was not easy. As a result, while `LoggingClient.newDecorator()` sanitizes sensitive headers, LoggingClient.builder().requestLogLevel(...).newDecorator()` did not work. Neither code set a sanitizer, so a default sanitizer should have been set, but it didn't. Modifications: - Refactor `LoggingDecoratorBuilder` to delegate all builder properties to either `LogWriterBuilder` or `LogFormatterBuilder`. - Add missing `@Deprecated` annotation to `LoggingClientBuilder` and `LoggingRpcClientBuilder` and `LoggingServiceBuilder`. - `@Deprecated` in the super method isn't inspected by IntelliJ #5395 - Breaking) Change the signature of `LogWriterBuilder.responseCauseFilter()` to have `RequestContext` as the first parameter. - It may be a bug or a mistake when adding the API. Our APIs usually provide `RequestContext` for predicates or handlers. Result: `LoggingClient` and `LoggingService` now correctly mask sensitive headers by default.
Motivation:
Mask sensitive headers when logging request and response headers.
Modifications:
maskHeaders
,maskRequestHeaders
,maskResponseHeaders
when usingAbstractFormatterBuilder
implementations. (e.g.TextLogFormatterBuilder
,JsonLogFormatterBuilder
)maskRequestHeaders
andmaskResponseHeaders
to mask request and response headersResult:
Users are able to easily mask request and response headers: