Authentification via un annuaire active directory, ldap .. |
Article original Publié le : 16 avril 2021 Mise a jour le : – |
Dans cet article, j’utilise un serveur Freeipa, pour un active directory il suffit d’adapter les attribues.
Plusieurs scénarios sont envisageables comme dans l’exemple sur devopstales
Créer un compte de service sur son Freeipa et configurer l’annuaire, créer et/ou modifier les fichiers suivants
1 |
$ sudo vim /etc/rundeck/jaas-multiauth.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
multiauth { com.dtolabs.rundeck.jetty.jaas.JettyCombinedLdapLoginModule sufficient debug="true" contextFactory="com.sun.jndi.ldap.LdapCtxFactory" providerUrl="ldap://<strong>freeipa01.izero.lan</strong>:389" bindDn="uid=<strong>compte_de_service</strong>,cn=users,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" bindPassword="<strong>mot_de_passe</strong>" authenticationMethod="simple" forceBindingLogin="true" userBaseDn="cn=users,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" userRdnAttribute="uid" userIdAttribute="uid" userPasswordAttribute="userPassword" userObjectClass="person" userLastNameAttribute="sn" userFirstNameAttribute="givenName" userEmailAttribute="mail" roleBaseDn="cn=groups,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" roleNameAttribute="cn" roleMemberAttribute="member" roleObjectClass="groupOfNames" cacheDurationMillis="300000" supplementalRoles="user" reportStatistics="true" timeoutRead="10000" timeoutConnect="20000" roleSearchSubtree="true" nestedGroups="true"; org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required debug="true" file="/etc/rundeck/realm.properties"; }; |
1 |
$ sudo vim /etc/rundeck/profile |
1 2 3 |
RDECK_JVM="-Drundeck.jaaslogin=<strong>true</strong> \ -Djava.security.auth.login.config=<strong>/etc/rundeck/jaas-multiauth.conf</strong> \ -Dloginmodule.name=<strong>multiauth</strong> \ |
1 |
$ sudo vim /etc/sysconfig/rundeckd |
1 2 |
export LOGIN_MODULE="<strong>multiauth</strong>" export JAAS_CONF="<strong>/etc/rundeck/jaas-multiauth.conf</strong>" |
Enfin, redémarrer le service et s’authentifier avec son compte d’annuaire,
parser les logs si l’authent échoue, généralement cela fait suite a un mauvais dn/cn ..
1 |
$ sudo systemctl restart rundeckd |
Pour une authentification sécurisée, en suivant la doc officielle il faut modifier en ldaps et port 636 et ajouter le certificat de sa CA
1 |
$ sudo vim /etc/rundeck/jaas-multiauth.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
multiauth { com.dtolabs.rundeck.jetty.jaas.JettyCombinedLdapLoginModule sufficient debug="true" contextFactory="com.sun.jndi.ldap.LdapCtxFactory" providerUrl="<strong>ldaps://freeipa01.izero.lan:636</strong>" bindDn="uid=<strong>compte_de_service</strong>,cn=users,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" bindPassword="<strong>mot_de_passe</strong>" authenticationMethod="simple" forceBindingLogin="true" userBaseDn="cn=users,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" userRdnAttribute="uid" userIdAttribute="uid" userPasswordAttribute="userPassword" userObjectClass="person" userLastNameAttribute="sn" userFirstNameAttribute="givenName" userEmailAttribute="mail" roleBaseDn="cn=groups,cn=accounts,dc=<strong>izero</strong>,dc=<strong>lan</strong>" roleNameAttribute="cn" roleMemberAttribute="member" roleObjectClass="groupOfNames" cacheDurationMillis="300000" supplementalRoles="user" reportStatistics="true" timeoutRead="10000" timeoutConnect="20000" roleSearchSubtree="true" nestedGroups="true"; org.rundeck.jaas.jetty.ReloadablePropertyFileLoginModule required debug="true" file="/etc/rundeck/realm.properties"; }; |
Récupérer le certificat de sa CA et l’ajouter a son trustore
Le truststore sera utilisé pour la communication locale entre les outils cli et le serveur rundeck.
Interroger le serveur ldap avec openssl
Le premier certificat est celui de la machine, le dernier est la CA
1 |
$ openssl s_client -showcerts -connect <strong>freeipa01.izero.lan</strong>:443 |
Prenez le dernier certificat avec les balises
1 2 |
-----BEGIN CERTIFICATE----- -----END CERTIFICATE----- |
et enregistrer le tout dans un fichier nommer ca.cer dans le répertoire ssl de Rundeck, par défaut /etc/rundeck/ssl/
Puis importer le certificat dans le trustore avec la commande Keytool, dans l’exemple le mot de passe sera phiengohRohPha7pe
1 |
$ sudo keytool -import -alias <strong>IZERO</strong> -file <strong>/etc/rundeck/ssl/ca.cer</strong> -keystore /etc/rundeck/ssl/truststore -storepass <strong>phiengohRohPha7pe</strong> |
/!\ Penser à modifier le mot de passe si changement
1 |
$ sudo vim /etc/rundeck/ssl/ssl.properties |
Pour ajouter le certificat au JRE, recherchez le fichier $ JAVA_HOME/lib/security/cacerts
1 |
$ sudo keytool -import -alias IZERO -file <strong>/etc/rundeck/ssl/ca.cer</strong> -keystore /usr/lib/jvm/java/jre/lib/security/cacerts -storepass changeit |
TIPS
Pour récupérer les attribues ou rechercher un champ particulier dans un annuaire, apache directory studio est très efficace.