-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 ldap auth #4751
base: master
Are you sure you want to change the base?
support ldap auth #4751
Conversation
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.
Tip
Please see the part of the contribution guide where we talk about discussing plans beforehand for future PRs.
"Duping work" is not maintainable both for contributors or maintainers ^^
To the PR:
- Please rebase this PR on top of Add basic multiple admin users support #3571.
- How can this be tested?
=> Please include a short paragraph how to set up a docker/.. environment to test that LDAP is working. - Could you write a first draft how this can be documented? (I have only a basic clue what half of the variables do)
Be aware that our current focus is on getting v2.0 out of the door (see #4500 for further details)
=> reviewing #3571 (as a prerequisite for this PR) might take longer.
server/auth.js
Outdated
]); | ||
if (process.env.AUTH_METHOD === "LDAP") { | ||
let ldapAuthSuccess = false; | ||
await new Promise((resolve, reject) => { |
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 extract the ldap parts of this implementation into a function.
This method is too long already and adding more will not aid in readability ^^
server/auth.js
Outdated
log.error("auth", "connecting ldap server failed"); | ||
resolve(); | ||
}); | ||
client.bind(process.env.LDAP_UID + "=" + username + "," + process.env.LDAP_BASE_DN, |
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 include debug logging what query is being executed
server/auth.js
Outdated
}); | ||
client.on("connectError", (err) => { | ||
log.error("auth", "connecting ldap server failed"); | ||
resolve(); |
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 refactor this to reject/resolve with the value of ldapAuthSuccess
.
This way, future PRs can't mess with the logic and introduce potential security flaws. (this logic is fine, but lets not leave a footgun lying around ^^)
server/auth.js
Outdated
url: [ process.env.LDAP_ADDRESS ] | ||
}); | ||
client.on("connectError", (err) => { | ||
log.error("auth", "connecting ldap server failed"); |
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.
include the error message if it contains context aiding in debugging
server/auth.js
Outdated
if (!ldapAuthSuccess) { | ||
return null; | ||
} | ||
let user = await R.findOne("user", " username = ? AND active = 1 ", [ |
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 extract the below parts into functions.
This is hard to comprehend => easy to make mistakes. Lets not risk this in security critical code ^^
server/auth.js
Outdated
log.warn("auth", "ldap authentication failed for user: " + username); | ||
} else { | ||
log.info("auth", "ldap authentication succeeded for user: " + username); |
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.
lets use a template for better readability
log.warn("auth", "ldap authentication failed for user: " + username); | |
} else { | |
log.info("auth", "ldap authentication succeeded for user: " + username); | |
log.info("auth", `ldap failed for ${username} because ${err}`); | |
} else { | |
log.info("auth", `${username} successfully logged in via ldap`); |
server/auth.js
Outdated
let ldapAuthSuccess = false; | ||
await new Promise((resolve, reject) => { | ||
const client = ldap.createClient({ | ||
url: [ process.env.LDAP_ADDRESS ] |
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.
On the parameters to this function (ldapjs
' docs):
- url does allow multiple LDAP servers.
Should we support this as well? - there are a few options regarding timouts. I think having timeouts for LDAP operations might be a good call.
- Should we add the
reconnection
parameter?
Thanks for your advises, that help me a lot. Due to #3571 is big change, this PR can be delayed or restructured. |
You can use handy tool to quickly test docker containers (sort of) Dockge |
Tick the checkbox if you understand [x]:
Resolves #5359
Description
add ldap auth support. It will works if below enviroment variables exist
The auth DN will be 'uid=username,cn=users,dc=xxxx,dc=com'.
If AUTH_METHOD not equal 'LDAP', it auth with local database user
Fixes #(issue)
Type of change
Please delete any options that are not relevant.
Checklist
Screenshots (if any)
Please do not use any external image service. Instead, just paste in or drag and drop the image here, and it will be uploaded automatically.