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

Support email-based authentication #58

Merged
merged 18 commits into from
Apr 2, 2019
Merged

Support email-based authentication #58

merged 18 commits into from
Apr 2, 2019

Conversation

anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Mar 25, 2019

Required Synapse PR: matrix-org/synapse#4931

Adds support for logging in/registering using your email address associated with LDAP. Additionally adds some new functionality to the LDAP search method to ask it for whatever search terms you'd like.

Makes use of a new check_3pid_auth method which allows for authentication via any 3PID method.
…nto anoa/email_auth

* 'master' of github.com:matrix-org/matrix-synapse-ldap3:
  Update LDAP dependency to fix broken unittests
anoadragon453 added a commit to matrix-org/synapse that referenced this pull request Mar 28, 2019
This PR allows password provider modules to bind email addresses when a user is registering and is motivated by matrix-org/matrix-synapse-ldap3#58
@anoadragon453 anoadragon453 marked this pull request as ready for review March 28, 2019 15:48
@@ -50,7 +50,7 @@ class LDAPMode(object):


class LdapAuthProvider(object):
__version__ = "0.1"
__version__ = "0.2"
Copy link
Member

Choose a reason for hiding this comment

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

Why are we bumping this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought since we were adding a relatively big feature, and we should get into the habit of bumping the version number when we do that.

Maybe that doesn't make sense though for this code.

Copy link
Member

Choose a reason for hiding this comment

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

I think if we do a release that should be done separately from this PR tbh.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok, good point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Heh, no idea

"User authenticated against LDAP server: %s",
conn
)
except NameError:
Copy link
Member

Choose a reason for hiding this comment

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

What's this doing? We don't expect logging to fail? And we've already logged conn in the debug logging above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, this was copied from

except NameError:

I assume if conn logs correctly then connection was successfully established. Not sure if this is the recommended way though.

Copy link
Member

Choose a reason for hiding this comment

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

I think the code before was checking whether we had managed to even define conn as a variable, rather than checking if conn can be stringified.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've set an option to the connection function to raise an exception if there's an issue connecting which should solve this?


except ldap3.core.exceptions.LDAPException as e:
logger.warning("Error during ldap authentication: %s", e)
defer.returnValue(None)
Copy link
Member

Choose a reason for hiding this comment

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

I'd have thought we wouldn't want to silently continue, as that is going to result in the wrong thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Again taken from elsewhere in the file. I agree silently failing isn't great for a client's perspective (they just get "invalid username/password"). Alternative is to actually fail so a M_UNKNOWN is returned which may actually prompt someone to poke their server admin.

Our only options for password providers are to return a user_id or None, either meaning authentication success or fail. We could just raise here though?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, ok. raise was what I vote for but we should be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

So do I. I'll edit all occurrences.

@anoadragon453
Copy link
Member Author

Sorry erik, one last time.

@erikjohnston
Copy link
Member

Is it possible to add some tests to this if you managed to break it?

"""
if self.ldap_mode != LDAPMode.SEARCH:
logger.warn("3PID LDAP login/register attempted but LDAP search mode "
"not enabled. Bailing.")
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this expected if you haven't enabled search? If so it shouldn't be a warn

Copy link
Member Author

Choose a reason for hiding this comment

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

True, just want to make sure people don't get confused if they expect email login to work. Debug instead?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'd vote for debug

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

Yeah, I think?

@anoadragon453 anoadragon453 merged commit 8e35312 into master Apr 2, 2019
@anoadragon453 anoadragon453 deleted the anoa/email_auth branch April 2, 2019 13:47
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.

2 participants