-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Server: Added ldap authentication #9150
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
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.
Thanks @marcorombach, that looks good overall. You'll need to run yarn install
and commit because CI is not passing at the moment.
Also would it be possible to add tests for this feature?
packages/server/src/utils/ldap.ts
Outdated
try { | ||
await client.bind(searchResults.searchEntries[0].dn, password); | ||
} catch (ex) { | ||
return null; |
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.
Shouldn't silence errors in general. Maybe wrap the error like above and rethrow it?
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 it as suggested. But now I remembered why I did it that way.
Now the user will be confronted with an error like "LdapErr: DSID-0c090439 ..."
By returning null the user gets "invalid username or password" which is almost always the cause for throwing an error here.
What would you prefer? Maybe returning null but logging the error message?
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.
In general we need to distinguish between user errors and server errors. If the call here is to check the user password, is it possible to look at the exception error and return null
if it's an invalid login, and throw an exception if, for example, the server is unreachable? Does the error object has some code attached to it that we could look at for this?
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.
I found the error code for invalid credentials. If an error with this code is thrown, it now will return null and otherwise it will return the error.
Tests would need a mock ldap server like https://www.npmjs.com/package/ldap-server-mock to work. |
Implementing a whole mock server would be overkill, but we need at least tests for the login method since this is a very important part of the software. You can do that relatively easily in |
Added some tests, are they sufficient? |
It looks good now, thanks for adding the test @marcorombach! There's now a conflict on yarn.lock - would you mind fixing it? You just need to run |
@laurent22 the conflict on yarn.lock is now resolved. Somehow there where changes to supportedLocales.js after running yarn install that where commited. There is a entry in .gitignore, so I don't know why that was commited. I reverted these changes and it seems like everything is ok now. |
Ok that's strange, because that file should actually be named |
Unable to get this to work with joplin/server:2.13.5-beta in Docker and using Authentik LDAP Outpost. The web interface says only
Docker stack environment variables for LDAP are
Is there any way of enabling extended debug/error logging? Right now the only clue is that it appears to have problem with the LDAP_1_SERVER url but not idea as to why. Tried having the variable in single, double quotes or no quotes, this makes no difference. |
Seems like you took the env vars from my initial PR comment. These are not the final variable names. I'll try to edit this comment. In the meanwhile you can find the correct variables including a brief description in this file: https://github.com/laurent22/joplin/blob/dev/packages/server/src/env.ts#L111 |
Thank you for the help and your contribution to the code, it's working now with the correct variable names. 😊 |
You're welcome! Glad it works for you now :) |
This provides the option to use up to two LDAP directories as authentication source for Joplin Server.
If activated user also will be created on the fly if LDAP authentication was successful.
The mail address is used to search the user in the directories.
Following ENV variables are available to configure the LDAP authentication:
For a second LDAP server just replace 1 with 2 in the variable name.
BIND_DN and BIND_PW are optional - if not provided, a anonymous bind against the LDAP server will be tried.
MAIL_ATTRIBUTE and FULLNAME_ATTRIBUTE may vary for different LDAP servers, the preset values works for ActiveDirectory.