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

Add username in accesslog #2111

Merged
merged 5 commits into from Jan 24, 2018

Conversation

bastiaanb
Copy link
Contributor

Description

This PR fixes issue #2060: logging of authenticated username in accesslog. Works for both Basic and Digest authentication.

@bastiaanb
Copy link
Contributor Author

@ldez could we still get this into 1.4? We need this feature to ditch nginx as http router.....

@ldez ldez changed the title Feature/username in accesslog2 Add username in accesslog Sep 12, 2017
@ldez
Copy link
Member

ldez commented Sep 13, 2017

@bastiaanb we are ok to put this in 1.4, but you need to add tests (https://github.com/containous/traefik/blob/master/integration/access_log_test.go)

@bastiaanb
Copy link
Contributor Author

@ldez I have adjusted the access_log_test to correctly reflect how and when the req.URL.User gets set (by the authenticator code).
Is that sufficient? My guess is that the scenario where the URL.User is already set before invocation of the logger does not happen at all.

@ldez
Copy link
Member

ldez commented Sep 13, 2017

@bastiaanb could you remove the merge of the master branch, and change the base PR branch to 1.4 (and rebase). Ask me if you need help.

We need to support the 2 cases:

  • user from Traefik auth
  • user from external

Consequently we need 2 tests.

Could you revert your changes in the test and add a new test?

@m3co-code
Copy link
Contributor

If possible would it be maybe better to not modify the request object itself, but to extend the access log code to understand both sources? @bastiaanb WDYT?

IMHO it's not a good practice to modify the request object in such a way as it creates an implicit dependency between our auth and logging components. Think about what happens when we would replace the auth middleware with a 3rd party one that does it for us? Then the logging would again be broken.

@bastiaanb
Copy link
Contributor Author

@ldez oh, exeternal auth is actually used? Is a usage scenario available somewhere? I presume 'external auth' typically would be TLS client certificates?
I am a go-lang novice, so it will take a bit of time to write the proper test code....

@bastiaanb
Copy link
Contributor Author

@marco-jantke what would be the proper way to relay the username from the auth component to the access logger?

@m3co-code
Copy link
Contributor

I am not an expert with the HTTP authentication methods, but it seems in both cases (Digest + Basic Auth) the username is transferred in plain text and we can simply read it from the request. For the basic auth this was working anyway already before, for Digest Auth we would need some parsing in order to get the username. See https://en.wikipedia.org/wiki/Digest_access_authentication#Example_with_explanation for the digest authentication process. Can you try if this is a feasible approach?

I would also like to hear the opinion of other Maintainers and whether others see the same benefits in making the logging middleware smarter to keep coupling of the components low. @containous/traefik

@bastiaanb
Copy link
Contributor Author

bastiaanb commented Sep 20, 2017 via email

@m3co-code
Copy link
Contributor

Thank you for the reasoning @bastiaanb!

Also the identity should show up in the access log only in case of successful authentication.

This is a very good argument to go with your approach. About duplicating the code to extract the username, I slightly disagree, because you could, of course, extract the code and reuse it at both places. Anyway I think I am convinced to go with your approach. Going into code review now :)

Copy link
Contributor

@m3co-code m3co-code left a comment

Choose a reason for hiding this comment

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

Can you add a simple unit test to authenticator_test.go that proofs that r.URL.User is written for both, basic and digest auth? It should not be too complicated, given we have some tests there already.

Additionally, can you add a comment here that the handler is responsible to set the request.URL.User in case of a successful authentication, in order to add the username to the access logs? I don't know where to document it better.

@ldez
Copy link
Member

ldez commented Sep 28, 2017

@bastiaanb any news?

@bastiaanb
Copy link
Contributor Author

@ldez sorry, I haven't been able to work on this issue in the last weeks at all. I hope to pick this up in two weeks after a (laptopless) holiday.

@ldez ldez added the kind/enhancement a new or improved feature. label Oct 26, 2017
@ldez
Copy link
Member

ldez commented Nov 3, 2017

@bastiaanb any news?

@ldez ldez removed this from the 1.5 milestone Nov 16, 2017
@mmatur mmatur self-assigned this Jan 11, 2018
@mmatur mmatur force-pushed the feature/username-in-accesslog2 branch from cd07f5d to b773e55 Compare January 15, 2018 13:35
Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@m3co-code m3co-code left a comment

Choose a reason for hiding this comment

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

Only a suggestion to also cover digest auth in the test case left. Thanks for bringing this forwards @mmatur 👍

req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8004/", nil)
c.Assert(err, checker.IsNil)
req.Host = "entrypoint.auth.docker.local"
req.SetBasicAuth("test", "test")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do another test request that uses digest authentication to have both cases covered? Would be fine for me to just do it in this test case.

Copy link
Member

Choose a reason for hiding this comment

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

Done @marco-jantke

@mmatur mmatur force-pushed the feature/username-in-accesslog2 branch from 20a70dd to 9e43dba Compare January 22, 2018 10:49
Copy link
Contributor

@m3co-code m3co-code left a comment

Choose a reason for hiding this comment

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

LGTM, thanks 👍

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants