Authentication, SSO and SSL

Revision as of 11:36, 29 December 2022 by Eldy (talk | contribs) (→‎http)


Authentication setup in Dolibarr

There is different solutions to be authenticated with Dolibarr. You can find the selected method into the htdocs/conf/conf.php file into the parameter $dolibarr_authentication_mode. This is a list of available values:

  • dolibarr
  • http
  • ldap
  • forceuser
  • ...

You can combine several methods (some combinations are however technically not compatible). If you use several method (separated by a coma), you will try to authenticate using the first method and if it fails, the next method will be used. For example, if you set

$dolibarr_authentication_mode="ldap,dolibarr"

the system will try to authenticate using the LDAP database and if it fails it will try to login using the internal Dolibarr login/password

Each authentication mode may have complementary parameters (also into htdocs/conf/conf.php file) to have them working. Let's have a look at each available method:

List of available authentication modes

dolibarr

With this method, the login and pass you entered on login page will be compared to the login and the hashed password saved into the Dolibarr database (Table llx_user).

http

You can set the authentication mode to "http" if you Dolibarr web application is protected by an Apache http basic authentication form. The login/pass are stored into the file used by the HTTP Basic system to store passwords (it is often a file called .htpasswd if you used the mod_auth_basic plugin of Apache).

This is an exemple of setup for Apache to protect your instance to be accessed using the HTTP Basic authentication:

https://github.com/Dolibarr/dolibarr/blob/develop/dev/setup/apache/virtualhost

Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.

ldap

If you set the authentication mode to LDAP, the test of the validity of your login and password are done using a LDAP database.

Note that the user must also exists as an existing user into the Dolibarr user database. Also the date of validity of this user must be valid.

forceuser

When this method is used, there is no need to enter a login or password. No login page is show. The user will be automatically set to the one defined into the variable $dolibarr_auto_user saved into htdocs/conf/conf.php

This mode is used only on development platforms. For example on an instance used to make demo or automated tests.

Note that the user must also exists as a existing user into the Dolibarr user database. Also the date of validity of this user must be valid.

googleauth

This method is still in development and is not yet available

openid

This method is not yet available and still in development.


However, if you need to connect using OpenID, you can already do it using the following solution:

Connect to dolibarr using Openid and the HTTP Basic of Apache

L'idée est d'utiliser deux éléments :

  • Le plugin auth_openidc pour Apache
  • L'authentification HTTP Dolibarr.

La procédure va donc nécessiter d'avoir Dolibarr installé avec Apache et le module apache https://github.com/zmartzone/mod_auth_openidc. Ce dernier est souvent directement disponible sur Linux via une commande du gestionnaire de package.

La seconde partie va donc être de configurer ce module apache afin d'authentifier les utilisateurs avec le protocole OpenID Connect. Dans le cas général, il vous faudra seulement l'URL des métadata. Voici un exemple de configuration apache pour de l'OpenID avec AzuereAD:

OIDCProviderMetadataURL https://login.microsoftonline.com/your-tenant-id/v2.0/.well-known/openid-configuration
OIDCClientID youropenidclient 
OIDCClientSecret yoursecret 
OIDCCryptoPassphrase randomstring 
OIDCRedirectURI https://mydolibarr.exemple.com/sso_redirect 
OIDCScope "openid email profile" 
OIDCRemoteUserClaim email ^(.*)@ 

<Directory /var/ht> 

# Docroot 
AuthType openid-connect 
Require valid-user 
Require env no-auth 

</Directory>


Dans l'exemple ci-dessus, les informations à rentrer dans OIDCProviderMetadataURL, OIDCClientID et OIDCClientSecret sont communiquées par votre fournisseur OpenID Connect.

La variable OIDCRemoteUserClaim définie quel "claim" sera utilisé pour le nom d'utilisateur. Dans notre exemple de configuration, nous considérons que le nom d'utilisateur qui sera utilisé dans Dolibarr est ce qui précède l'arobase dans l'adresse email.

Après cette manipulation, vous devriez être invité à vous connecter à votre compte OpenID Connect pour accéder à votre installation Dolibarr. Cependant, il reste à indiquer à Dolibarr qu'il doit utiliser le nom d'utilisateur défini par Apache. C'est dans le fichier conf/conf.php que nous allons réaliser cette manipulation. Ajoutez à la fin du fichier la ligne suivante :

$dolibarr_main_authentication='http';

Votre authentification OpenID Connect est maintenant pleinement fonctionnelle ! Attention toutefois, il peut y avoir des ajustements à faire pour que cette configuration fonctionne avec certains modules. Par exemple, l'usage de WebDav dans Dolibarr n'est pas compatible avec cette configuration. Ou encore, l'accès aux pages publiques (pages /public/*) se retrouvera bloquer par la demande d'authentification mise en place. Pour éviter cela, il vous faut aussi exclure les chemins qui ne doivent pas être protégé par l'authentification Apache pour OpenID qui défini le Directory protégé. Voir l'exemple de la configuration du mode d'authentification "http" pour une configuration plus complète.

En adaptant plus loin cette configuration, est est aussi possible d'utiliser l'authentification ActiveDirectory et d'autres services d'authentification.