-
Notifications
You must be signed in to change notification settings - Fork 357
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
filters/accesslog: Add maskAccessLogQuery
filter
#3471
base: master
Are you sure you want to change the base?
Conversation
72d732b
to
50aca5c
Compare
Signed-off-by: Remy Chantenay <[email protected]>
Signed-off-by: Remy Chantenay <[email protected]>
Signed-off-by: Remy Chantenay <[email protected]>
50aca5c
to
fcff629
Compare
b844976
to
7af633f
Compare
maskAccessLogAuery
filter
018897d
to
3fb7525
Compare
…parameters filtering This change allows to use several maskAccessLogQuery filters in one route. This allows us to have default masked values in prepend filters. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
…ions Replace google/go-cmp with stretchr/testify in accessLogFormat control tests. The change also improves readability by replacing nested conditional statements with straightforward assertions. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
The commit corrects a bug in the AccessLogFilter.Request method where an incorrect type assertion was being performed. The code was attempting to assert a value from the state bag as an AccessLogFilter value rather than a pointer (*AccessLogFilter), which would cause runtime errors when two or more instances of the filter are used. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
This commit adds tests to verify that the access log control filters correctly merge masked query parameters from multiple filters. The tests validate that parameters from different filters are correctly combined and that repeated parameters are properly handled. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
This commit removes the redundant array type declaration in the test files by using the short syntax for array literals. The Go compiler can infer the type from the context. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
3fb7525
to
c69d2c7
Compare
maskAccessLogAuery
filtermaskAccessLogQuery
filter
} else { | ||
return | ||
} | ||
require.Error(t, err, "Expected error creating filter") |
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.
minor: you can also use require.Condition
to remove the outer if.
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.
Seems that it will look more complex with Condition
logging/access.go
Outdated
@@ -109,6 +115,29 @@ func stripQueryString(u string) string { | |||
} | |||
} | |||
|
|||
// maskQueryParams masks (i.e., hashing) specific query parameters in the provided request's URI. | |||
// Returns the obfuscated URI. | |||
func maskQueryParams(req *http.Request, maskedQueryParams map[string]bool) string { |
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.
I think we can also inline map len check here and return early
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.
But this function returns string, means we need to allocate new one even for early return.
logging/access.go
Outdated
@@ -144,6 +173,10 @@ func LogAccess(entry *AccessEntry, additional map[string]interface{}) { | |||
uri = entry.Request.RequestURI | |||
if stripQuery { | |||
uri = stripQueryString(uri) | |||
} else if keys, ok := additional[KeyMaskedQueryParams].(map[string]bool); ok { | |||
if len(keys) > 0 { |
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.
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 link is broken for me
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.
was this one #3471 (comment)
Using map[string]struct{} for MaskedQueryParams to represent a set of query parameters more efficiently. This is a common Go pattern for implementing sets, where we care only about the existence of a key and not any associated value. The empty struct requires no memory allocation for values. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
This change replaces a classic for loop indexing with a more idiomatic range iteration over values in the maskAccessLogQuery.CreateFilter method. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
This test was testing the xxhash.Sum64String library function Signed-off-by: Aleksandr Ponimaskin <[email protected]>
This commit simplifies the logic in maskQueryParams by removing an unnecessary intermediate variable for the hashed value and directly using the hash function result in the params.Set() call. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
Consolidated nested if statements in access.go for better readability while preserving the same functionality. The code now checks both conditions (keys exist and length > 0) in a single if statement rather than using nested conditionals. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
Replace `struct{}{}` with `{}` in map declarations for the `struct{}` type in the test files. This uses Go's shorthand struct literal syntax, making the code more concise and readable while maintaining the same functionality. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
ff42068
to
46828d4
Compare
filters/accesslog/control.go
Outdated
bag[AccessLogEnabledKey] = al | ||
if f, ok := bag[AccessLogEnabledKey]; ok { | ||
a := f.(*AccessLogFilter) | ||
maps.Copy(a.MaskedQueryParams, al.MaskedQueryParams) |
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.
This modifies filter instance from parallel requests and will panic.
This commit moves the responsibility for managing masked query parameters from the proxy to the AccessLogFilter. It properly stores masquerading information in the state bag under the AccessLogAdditionalDataKey, ensuring better isolation between components. A new constant KeyMaskedQueryParams has been moved from logging to accesslog package for better organization, and the code now uses maps.Copy for compatibility. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
The test was incorrectly comparing the entire AccessLogFilter struct when it should only be comparing the masked query parameters map. This change updates the test to correctly access the masked query parameters from the state bag and compare only that specific field. Signed-off-by: Aleksandr Ponimaskin <[email protected]>
f6d8b28
to
5e2ba42
Compare
Introduce a new
maskAccessLogQuery
filter that masks/obfuscates values of specific sensitive query parameters in access logs.Additionally, refactor
accesslog/control_test.go
to use testify/assert for improved test readability.See the previous PR for discussion details - #2674
Closing #2156, #2674