User Tools

Site Tools


informatica:linux:openldap

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
informatica:linux:openldap [2013/05/23 14:09] javiinformatica:linux:openldap [2017/11/16 10:22] jose
Line 125: Line 125:
 </code> </code>
  
-NOTA: la contrasenya de los usuarios luego la cambiamos con phpldapmyadmin+NOTA: la contrasenya de los usuarios luego la cambiamos con [[phpldapadmin]]
  
 2. Ejecutar: 2. Ejecutar:
Line 323: Line 323:
 5. Verificar: 5. Verificar:
  
-  ldapsearch -xLLL -b "dc=example,dc=com" uid=perico+  ldapsearch -x -LLL -b "dc=example,dc=com" uid=perico
  
 Salida: Salida:
Line 359: Line 359:
 </code> </code>
  
-6. A partir de aqui ya podriamos probar con PhpLdapAdmin:+6. A partir de aqui ya podriamos probar con [[phpldapadmin]]:
  
   Login DN: cn=admin,dc=example,dc=com   Login DN: cn=admin,dc=example,dc=com
Line 389: Line 389:
 1. (Apache) Habilitar el modulo ldap 1. (Apache) Habilitar el modulo ldap
  
-  sudo a2enmod ldap+  sudo a2enmod authnz_ldap
  
-2. (Apache) Ejemplo de virtualhost:+==== HTTP plano ==== 
 + 
 +1. (Apache) Ejemplo de virtualhost:
  
 <code> <code>
Line 405: Line 407:
  
         <Directory /srv/www/testldap>         <Directory /srv/www/testldap>
 +         Options Indexes ExecCGI FollowSymLinks
         order allow,deny         order allow,deny
         allow from all         allow from all
 +
         AuthName "AuthRequired"         AuthName "AuthRequired"
         AuthType Basic         AuthType Basic
         AuthBasicProvider ldap         AuthBasicProvider ldap
-        AuthLDAPURL "ldap://ldap.example.com:389/ou=people,dc=example,dc=com"+ 
 +        AuthLDAPBindDN cn=readonly,dc=example,dc=com 
 +        AuthLDAPBindPassword clearpassword 
 +        AuthLDAPURL "ldap://ldap.example.com:389/ou=people,dc=example,dc=com" STARTTLS        
         require valid-user         require valid-user
-        </Directory>+       </Directory>
  
         ErrorLog ${APACHE_LOG_DIR}/testldap.error.log         ErrorLog ${APACHE_LOG_DIR}/testldap.error.log
- 
         # Possible values include: debug, info, notice, warn, error, crit,         # Possible values include: debug, info, notice, warn, error, crit,
         # alert, emerg.         # alert, emerg.
         LogLevel warn         LogLevel warn
- 
         CustomLog ${APACHE_LOG_DIR}/testldap.access.log combined         CustomLog ${APACHE_LOG_DIR}/testldap.access.log combined
 </VirtualHost> </VirtualHost>
Line 429: Line 434:
 Ver [[http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html#authldapurl|authldapurl]] Ver [[http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html#authldapurl|authldapurl]]
  
-3. (Apache) Reiniciar Apache:+==== TLS ====
  
-  sudo /etc/init.d/apache2 restart+1Configuracion del virtual host:
  
-4. En un navegador teclear:+<code> 
 +<VirtualHost *:443> 
 +        ServerName testldap.example.com 
 +        ServerAdmin webmaster@localhost 
 +        DocumentRoot /srv/www/testldap 
 + 
 +        <Directory /> 
 +                Options FollowSymLinks 
 +                AllowOverride None 
 +        </Directory> 
 + 
 +        <Directory /srv/www/testldap> 
 +         Options Indexes ExecCGI FollowSymLinks 
 +        order allow,deny 
 +        allow from all 
 + 
 +        AuthName "AuthRequired" 
 +        AuthType Basic 
 +        AuthBasicProvider ldap 
 + 
 +        AuthLDAPBindDN cn=readonly,dc=example,dc=com 
 +        AuthLDAPBindPassword clearpassword 
 +        AuthLDAPURL "ldaps://ldap.local.jamgo.org:636/ou=people,dc=jamgo,dc=org" 
 + 
 +        require valid-user 
 +       </Directory> 
 + 
 +        ErrorLog ${APACHE_LOG_DIR}/testldap.error.log 
 +        # Possible values include: debug, info, notice, warn, error, crit, 
 +        # alert, emerg. 
 +        LogLevel warn 
 +        CustomLog ${APACHE_LOG_DIR}/testldap.access.log combined 
 +</VirtualHost> 
 +</code> 
 + 
 +2. Crear el siguiente archivo: 
 + 
 +  sudo vim /etc/apache2/conf.d/ldap-tls 
 +   
 +Con el siguiente contenido: 
 + 
 +  LDAPVerifyServerCert Off 
 + 
 +3. (TODO) Comprobar si es necesario reiniciar apache o con el reload de mas adelante es suficiente  
 + 
 +==== Comprobacion ==== 
 + 
 +1. (Apache) Reiniciar Apache: 
 + 
 +  sudo service apache2 reload 
 + 
 +2. En un navegador teclear:
  
   http://testldap.example.com   http://testldap.example.com
Line 520: Line 576:
  
 NOTA: si se utiliza 'cn=config' en lugar de 'slapd.conf' NO hace falta reiniciar el servicio. Esto vale para todos los cambios a no ser que se indique lo contrario NOTA: si se utiliza 'cn=config' en lugar de 'slapd.conf' NO hace falta reiniciar el servicio. Esto vale para todos los cambios a no ser que se indique lo contrario
 +
  
 ===== TLS, SSL, STARTTLS, LDAPS ===== ===== TLS, SSL, STARTTLS, LDAPS =====
  
-1. Seguir los pasos especificados en https://help.ubuntu.com/12.10/serverguide/openldap-server.html#openldap-tls+https://help.ubuntu.com/12.10/serverguide/openldap-server.html#openldap-tls
  
-2**IMPORTANTE** es recomendable habilitar ldaps, por lo tanto **SI** es necesario:+When authenticating to an OpenLDAP server it is best to do so using an encrypted session. This can be accomplished using Transport Layer Security (TLS).
  
-2.1 Editar:+Here, we will be our own Certificate Authority and then create and sign our LDAP server certificate as that CASince slapd is compiled using the gnutls library, we will use the certtool utility to complete these tasks. 
 + 
 +1. Install the gnutls-bin and ssl-cert packages: 
 + 
 +  sudo apt-get install gnutls-bin ssl-cert 
 + 
 +2. Create a private key for the Certificate Authority: 
 + 
 +  sudo sh -c "certtool --generate-privkey > /etc/ssl/private/cakey.pem" 
 + 
 +3. Create the template/file /etc/ssl/ca.info to define the CA: 
 + 
 +<code> 
 +cn = Example Company 
 +ca 
 +cert_signing_key 
 +</code> 
 + 
 +4. Create the self-signed CA certificate: 
 + 
 +  sudo certtool --generate-self-signed --load-privkey /etc/ssl/private/cakey.pem --template /etc/ssl/ca.info --outfile /etc/ssl/certs/cacert.pem 
 + 
 +5. Make a private key for the server: 
 + 
 +  sudo certtool --generate-privkey --bits 1024 --outfile /etc/ssl/private/ldap01_slapd_key.pem 
 + 
 +6. Create the /etc/ssl/ldap01.info info file containing: 
 + 
 +<code> 
 +organization = Example Company 
 +cn = ldap01.example.com 
 +tls_www_server 
 +encryption_key 
 +signing_key 
 +expiration_days = 3650 
 +</code> 
 + 
 +The above certificate is good for 10 years. Adjust accordingly. 
 + 
 +7. Create the server's certificate: 
 + 
 +  sudo certtool --generate-certificate --load-privkey /etc/ssl/private/ldap01_slapd_key.pem --load-ca-certificate /etc/ssl/certs/cacert.pem --load-ca-privkey /etc/ssl/private/cakey.pem --template /etc/ssl/ldap01.info --outfile /etc/ssl/certs/ldap01_slapd_cert.pem 
 + 
 +8. Create the file /etc/ssl/certinfo.ldif with the following contents (adjust accordingly, our example assumes we created certs using https://www.cacert.org): 
 + 
 +<code> 
 +dn: cn=config 
 +add: olcTLSCACertificateFile 
 +olcTLSCACertificateFile: /etc/ssl/certs/cacert.pem 
 +
 +add: olcTLSCertificateFile 
 +olcTLSCertificateFile: /etc/ssl/certs/ldap01_slapd_cert.pem 
 +
 +add: olcTLSCertificateKeyFile 
 +olcTLSCertificateKeyFile: /etc/ssl/private/ldap01_slapd_key.pem 
 +</code> 
 + 
 +Use the ldapmodify command to tell slapd about our TLS work via the slapd-config database: 
 + 
 +  sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/ssl/certinfo.ldif 
 + 
 +9. IMPORTANTE es recomendable habilitar ldaps, por lo tanto SI es necesario:  
 + 
 +Editar:
  
   sudo vim /etc/default/slapd   sudo vim /etc/default/slapd
Line 535: Line 655:
   SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"   SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"
  
-2.2 Reiniciar LDAP:+Mas info: 
 + 
 + 
 +LDAP over TLS/SSL (ldaps: / / ) is deprecated in favour of StartTLSThe latter refers to an existing LDAP session (listening on TCP port 389) becoming protected by TLS/SSL whereas LDAPS, like HTTPS, is a distinct encrypted-from-the-start protocol that operates over TCP port 636. 
 + 
 + 
 +10. Tighten up ownership and permissions: 
 + 
 +  sudo adduser openldap ssl-cert 
 +  sudo chgrp ssl-cert /etc/ssl/private/ldap01_slapd_key.pem 
 +  sudo chmod g+r /etc/ssl/private/ldap01_slapd_key.pem 
 +  sudo chmod o-r /etc/ssl/private/ldap01_slapd_key.pem 
 + 
 +11. Restart OpenLDAP:
  
   sudo service slapd restart   sudo service slapd restart
  
---------------------------------------------------------------------------------+12. Comprobar: 
 +   
 +  sudo netstat -nlp | egrep "636|389" | grep -v "tcp6"
  
 +Salida esperada:
  
 +<code>
 +tcp        0      0 0.0.0.0:636             0.0.0.0:              LISTEN      15275/slapd     
 +tcp        0      0 0.0.0.0:389             0.0.0.0:              LISTEN      15275/slapd
 +</code>
  
-^ Protocolo ^ Config.adicional servidor ^ Puerto ^ +===== Modificar un registro en LDAP ===== 
-| StartTLS | La descrita en esta seccion | 389 | +Para añadir un campo, por ejemplo loginshell al usuario jurCreeamos el fichero anyadir.ldif: 
-| ldaps | La descrita en esta seccionEditar '/etc/default/slapd' | 636 |+<code> 
 +dn: cn=jur,dc=lobo99,dc=info 
 +add: loginshell 
 +loginshell: /bin/bash 
 +</code>
  
-**IMPORTANTE**: +Lo añadimos con el comando: 
 +  ldapmodify -x -w ******** -D "cn=admin,dc=lobo99,dc=info" -f anyadir.ldif 
 +   
 +Para modificarlo, creamos el fichero modificar.ldif 
 +<code> 
 +dn: cn=jur,dc=lobo99,dc=info 
 +changetype: modify 
 +replace: loginshell 
 +loginshell/bin/sh 
 +</code>
  
-a) LDAP over TLS/SSL (ldaps://) is deprecated in favour of StartTLS. The latter refers to an existing LDAP session (listening on TCP port 389) becoming protected by TLS/SSL whereas LDAPS, like HTTPS, is a distinct encrypted-from-the-start protocol that operates over TCP port 636.+  ldapmodify --w ******** -D "cn=admin,dc=lobo99,dc=info" -f modificar.ldif
  
-b) Hay todavia muchas aplicaciones que NO soportan StartTLS. 
  
-c) En el lado servidor se realizan las configuracionesen el lado cliente dependiendo de la URL de conexion del puerto se intenta ldaps o StartTLS.+===== Consulta sin corte de línea ===== 
 +  ldapsearch -D "cn=admin,dc=nodomain" -h 172.17.0.2 -p 389 -w **** -s base -b "CN=Subschema" objectclasses -v -o ldif-wrap=no 
 +Con linux si tienes perl: 
 +  ldapsearch -D "cn=admin,dc=nodomain" -h 172.17.0.2 -p 389 -w **** -s base -b "CN=Subschema" objectclasses -v | perl -p00e 's/\r?\n //g' 
 +===== Consulta de todos los atributos ===== 
 +  ldapsearch -D "cn=admin,dc=nodomain" -h 172.17.0.2 -p 389 -w **** -s base -b "CN=Subschema" objectclasses -v -ldif-wrap=no 
 +<code> 
 +objectClasses: ( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass ) 
 +objectClasses: ( 1.3.6.1.4.1.1466.101.120.111 NAME 'extensibleObject' DESC 'RFC4512: extensible object' SUP top AUXILIARY ) 
 +objectClasses: ( 2.5.6.1 NAME 'alias' DESC 'RFC4512: an alias' SUP top STRUCTURAL MUST aliasedObjectName ) 
 +objectClasses: ( 2.16.840.1.113730.3.2.6 NAME 'referral' DESC 'namedref: named subordinate referral' SUP top STRUCTURAL MUST ref ) 
 +objectClasses: ( 1.3.6.1.4.1.4203.1.4.1 NAME ( 'OpenLDAProotDSE' 'LDAProotDSE' ) DESC 'OpenLDAP Root DSE object' SUP top STRUCTURAL MAY cn ) 
 +objectClasses: ( 2.5.17.0 NAME 'subentry' DESC 'RFC3672: subentry' SUP top STRUCTURAL MUST ( cn $ subtreeSpecification ) ) 
 +</code> 
 +  
  
informatica/linux/openldap.txt · Last modified: 2018/07/24 09:37 by javi