Remove lfs-uefi.txt symlink
[linux_from_scratch_hints.git] / PREVIOUS_FORMAT / ldap_auth.txt
bloba623c555034d1d7d042e77c31f76c2b7cdf5ff02
1 TITLE:          LDAP AUTH
2 LFS VERSION:    3.1
3 AUTHOR:         Michenaud Laurent <Michenaud Laurent>
5 VERSION : BETA BETA BETA
7 SYNOPSIS:
9 HINT:
11 I - PAM
12 =======
14 download here :
15 http://www.us.kernel.org/pub/linux/libs/pam/pre/library/Linux-PAM-0.75.tar.bz2
16 http://www.us.kernel.org/pub/linux/libs/pam/pre/library/cracklib-files.tgz
19 1) CrackLib Installation
21 unpack cracklib-files.tgz
23 cp usr/include/* /usr/include/*
24 cp usr/lib/* /usr/lib/*
25 cp usr/sbin/* /usr/sbin/*
28 2) Pam Installation
30 ./configure --with-mailspool=/var/mail
32 make
34 make install
36 # Create the directory where u can have one file 
37 # per service configuration
38 mkdir /etc/pam.d
40 # Creating missing links
41 cd /lib
42 ln -s libpam.so.0.75 libpam.so.0
43 ln -s libpam_misc.so.0.75 libpam_misc.so.0
46 3) Shadow-20001016 recompilation
48 You have to reinstall the shadow-20001016 package
49 in order to take of PAM.
51 For that, recompile the option --with-pam
53 I am not a pam specialist and maybe it will be good to add
54 a specific configuration for the other services such ftp, telnet,etc...
58 II - OPENLDAP
59 =============
61 download here :
62 ftp://ftp.OpenLDAP.org/pub/OpenLDAP/openldap-release/openldap-2.0.22.tgz
64 1) Installation
65 ---------------
66 ./configure --prefix=/usr \
67             --sysconfdir=/etc \
68             --localstatedir=/var \
69             --enable-syslog \
70             --with-threads \
71             --with-tls \
72             --enable-ldap \
73             --enable-slapd \
74             --enable-crypt \
75             --enable-modules \
76             --enable-dynamic \
77             --enable-ldbm \
78             --enable-passwd-backend \
79             --enable-slurpd
80 make depend
81 make
82 make test
83 make install
86 2) SSL Key Generation for connection encryption
87 -----------------------------------------------
89 mkdir /etc/openldap/ssl
90 cd /etc/openldap/ssl
91 openssl req -new -x509 -nodes -out slapd.pem -keyout slapd.key -days 365
94 It will ask a few question needed to generate the key.
95 VERY IMPORTANT :
96 When asking for Common Name, enter your hostname.
98 I don't know why but without that, it will not work.
101 3) OpenLDAP Configuration
102 --------------------------
104 You should read the documentation.
105 Here is what i use with some explanations.
107 The configuration is /etc/openldap/slapd.conf
109 ###################################
110 # Begin of /etc/openldap/slapd.conf
112 # The following included files define the necessary
113 # objects
114 include         /etc/openldap/schema/core.schema
115 include         /etc/openldap/schema/cosine.schema
116 include         /etc/openldap/schema/inetorgperson.schema
117 include         /etc/openldap/schema/nis.schema
120 # GLOBAL DIRECTIVES
123 pidfile         /var/run/slapd.pid
124 argsfile        /var/run/slapd.args
126 # Load dynamic backend modules:
127 modulepath      /usr/libexec/openldap
128 # moduleload    back_ldap.la
129 moduleload      back_ldbm.la
130 # moduleload    back_passwd.la
131 # moduleload    back_shell.la
133 # Access Control
134 # access to
136 # Default acces { none | compare | search | read | write } 
137 defaultaccess read
139 # Time before an idle connection is killed, -1 to desactivate this fonction
140 idletimeout     0
142 # Loglevel
143 loglevel 256
145 # Define the max records number that a research can provide.
146 sizelimit 500
148 # Specifie le referral quand slapd ne peut trouver une base 
149 # de données locale
150 # referral
153 # GENERAL BACKEND OPTIONS
154 #  options for all databases
157 # Database type : ldbm, shell, passwd
158 backend ldbm
162 # GENERAL DATABASE DIRECTIVES
165 # Database type
166 database ldbm
168 # Read only database
169 readonly off
171 # replica ldap-1.example.com:389 tls=yes
172 #       bindmethod=sasl saslmech=GSSAPI
173 #       authcId=host/ldap-master.example.com@EXAMPLE.COM
175 # Log file for replication
176 replogfile     /var/log/openldap/master-slapd.replog
178 # specifies the DN that is not subject to access control or 
179 # administrative limit restrictions for operations on this database. The DN 
180 # need not refer to an entry in the directory. The DN may refer to a SASL 
181 # identity.
182 rootdn          "cn=Manager,dc=zerezo,dc=org"
184 # Specify a password for the entry above
185 rootpw          secret
186 #rootpw         {crypt}fdssdfs
188 # Suffix for this database
189 suffix          "dc=zerezo,c=org"
192 #updatedn <dn>
193 #updateref <url>
197 # LDBM BACKEND SPECIFIC DIRECTIVES
200 # Memory cache size
201 cachesize       1000
203 # Cache size for each opened index
204 dbcachesize     100000
206 # Deactivate database lock
207 dbnolocking
209 # Directory that contains lbdm-files
210 directory       /var/openldap-ldbm
212 # Defines the index to maintain
213 index   objectClass,uid,uidNumber,gidNumber,memberUid   eq
214 index   cn,mail,surname,givenname                       eq,subinitial
216 # Droits par default pour les nouveaux index
217 mode    0600
219 # SSL encryption
220 TLSCertificateFile /etc/openldap/ssl/slapd.pem
221 TLSCertificateKeyFile /etc/openldap/ssl/slapd.key
222 TLSCACertificateFile /etc/openldap/ssl/slapd.pem
225 # End of /etc/openldap.slapd.conf
226 #################################
229 Now, we have to configure the log mechanism.
230 U have to add this line in /etc/syslog.conf :
231 local4.*     -/var/log/openldap.log
235 3) The starting script /etc/rc.d/init.d/openldap
236 ------------------------------------------------
238 #!/bin/sh
239 # Begin $rc_base/init.d/
241 # Based on sysklogd script from LFS-3.1 and earlier.
242 # Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org
244 source /etc/sysconfig/rc
245 source $rc_functions
247 case "$1" in
248         start)
249                 echo -n "Démarrage du serveur openldap..."
250                 /opt/network/libexec/slapd -h "ldap:///  ldaps:///" -d 1
251                 ;;
253         stop)
254                 echo -n "Arrêt du serveur openldap..."
255                 kill -INT `cat /var/run/slapd.pid`
256                 ;;
257         reload)
258                 echo -n "Rechargement du serveur openldap..."
259                 reloadproc openldap
260                 ;;
262         restart)
263                 $0 stop
264                 sleep 1
265                 $0 start
266                 ;;
268         status)
269                 statusproc
270                 ;;
272         *)
273                 echo "Usage: $0 {start|stop|reload|restart|status}"
274                 exit 1
275                 ;;
276 esac
277 # End $rc_base/init.d/
279 Add the link in 
280 /etc/rc.d/rc*.d
283 3) Starting the server
284 ---------------------
286 First, start the openldap server with the script.
287 If it fails, try to launch it by hand with debug mode 
288 with the following command :
290 $ /usr/libexec/slapd -d 1
292 Then, execute the following test and checks wether there are no error :
294 ldapsearch -b 'dc=zerezo,dc=org' 'objectclass=*'
298 4) Importing data for OPENLDAP
299 ------------------------------
301 Now, you have to write the file containing your user data.
302 My openldap database has the following structure :
305 |- zerezo
306         |- people
307                 | zarba
308                 | karine
309         |- groups
310                 | wheel
311                 | users
313 Here the file in the LDIF format :
315 # Begin of /tmp/newentry
317 dn: dc=zerezo, dc=org
318 objectclass: top
319 objectclass: organizationalUnit
320 ou: zerezo
322 dn:ou=groups, dc=zerezo, dc=org
323 objectclass: top
324 objectclass: organizationalUnit
325 ou: groups
327 dn:ou=people, dc=zerezo, dc=org
328 objectclass: top
329 objectclass: organizationalUnit
330 ou: people
332 dn: cn=Michenaud Laurent, ou=people, dc=zerezo, dc=org
333 cn: Michenaud Laurent
334 sn: Zarba
335 objectclass: top
336 objectclass: person
337 objectclass: posixAccount
338 objectclass: shadowAccount
339 uid:zarba
340 userpassword:{crypt}sfsdfdsfd
341 uidnumber:1002
342 gidnumber:103
343 gecos:Michenaud Laurent
344 loginShell:/bin/bash
345 homeDirectory: /home/zarba
346 shadowLastChange:10877
347 shadowMin: 0
348 shadowMax: 999999
349 shadowWarning: 7
350 shadowInactive: -1
351 shadowExpire: -1
352 shadowFlag: 0
354 dn: cn=Michenaud Karine, ou=people, dc=zerezo, dc=org
355 cn: Michenaud Karine
356 sn: Buffy
357 objectclass: top
358 objectclass: person
359 objectclass: posixAccount
360 objectclass: shadowAccount
361 uid:karine
362 userpassword:{crypt}sfsdfdsfd
363 uidnumber:1002
364 gidnumber:103
365 gecos:Michenaud Karine
366 loginShell:/bin/bash
367 homeDirectory: /home/karine
368 shadowLastChange:10877
369 shadowMin: 0
370 shadowMax: 999999
371 shadowWarning: 7
372 shadowInactive: -1
373 shadowExpire: -1
374 shadowFlag: 0
377 dn: cn=wheel, ou=groups, dc=zerezo, dc=org
378 objectclass: top
379 objectclass: posixGroup
380 cn: wheel
381 gidnumber: 103
382 memberuid: zarba
384 dn: cn=users, ou=groups, dc=zerezo, dc=org
385 objectclass: top
386 objectclass: posixGroup
387 cn: users
388 gidnumber: 100
389 memberuid: zarba
390 memberuid: karine
392 # End of file /tmp/newentry
394 Import the file in your database with the following command :
396 $ ldapadd -f /tmp/newentry -D "cn=Manager,dc=zerezo,dc=org" -w secret
399 Then, you can execute the following test for fun :
401 ldapsearch -b 'dc=zerezo,dc=org' 'cn=Michenaud Laurent'
402 ldapsearch -u -b 'dc=zerezo,dc=org' 'cn=Michenaud Laurent' sn mail 
404 See in the LDAP Howto at www.linuxdoc.org to modify or
405 delete some ldap records.
409 III - PAM_LDAP
410 ==============
412 Download here : ftp://ftp.padl.com/pub/pam_ldap.tgz
414 1) Installation
416 Strange installation but i didnot find any other way
417 to make compilation working.
419 ./configure --with-ldap-lib=openldap --with-ldap-dir=/usr
421 make
422 make
424 sed 's|depcomp = $(SHELL) $(top_srcdir)/depcomp||' \
425 Makefile > Makefile.tmp &&
426 mv Makefile.tmp Makefile
428 make
429 make install
431 # We copy all the pam service config files in /etc/pam.d/
432 cp pam.d/* /etc/pam.d/
437 IV - NSS LDAP
438 =============
440 download here : ftp://ftp.padl.com/pub/nss_ldap.tgz
442 1) Installation
444 ./configure --enable-schema-mapping --with-ldap-lib=openldap --with-ldap-dir=/usr
446 make
447 make
449 sed 's|depcomp = $(SHELL) $(top_srcdir)/depcomp||' \
450 Makefile > Makefile.tmp &&
451 mv Makefile.tmp Makefile
453 make
454 make install
456 2) Configuration
458 You have to edit the /etc/nsswitch.conf like this :
460 passwd: files ldap
461 group:  files ldap
462 shadow: files ldap
464 3) LDAP client configuration file
466 # Begin of /etc/ldap.conf
468 # Your LDAP server. Must be resolvable without using LDAP.
469 host 127.0.0.1
471 # The distinguished name of the search base.
472 base dc=zerezo,dc=org
474 # version de ldap
475 ldap_version 3
477 # The distinguished name to bind to the server with.
478 # Optional: default is to bind anonymously.
479 #binddn cn=proxyuser,dc=padl,dc=com
481 # The credentials to bind with. 
482 # Optional: default is no credential.
483 #bindpw secret
485 # The distinguished name to bind to the server with
486 # if the effective user ID is root. Password is
487 # stored in /etc/ldap.secret (mode 600)
488 #rootbinddn cn=manager,dc=padl,dc=com
490 # The port.
491 # Optional: default is 389.
492 port 636
494 # The search scope.
495 #scope sub
496 #scope one
497 #scope base
499 # Search timelimit
500 #timelimit 30
502 # Bind timelimit
503 #bind_timelimit 30
505 # Idle timelimit; client will close connections
506 # (nss_ldap only) if the server has not been contacted
507 # for the number of seconds specified below.
508 #idle_timelimit 3600
510 # Filter to AND with uid=%s
511 pam_filter objectclass=posixAccount
513 # The user ID attribute (defaults to uid)
514 pam_login_attribute uid
516 # Search the root DSE for the password policy (works
517 # with Netscape Directory Server)
518 #pam_lookup_policy yes
520 # Check the 'host' attribute for access control
521 # Default is no; if set to yes, and user has no
522 # value for the host attribute, and pam_ldap is
523 # configured for account management (authorization)
524 # then the user will not be allowed to login.
525 #pam_check_host_attr yes
527 # Group to enforce membership of
528 #pam_groupdn cn=PAM,ou=Groups,dc=padl,dc=com
530 # Group member attribute
531 #pam_member_attribute uniquemember
532 pam_member_attribute memberuid
534 # Specify a minium or maximum UID number allowed
535 #pam_min_uid 0
536 #pam_max_uid 0
538 # Template login attribute, default template user
539 # (can be overriden by value of former attribute
540 # in user's entry)
541 #pam_login_attribute userPrincipalName
542 #pam_template_login_attribute uid
543 #pam_template_login nobody
545 # HEADS UP: the pam_crypt, pam_nds_passwd,
546 # and pam_ad_passwd options are no
547 # longer supported.
549 # Do not hash the password at all; presume
550 # the directory server will do it, if
551 # necessary. This is the default.
552 #pam_password clear
554 # Hash password locally; required for University of
555 # Michigan LDAP server, and works with Netscape
556 # Directory Server if you're using the UNIX-Crypt
557 # hash mechanism and not using the NT Synchronization
558 # service. 
560 pam_password crypt
562 # Remove old password first, then update in
563 # cleartext. Necessary for use with Novell
564 # Directory Services (NDS)
565 #pam_password nds
567 # Update Active Directory password, by
568 # creating Unicode password and updating
569 # unicodePwd attribute.
570 #pam_password ad
572 # Use the OpenLDAP password change
573 # extended operation to update the password.
574 #pam_password exop
576 # RFC2307bis naming contexts
577 # Syntax:
578 # nss_base_XXX          base?scope?filter
579 # where scope is {base,one,sub}
580 # and filter is a filter to be &'d with the
581 # default filter.
582 # You can omit the suffix eg:
584 # nss_base_passwd       ou=People,
585 # to append the default base DN but this
586 # may incur a small performance impact.
587 #nss_base_passwd        ou=People,dc=padl,dc=com?one
588 #nss_base_shadow        ou=People,dc=padl,dc=com?one
589 #nss_base_group         ou=Group,dc=padl,dc=com?one
590 #nss_base_hosts         ou=Hosts,dc=padl,dc=com?one
591 #nss_base_services      ou=Services,dc=padl,dc=com?one
592 #nss_base_networks      ou=Networks,dc=padl,dc=com?one
593 #nss_base_protocols     ou=Protocols,dc=padl,dc=com?one
594 #nss_base_rpc           ou=Rpc,dc=padl,dc=com?one
595 #nss_base_ethers        ou=Ethers,dc=padl,dc=com?one
596 #nss_base_netmasks      ou=Networks,dc=padl,dc=com?ne
597 #nss_base_bootparams    ou=Ethers,dc=padl,dc=com?one
598 #nss_base_aliases       ou=Aliases,dc=padl,dc=com?one
599 #nss_base_netgroup      ou=Netgroup,dc=padl,dc=com?one
601 # attribute/objectclass mapping
602 # Syntax:
603 #nss_map_attribute      rfc2307attribute        mapped_attribute
604 #nss_map_objectclass    rfc2307objectclass      mapped_objectclass
606 # configure --enable-nds is no longer supported.
607 # For NDS now do:
608 #nss_map_attribute uniqueMember member
610 # configure --enable-mssfu-schema is no longer supported.
611 # For MSSFU now do:
612 #nss_map_objectclass posixAccount User
613 #nss_map_attribute uid msSFUName
614 #nss_map_attribute uniqueMember posixMember
615 #nss_map_attribute userPassword msSFUPassword
616 #nss_map_attribute homeDirectory msSFUHomeDirectory
617 #nss_map_objectclass posixGroup Group
618 #pam_login_attribute msSFUName
619 #pam_filter objectclass=User
620 #pam_password ad
622 # configure --enable-authpassword is no longer supported
623 # For authPassword support, now do:
624 #nss_map_attribute userPassword authPassword
625 #pam_password nds
627 # For IBM SecureWay support, do:
628 #nss_map_objectclass posixAccount aixAccount
629 #nss_map_attribute uid userName
631 #nss_map_attribute gidNumber gid
632 #nss_map_attribute uidNumber uid
633 #nss_map_attribute userPassword passwordChar
634 #nss_map_objectclass posixGroup aixAccessGroup
635 #nss_map_attribute cn groupName
636 #nss_map_attribute uniqueMember member
637 #pam_login_attribute userName
638 #pam_filter objectclass=aixAccount
639 #pam_password clear
641 # Netscape SDK LDAPS
642 #ssl on
644 # Netscape SDK SSL options
645 #sslpath /etc/ssl/certs/cert7.db
647 # OpenLDAP SSL mechanism
648 # start_tls mechanism uses the normal LDAP port, LDAPS typically 636
649 ssl start_tls
650 ssl on
652 # OpenLDAP SSL options
653 # Require and verify server certificate (yes/no)
655 # Default is "no"
656 #tls_checkpeer yes
658 # CA certificates for server certificate verification
659 # At least one of these are required if tls_checkpeer is "yes"
660 #tls_cacertfile /etc/ssl/ca.cert
661 #tls_cacertdir /etc/ssl/certs
663 # SSL cipher suite
664 # See man ciphers for syntax
665 #tls_ciphers TLSv1
667 # Client certificate and key
668 # Use these, if your server requires client authentication.
669 #tls_cert
670 #tls_key
673 4) Check the permission
675 -rw-r--r--  root.root /etc/ldap.conf
676 -rw-------  root.root /etc/openldap/slapd.conf
679 5) Examples of extension of nss_ldap
681 You can put your services definition in your openldap too.
682 Here is an example ldif file for services :
684 dn:ou=tcpIp, dc=zerezo, dc=org
685 objectclass: top
686 objectclass: organizationalUnit
687 ou: tcpIp
689 dn: cn=swat,ou=tcpIp,dc=zerezo,dc=org
690 cn: swat
691 objectclass: ipService
692 ipServicePort: 901
693 ipServiceProtocol: tcp
694 cn: swat
696 dn: cn=cups,ou=tcpIp,dc=zerezo,dc=org
697 cn: cups
698 objectclass: ipService
699 ipServicePort: 631
700 ipServiceProtocol: tcp
701 cn: cups
703 Then just add "ldap" in nsswitch.conf for the line services.
705 What is bad is that aliases are not managed in the schema.
707 You can define too your networks, protocols and rpc in the
708 openldap database.
711 ==========================
712 V - PROFTPD auth with LDAP
713 ==========================
715 It just speaks about adding LDAP to proftpd...
716 It doesnot speak about installing and configuring proftpd...
718 download here :  http://horde.net/~jwm/software/mod_ldap/mod_ldap-2.8.1.tar.bz2
720 1) Installation
722 Proftpd-1.2.4 provides only mod_ldap-2.7.6 so you have to download the
723 latest version of the module.
725 Extract the module archive and copy mod_ldap.c in your proftpd-1.2.4/contrib/
727 Proftpd can work with LDAP SSL/TLS. To enable SSL/TLS, edit mod_ldap.c
728 and uncomment /* #define USE_LDAPV3_TLS */
730 Recompile proftpd with the option : --with-modules=mod_ldap
733 2) Configuration
735 In your proftpd.conf, just add :
737 LDAPServer localhost
738 LDAPDNInfo cn=Manager,dc=zerezo,dc=org password
739 LDAPDoAuth on "dc=zerezo,dc=org"
740 LDAPUseTLS on
742 I had to add these parameters for the global section and for
743 each virtual host to make it work
745 You have to create the /etc/ftpusers, /etc/shells too
748 ============================
749 VII - POSTFIX Auth with LDAP
750 ============================
752 Postfix doesnot work with LDAP-TLS/SSL.
754 1) Installation
756 Unpack the postfix tarballs and execute the following commands, 
757 and then compile like you are used to to it.
759 make tidy
760 make makefiles CCARGS="-I/usr/local/include -DHAS_LDAP" \
761         AUXLIBS="-L/usr/local/lib -lldap -L/usr/local/lib -llber"
764 2) Configuration in your main.cf files.
766 Here is a basic configuration for integrating ldap in postfix.
767 I know you can do more like integrating your files /etc/aliases, 
768 sender_canonical and recipient_canonicial in the openldap database.
770 alias_maps = hash:/etc/aliases, ldap:ldapsource
772 ldapsource_server_host = localhost
773 ldapsource_server_port = 389
774 ldapsource_search_base = dc=zerezo, dc=org
775 ldapsource_timeout = 5
776 #ldapsource_query_filter=mailacceptinggeneralid=%s
777 #ldapsource_domain = postfix.org, hash:/etc/postfix/searchdomains
778 #ldapsource_result_attribute = mailbox,maildrop
779 #ldapsource_special_result_attribute = member
780 #ldapsource_bind = no
781 #ldapsource_bind_dn = uid=postfix, dc=your, dc=com
782 #ldapsource_bind_pw = postfixpw
785 ===================
786 IX - OPENLDAP UTILS
787 ===================
789 1) GQ, an interface to browse/edit an ldap database
791 download here : http://biot.com/gq/download/gq-0.4.0.tar.gz
793 ./configure
794 make
795 make install
797 2) Directory Administrator
799 A great program to manager users and group
800 through openldap
802 download here :
803 http://prdownloads.sourceforge.net/directoryadmin/directory_administrator-1.1.3.tar.gz
805 ./configure
806 make
807 make install
810 =========
811 X - SAMBA
812 =========
814 1) Samba installation
816 I recommend Samba 2.2.2_HEAD
818 cd sources
819  ./configure --prefix=/opt/network \
820         --with-smbmount \
821         --with-configdir=/etc/samba \
822         --with-privatedir=/etc/samba/private \
823         --with-acl-support \
824         --with-profile \
825         --disable-static \
826         --with-ldapsam \
827         --with-syslog \
828         --with-ssl \
829         --with-ssl-lib=/opt/network/lib \
830         --with-ssl-include=/opt/network/include \
831         --with-pam \
832         --with-pam_smbpass
834 make
835 make install
836 cd ..
837 cp examples/LDAP/samba.schema /etc/openldap/schema/
840 2) Configuration
842 Add in /etc/openldap/slapd.conf :
843 include         /etc/openldap/schema/samba.schema
845 access to attrs=lmPassword,ntPassword
846         by 'cn=samba,ou=SystemAccounts,dc=zerezo,dc=Org'
847         write by self write by * auth
850 Edit samba.schema and delete the displayName attribute
851 because we have already it.
853 Then we need to precise the password for accessing the LDAP server
854 smbpasswd -w secret
858 ==============
859 X - CONCLUSION
860 ==============
862 I wrote this hint while discovering openldap.
863 There may be some errors and it may be incomplete.
865 Feel free to modify this hint to improve it :)
867 TO DO :
868         - Adding security rules
869         - exporting an entire LDAP ( backup )
870         - Samba Auth with LDAP ( Completing )
871         - Postfix more integration
872         - Replication
873         - Maybe Kerberos
874