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

✨ LDAP StartTLS #56

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Demo/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
ldap_host: ldap://ldap.company.com:389/
ldap_port: 389
ldap_version: 3
ldap_start_tls: false
ldap_search_attribute: uid
ldap_base_dn: "ou=People,o=Company"
ldap_filter: "(objectClass=*)"
Expand Down
1 change: 1 addition & 0 deletions Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Some image parameters can be changed, by specifying the desired parameters in co
| ldap_host | URL or IP to connect LDAP server | `ldap://ldap.company.com/` |
| ldap_port | Port used to connect LDAP server | `389` |
| ldap_version | LDAP version or protocol version used by LDAP server | `3` |
| ldap_start_tls | LDAP over STARTTLS | `false` |
| ldap_search_attribute | Attribute used to identify a user on the LDAP | `uid` |
| ldap_filter | Additional filter for LDAP search | `objectClass=*` |
| ldap_base_dn | The base directory name of your LDAP server | ` ou=People,o=Company` |
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Edit `oauth/LDAP/config_ldap.php` and adapt prameters with your LDAP configurati
| ldap_host | URL or IP to connect LDAP server | `ldap://ldap.company.com/` |
| ldap_port | Port used to connect LDAP server | `389` |
| ldap_version | LDAP version or protocol version used by LDAP server | `3` |
| ldap_start_tls | LDAP over STARTTLS | `false` |
| ldap_search_attribute | Attribute used to identify a user on the LDAP | `uid` |
| ldap_filter | Additional filter for LDAP search | `(objectClass=*)` |
| ldap_base_dn | The base directory name of your LDAP server | `ou=People,o=Company` |
Expand All @@ -259,7 +260,7 @@ For openLDAP server, the 'ldap_search_attribute' should be `uid`, and for AD ser

Parameters 'ldap_bind_dn' and 'ldap_bind_pass' are required if your LDAP is restrictive, else put an empty string ("").

**Wraning** : Mattermost-LDAP V2 has changed 'ldap_filter' syntax. Now, the ldap filter must respect the LDAP syntax and need to be included into parenthesis.
**Warning** : Mattermost-LDAP V2 has changed 'ldap_filter' syntax. Now, the ldap filter must respect the LDAP syntax and need to be included into parenthesis.

*Note* : 'ldap_version' avoid LDAP blind error with LDAP 3 (issue #14)

Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
- ldap_host
- ldap_port
- ldap_version
- ldap_start_tls
- ldap_search_attribute
- ldap_base_dn
- ldap_filter
Expand Down
3 changes: 3 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ ldap_port = "389"
# LDAP protocol version
ldap_version = "3"

# LDAP STARTTLS
ldap_start_tls = "1"

# Unique identifier for entry in LDAP
ldap_search_attribute = "uid"

Expand Down
3 changes: 3 additions & 0 deletions ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//LDAP version
$ldap_version = 3;

//LDAP STARTTLS
$ldap_start_tls = false;

//Unique identifier of user on LDAP
$uid = "username";
$email = "[email protected]";
Expand Down
9 changes: 8 additions & 1 deletion oauth/LDAP/LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class LDAP implements LDAPInterface
* An optional int to specify ldap server port, by default : 389
* @param int @ldap_version
* An optional int to specify ldap version, by default LDAP V3 protocol is used
* @param boolean @ldap_start_tls
* An optional boolean to use ldap over STARTTLS, by default LDAP STARTTLS is not used
*
* Initiate LDAP connection by creating an associated resource
*/
public function __construct($ldap_host, $ldap_port = 389, $ldap_version = 3)
public function __construct($ldap_host, $ldap_port = 389, $ldap_version = 3, $ldap_start_tls = false)
{
if (!is_string($ldap_host)) {
throw new InvalidArgumentException('First argument to LDAP must be the hostname of a ldap server (string). Ex: ldap//example.com/ ');
Expand All @@ -45,6 +47,11 @@ public function __construct($ldap_host, $ldap_port = 389, $ldap_version = 3)
throw new InvalidArgumentException('Third argument to LDAP must be the ldap version (int). Ex : 3');
}

// Support LDAP over STARTTLS
if ($ldap_start_tls === true) {
ldap_start_tls($ldap);
}

$this->ldap_server = $ldap;
}

Expand Down
1 change: 1 addition & 0 deletions oauth/LDAP/config_ldap.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$ldap_host = getenv('ldap_host') ?: "ldap://ldap.company.com/";
$ldap_port = intval(getenv('ldap_port')) ?: 389;
$ldap_version = intval(getenv('ldap_version')) ?: 3;
$ldap_start_tls = boolval(getenv('ldap_start_tls')) ?: false;

// Attribute use to identify user on LDAP - ex : uid, mail, sAMAccountName
$ldap_search_attribute = getenv('ldap_search_attribute') ?: "uid";
Expand Down
2 changes: 1 addition & 1 deletion oauth/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function messageShow($html_template, $message = 'No Msg') {
$password=$_POST['password'];

// Open a LDAP connection
$ldap = new LDAP($ldap_host,$ldap_port,$ldap_version);
$ldap = new LDAP($ldap_host,$ldap_port,$ldap_version,$ldap_start_tls);

// Check user credential on LDAP
try{
Expand Down
2 changes: 1 addition & 1 deletion oauth/resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
$assoc_id = intval($info_oauth["assoc_id"]);

// Open a LDAP connection
$ldap = new LDAP($ldap_host, $ldap_port, $ldap_version);
$ldap = new LDAP($ldap_host, $ldap_port, $ldap_version, $ldap_start_tls);

// Try to get user data on the LDAP
try {
Expand Down