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

refactor LDAP driver in userprovider #2133

Closed
wants to merge 6 commits into from

Conversation

rhafer
Copy link
Contributor

@rhafer rhafer commented Oct 5, 2021

Move some common code into helper functions. Also don't assume that the
userid in reva matches the user's username. So add an additional LDAP
lookup to get the username before looking up groupmembership.

@update-docs
Copy link

update-docs bot commented Oct 5, 2021

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@lgtm-com
Copy link

lgtm-com bot commented Oct 5, 2021

This pull request introduces 1 alert when merging 7763348 into c40fcc8 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Oct 6, 2021

This pull request introduces 1 alert when merging 5851c05 into 67f39be - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@rhafer rhafer force-pushed the ldap-refactor branch 7 times, most recently from 18d2416 to c4adc4c Compare October 7, 2021 17:41
@rhafer rhafer marked this pull request as ready for review October 7, 2021 18:03
@rhafer rhafer requested a review from labkode as a code owner October 7, 2021 18:03
@rhafer
Copy link
Contributor Author

rhafer commented Oct 11, 2021

cc @aduffeck @butonic

@rhafer
Copy link
Contributor Author

rhafer commented Oct 13, 2021

@labkode Could you please take a look at this?

rhafer and others added 6 commits November 1, 2021 16:19
Move some common code into helper functions. Also don't assume that the
userid in reva matches the user's username. So add an additional LDAP
lookup to get the username before looking up groupmembership.
The entryUUID attribute is generated by the LDAP server. By using this
me can make sure that the the users get different IDs with every
test. So that can avoid setting DELETE_USER_DATA_CMD to delete
the USER data after each test in the long run.

Also this seems to uncover some issue in the WebDAV code which still
assumes that the userid always match the username.
Return a proper NOT_FOUND error instead of INTERNAL when user is not found.
GetUser() is for getting users by ID only. Also try to handle the "User does not
exist" case with a more helpful error message.
GetUserByClaim is suppose to return exactly one user. Return a
more helpful error if the filter matches multiple users.
Status: status.NewInternal(ctx, err, "error getting user"),
res := &userpb.GetUserResponse{}
if _, ok := err.(errtypes.NotFound); ok {
res.Status = status.NewNotFound(ctx, "user not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add req.UserId to the error

}

// Check if we got a Username
res, err := gatewayClient.GetUserByClaim(ctx, &userpb.GetUserByClaimRequest{
Copy link
Contributor

Choose a reason for hiding this comment

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

These calls can be avoided by checking what is being specified in the template. If we know that the calls will always be to the /dav/files/$username/$path and the namespace template asks for username only, then we can return early. Also, these need to be cached. Going to the userprovider service for every storage operation would be costly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why we want to support requests to both /dav/files/$username/$path and /dav/files/$uid/$path

})
HandleWebdavError(appctx.GetLogger(r.Context()), w, b, err)
}
r.URL.Path = newPath
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! But this shouldn't have worked previously. I'd recommend having integration tests for both scenarios files_namespace = "/users/{{.Id.OpaqueId}}" and files_namespace = "/users"

@@ -405,7 +420,7 @@ func (m *manager) getFindFilter(query string) string {
return strings.ReplaceAll(m.c.FindFilter, "{{query}}", ldap.EscapeFilter(query))
}

func (m *manager) getGroupFilter(uid *userpb.UserId) string {
func (m *manager) getGroupFilter(uid interface{}) string {
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 go back to uid being *userpb.UserId?

@ishank011 ishank011 mentioned this pull request Nov 29, 2021
3 tasks
@rhafer
Copy link
Contributor Author

rhafer commented Feb 22, 2022

This has landed in edge a while ago. I am going to close this for now. (Trying to bring back the edge an master branch in sync with another PR)

@rhafer rhafer closed this Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants