Navigation Menu

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

Allow looking up users by an email address #11562

Closed

Conversation

andrewshadura
Copy link
Contributor

This patch adds an option to look up users by an email address. This is useful for example for tools manipulating or synchronising the user database with other sources.

The new API does not pose any greater privacy or security risk than the currently available APIs, since they already allow finding a user by their email address, albeit much slower (list all users, iterate over users, request emails; possible to optimise by first checking users with usernames similar to their email addresses).

Example of the usage:

$ osc --debug api '/person?email=andrew.shadura@collabora.co.uk'
GET https://obs-api/person?email=andrew.shadura@collabora.co.uk
<directory count="1">
  <entry name="andrewsh"/>
</directory>

This does not pose any greater privacy or security risk than the currently
available APIs, since they already allow finding a user by their email
address, albeit much slower (list all users, iterate over users, request
emails; possible to optimise by first checking users with usernames
similar to their email addresses).

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
@github-actions github-actions bot added the Frontend Things related to the OBS RoR app label Aug 31, 2021
@dmarcoux
Copy link
Contributor

dmarcoux commented Aug 31, 2021

I'm not against this, but I'm also not entirely convinced. So when you write This is useful for example for tools manipulating or synchronizing the user database with other sources, I would be interested to hear more about those tools.

If we decide to go ahead and introduce this feature, it should be documented in the API documentation. We would also need an index on the email column in the users table. I can guide you with this, but first I'll wait on details about the tools.

@andrewshadura
Copy link
Contributor Author

We’re currently writing a tool to synchronise group membership with an external database, so when a (new) user logs in, they’re added to the corresponding groups. The upstream users database does not use usernames at all, but uses emails as the primary identifier; to keep the performance within safe limits, we need this extra API, otherwise as I outlined in the PR description, it’s way too tedious to extract the same information from the API.

I must admit this works quite well without any additional indices. The current work-in-progress patchset for OmniAuth-based SSO uses find_by_email (which ends up doing the same query) and it works well enough for the purpose.

This query is not expected to be used frequently anyway, so slower performance shouldn’t be a big issue.

Copy link
Member

@hennevogel hennevogel left a comment

Choose a reason for hiding this comment

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

I'm against to enable this for regular users. Only for admins please.

@andrewshadura
Copy link
Contributor Author

andrewshadura commented Sep 1, 2021 via email

@hennevogel
Copy link
Member

Can you explain the reason please?

It's making it too easy for my taste to check if some email address has an account.

@adrianschroeter
Copy link
Member

you can achieve the same via xpath search already

/search/person?match=@email=...

@@ -15,6 +15,8 @@ class PersonController < ApplicationController
def show
@list = if params[:prefix]
User.where('login LIKE ?', params[:prefix] + '%')
elsif params[:email]
User.where(:email => params[:email])
Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewshadura User.where(email: params[:email]) to make the linter happy

@hennevogel
Copy link
Member

So yeah this is already (although undocumented) possible...

osc api "/search/person?match=@email='hvogel@suse.com'"
<collection matches="1">
  <person>
    <login>hennevogel</login>
    <email>hvogel@suse.com</email>
    <realname>Hendrik Vogelsang</realname>
    <state>confirmed</state>
    <globalrole>Staff</globalrole>
  </person>

@hennevogel hennevogel closed this Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend Things related to the OBS RoR app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants