Skip to content
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

API: Include IP address when logging request error #21596

Merged

Conversation

thedeveloperr
Copy link
Contributor

@thedeveloperr thedeveloperr commented Jan 19, 2020

What this PR does / why we need it:
This will provide additional security information on failed login
and also help integrate services like Fail2Ban to detect brute
force attacks.

Which issue(s) this PR fixes:

Fixes #21310

Special notes for your reviewer:
In my local dev setup, e2e tests were failing due to some phantomjs installation issue, I create this PR to run tests on circle ci to ensure my changes are not failing any tests. Also this log line didn't fail any backend test so didn't write my own test. Do you need me to write test for this change ?

@claassistantio
Copy link

claassistantio commented Jan 19, 2020

CLA assistant check
All committers have signed the CLA.

@thedeveloperr thedeveloperr changed the title Logs: Add client ip to login log message. Logging: Add client ip to login log message. Jan 19, 2020
@thedeveloperr thedeveloperr requested a review from marefr January 19, 2020 16:26
@thedeveloperr thedeveloperr marked this pull request as ready for review January 19, 2020 16:27
@marefr marefr added area/backend pr/external This PR is from external contributor labels Jan 20, 2020
Copy link
Contributor

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thedeveloperr thanks. Sorry it taken me long time to come back to this one. After consideration I've notice that our router logging middleware (when enabled) includes remote_addr, <ip> why I suggest to revert your change to middleware.go and in addition log IP address on error in common.go:

diff --git a/pkg/api/common.go b/pkg/api/common.go
index 0f81e30..7f87925 100644
--- a/pkg/api/common.go
+++ b/pkg/api/common.go
@@ -47,7 +47,7 @@ func Wrap(action interface{}) macaron.Handler {
 
 func (r *NormalResponse) WriteTo(ctx *m.ReqContext) {
        if r.err != nil {
-               ctx.Logger.Error(r.errMessage, "error", r.err)
+               ctx.Logger.Error(r.errMessage, "error", r.err, "remote_addr", ctx.RemoteAddr())
        }
 
        header := ctx.Resp.Header()

@thedeveloperr
Copy link
Contributor Author

So remove changes from middleware.go but add here in common.go ?

@bergquist
Copy link
Contributor

Yes, please :)

Eager to merge once its been fixed.

This will provide additional security information on failed login
and also help integrate services like Fail2Ban to detect brute
force attacks.
@thedeveloperr thedeveloperr force-pushed the area/backend/logging/add_ip_on_login branch from 4ab7b6d to 5043eab Compare March 1, 2020 14:40
@thedeveloperr thedeveloperr requested a review from marefr March 1, 2020 14:45
Copy link
Contributor

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marefr marefr changed the title Logging: Add client ip to login log message. API: Include IP address when logging request error Mar 2, 2020
@marefr marefr merged commit 94951df into grafana:master Mar 2, 2020
@marefr
Copy link
Contributor

marefr commented Mar 2, 2020

Thank you for contributing to Grafana!

@marefr marefr added this to the 6.7 milestone Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log “Invalid username or password” plus IP of the request (Allow detection of attacks with fail2ban)
4 participants