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
Watch the htpasswd
file for changes and update the htpasswdMap
#1701
Conversation
Hi all. Checking into this PR to see if its now ready for merge? |
@braunsonm The requested changes were implemented, could you please review it again? |
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.
lgtm, @JoelSpeed
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.
Some styling nits but otherwise LGTM, thanks!
pkg/authentication/basic/htpasswd.go
Outdated
|
||
err := h.loadHTPasswdFile(path) | ||
if err != nil { | ||
return nil, err |
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.
Please wrap errors you are returning with additional context
return nil, err | |
return nil, fmt.Errorf("could not load htpasswd file: %v", err) |
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.
We already have the context in the oauthproxy.go
file -> https://github.com/oauth2-proxy/oauth2-proxy/blob/master/oauthproxy.go#L114-L117.
We just need the value of the error retrieved from loadHTPasswdFile
or WatchFileForUpdates
.
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.
Typically, if you add context at every level, it's easy to see the exact error paths. Else you have to dig into each function call within this function to see which child error came up
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.
Changed the error message from oauthproxy.go
and added the context for load and watch.
pkg/authentication/basic/htpasswd.go
Outdated
} | ||
}) | ||
if err != nil { | ||
return nil, err |
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.
Please wrap with context
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 context in already in the oauthproxy.go
file -- same as above.
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.
Wrapped the error with context
Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
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, let's get this merged!
Amazing! |
…auth2-proxy#1701) * dynamically update the htpasswdMap based on the changes made to the htpasswd file * added tests to validate that htpasswdMap is updated after the htpasswd file is changed * refactored `htpasswd` and `watcher` to lower cognitive complexity * returned errors and refactored tests * added `CHANGELOG.md` entry for oauth2-proxy#1701 and fixed the codeclimate issue * Apply suggestions from code review Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> * Fix lint issue from code suggestion * Wrap htpasswd load and watch errors with context * add the htpasswd wrapped error context to the test Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
Description
watcher.go
was moved to a package to be accessible globallywatcher.go
- code was refactored to accommodate the implemented featurehtpasswd.go
- code was refactored to allow updates while the service is up&runninghtpasswd_test.go
- new tests were added to validate the added featureBased on these changes basic auth users can be dynamically added or removed
Motivation and Context
Fixes #1320
How Has This Been Tested?
oauth2-proxy
charthtpasswd-file
Secret
while the service was running (used working/malformed/invalid user details)Checklist: