mattv8 / yourls-ldap-plugin

Simple LDAP plugin for YOURLS
GNU General Public License v3.0
18 stars 13 forks source link

yourls-ldap-plugin

This plugin for YOURLS enables the simple use of LDAP for user authentication.

Installation

  1. Download the latest yourls-ldap-plugin.
  2. Copy the plugin folder into your user/plugins folder for YOURLS.
  3. Set up the parameters for yourls-ldap-plugin in YOURLS configuration user/config.php (see below).
  4. Activate the plugin with the plugin manager in the admin interface.

Usage

When yourls-ldap-plugin is enabled and a user was not successfully authenticated using data specified in yourls_user_passwords, an LDAP authentication attempt will be made. If LDAP authentication is successful, then you will immediately go to the admin interface.

You can also set a privileged account to search the LDAP directory with. This is useful for directories that don't allow anonymous binding. If you define a suitable template, the current user will be used for binding. This is useful for Active Directory / Samba.

Setting the groups settings will check if the user is a member of that group before logging them in and storing their credentials. This check is only performed the first time they authenticate or when their password changes.

yourls-ldap-plugin, by default, will now implement a simple cache of LDAP users. As well as reducing requests to the LDAP server, this has the effect of allowing the YOURLS API to work with LDAP users.

Configuration

To use a privileged account for the user search:

To define a template to bind using the current user for the search: Use %s as the placeholder for the current username

To use a custom LDAP search filter:

If this option is not set, the filter is based only on LDAPAUTH_USERNAME_FIELD (default). This is useful if a more advanced filter is needed, like when using AD nested groups. For searching based on AD Nested group LDAP_MATCHING_RULE_IN_CHAIN OID (1.2.840.113556.1.4.1941) must be specified for the user's memberof attribute. Example of a filter based on AD nested group: define( 'LDAPAUTH_SEARCH_FILTER', '(&(samaccountname=%s)(memberof:1.2.840.113556.1.4.1941:=YOURLS-ADMINS,OU=Groups,DC=example,DC=com))' );

To check group membership before authenticating:

To define the scope of group req search:

To define the type of user cache used:

To automatically add LDAP users to config.php:

To use Active Directory Sites and Services DNS entry for LDAP server name lookup

NOTE: This will require config.php to be writable by your webserver user. This function is now largely unneeded because the database-based cache offers similar benefits without the need to make config.php writable. It is retained for backward compatibility.

Troubleshooting

About the user cache

When a successful login is made against an LDAP server, the plugin will cache the username and encrypted password. Currently, this is done by saving them in an array in the YOURLS options table. This has some advantages:

Unfortunately, the cache will not scale well. This is because it integrates tightly with YOURLS's internal auth mechanism, and that does not scale. If you have a few tens of LDAP users likely to use your YOURLS installation, it should be fine. Much more than that, and you may see performance issues. If so, you should probably disable the cache. This will mean that your LDAP users will not be able to use the API. At least not unless they are also listed in users/config.php, which suffers from the same scaling problems.

License

Original Plugin Author(s):
Copyright 2013 K3A, #1davoaust
Copyright 2013 Nicholas Waller (code@nicwaller.com) as I used some parts of his CAS authentication plugin :)

Maintainer(s):
Matt Visnovsky #mattv8

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.