-
Notifications
You must be signed in to change notification settings - Fork 351
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
New filter: maskAccessLogQuery #2674
Open
remychantenay
wants to merge
3
commits into
zalando:master
Choose a base branch
from
remychantenay:feature/add-mask-access-log-query-filter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package logging | |
import ( | ||
"bytes" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -15,10 +16,21 @@ const logOutput = `127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gi | |
const logJSONOutput = `{"audit":"","auth-user":"","duration":42,"flow-id":"","host":"127.0.0.1","level":"info","method":"GET","msg":"","proto":"HTTP/1.1","referer":"","requested-host":"example.com","response-size":2326,"status":418,"timestamp":"10/Oct/2000:13:55:36 -0700","uri":"/apache_pb.gif","user-agent":""}` | ||
const logExtendedJSONOutput = `{"audit":"","auth-user":"","duration":42,"extra":"extra","flow-id":"","host":"127.0.0.1","level":"info","method":"GET","msg":"","proto":"HTTP/1.1","referer":"","requested-host":"example.com","response-size":2326,"status":418,"timestamp":"10/Oct/2000:13:55:36 -0700","uri":"/apache_pb.gif","user-agent":""}` | ||
|
||
func testRequest() *http.Request { | ||
r, _ := http.NewRequest("GET", "http://[email protected]", nil) | ||
func testRequest(params url.Values) *http.Request { | ||
fullURL := url.URL{ | ||
Scheme: "http", | ||
Host: "example.com", | ||
RawQuery: params.Encode(), | ||
} | ||
|
||
r, err := http.NewRequest(http.MethodGet, fullURL.String(), nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
r.RequestURI = "/apache_pb.gif" | ||
r.RemoteAddr = "127.0.0.1" | ||
|
||
return r | ||
} | ||
|
||
|
@@ -29,19 +41,30 @@ func testDate() time.Time { | |
|
||
func testAccessEntry() *AccessEntry { | ||
return &AccessEntry{ | ||
Request: testRequest(), | ||
Request: testRequest(nil), | ||
ResponseSize: 2326, | ||
StatusCode: http.StatusTeapot, | ||
RequestTime: testDate(), | ||
Duration: 42 * time.Millisecond, | ||
AuthUser: ""} | ||
} | ||
|
||
func testAccessEntryWithQueryParameters(params url.Values) *AccessEntry { | ||
testAccessEntry := testAccessEntry() | ||
testAccessEntry.Request = testRequest(params) | ||
|
||
return testAccessEntry | ||
} | ||
|
||
func testAccessLog(t *testing.T, entry *AccessEntry, expectedOutput string, o Options) { | ||
testAccessLogExtended(t, entry, nil, expectedOutput, o) | ||
} | ||
|
||
func testAccessLogExtended(t *testing.T, entry *AccessEntry, additional map[string]interface{}, expectedOutput string, o Options) { | ||
func testAccessLogExtended(t *testing.T, entry *AccessEntry, | ||
additional map[string]interface{}, | ||
expectedOutput string, | ||
o Options, | ||
) { | ||
var buf bytes.Buffer | ||
o.AccessLogOutput = &buf | ||
Init(o) | ||
|
@@ -74,6 +97,19 @@ func TestAccessLogFormatJSONWithAdditionalData(t *testing.T) { | |
testAccessLogExtended(t, testAccessEntry(), map[string]interface{}{"extra": "extra"}, logExtendedJSONOutput, Options{AccessLogJSONEnabled: true}) | ||
} | ||
|
||
func TestAccessLogFormatJSONWithMaskedQueryParameters(t *testing.T) { | ||
additional := map[string]interface{}{KeyMaskedQueryParams: []string{"foo"}} | ||
|
||
params := url.Values{} | ||
params.Add("foo", "bar") | ||
testAccessLogExtended(t, | ||
testAccessEntryWithQueryParameters(params), | ||
additional, | ||
`{"audit":"","auth-user":"","duration":42,"flow-id":"","host":"127.0.0.1","level":"info","method":"GET","msg":"","proto":"HTTP/1.1","referer":"","requested-host":"example.com","response-size":2326,"status":418,"timestamp":"10/Oct/2000:13:55:36 -0700","uri":"/apache_pb.gif?foo=5234164152756840025","user-agent":""}`, | ||
Options{AccessLogJSONEnabled: true}, | ||
) | ||
} | ||
|
||
func TestAccessLogIgnoresEmptyEntry(t *testing.T) { | ||
testAccessLogDefault(t, nil, "") | ||
} | ||
|
@@ -263,3 +299,12 @@ func TestAccessLogStripQuery(t *testing.T) { | |
entry.Request.RequestURI += "?foo=bar" | ||
testAccessLog(t, entry, logOutput, Options{AccessLogStripQuery: true}) | ||
} | ||
|
||
func TestHashQueryParamValue(t *testing.T) { | ||
want := uint64(3728699739546630719) | ||
got := hash("foo") | ||
|
||
if got != want { | ||
t.Errorf("\ngot %v\nwant %v", got, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will override any preceding filter configuration.
Maybe we should think about supporting a usecase where we could specify default masked values
and then user may specify additional values.
OTOH proposed solution is simple and in line with what already exists.
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.
Hey @AlexanderYastrebov
Yeah, I wanted to keep it simple. In hindsight, I am not sure my thinking is right.
If the current implementation is a no-go, I will try and spend a bit more time and see if I can come up with something when I get back from vacay (from tomorrow till the beginning of next month.)