Installation goals:
* use Kerberos for user authentication to the system and for access to the samba shared directories
* use encrypted access to the LDAP interface of the MS Active Directory
Useful debugging tools:
Ethereal - ** THIS IS MUST-HAVE TOOL HERE** - for tracing communication between your Linux machine and the AD Server
http://www.ethereal.com/
LDAP browser - for accessing the AD through ldap and viewing information stored there (you can see the same iformation in the MS ADSI Editor, too) You can use it to check directory structure and reading/editing of the information stored there. I am using the java LDAP browser from this page:
http://www.iit.edu/~gawojar/ldap/
Unfortunatelly, this browser doesn't play well wit the blackdown-jdk, but works fine with the sun-jdk.
strace (dev-util/strace) - debugging utility, which intercepts and records the system calls called by a process and the signals which are received by a process. For example, to find out, which files are opened during execution of the getent passwd command, you can use this command:
Code: Select all
strace -e open getent passwd
Microsoft Services For Unix, or SFU (current version is 3.5). You can download this software (approx. 350MB) on this site:
http://www.microsoft.com/windows/sfu/do ... efault.asp
(You have to be registered on the MS .net passport before downloading.) In previous posts, there was recommended the AD4UNIX software, but it seems to be abandoned now, while the MS SFU is for free now and still developping.
During the installation of the MS SFU choose only the "Server for NIS" option. This will extend the AD schema and install the MMC snap-in (similar to the AD4UNIX one). Verify, that you are able to create users with UNIX attributes and inspect those users from the LDAP side. When the installation is finished and the server is restarted, you can test functionality of the SFU MMC snap-in and verify the SFU attributes in the LDAP browser. As the NIS server will not be needed, stop the Server for NIS service and chnge it's startup type to Manual.
Note: The Server for NIS service among other things performs password synchronization between the Kerberos and LDAP msSFU30Password attribute. Synchronized passwords are however truncated to the 8 characters and they aren't well encrypted - that's another reason to stop te Server for NIS service.
Needed packages to emerge:
samba - make sure, that it's the 3.x version
openlssl - needed for ssl
openldap - we will need this for client ldap searches
cyrus-sasl - Simple Authentication and Security Layer - for basic encryption of ldap binds and searches
ntp - We will use the ntp-client for time synchronization (for proper Kerberos functioning)
mit-krb5 - the MIT Kerberos
pam - the Pluggable Authentication Module base
pam_krb5 - kerberos pam module (note, that pam_ldap module will not be needed). There are some problems to emerge the 1.0 version, see other posts on these forums. It seems to have problems with password change, too.
nss_ldap - LDAP module for name switch system (enables redirection of searches for users, groups, etc. to ldap)
Note: Make sure, that nss_ldap is compilled with the --enable-schema-mapping parameter enabled, otherwise it will be of no use here.
Let's assume following initial confguration:
- MS Windows Server:
Servername: SFUSRV
AD Domain: DC=SFU,DC=ACME,DC=COM
DNS Name: sfusrv.sfu.acme.com
Server's IP address: 192.168.1.20
Configuration details:
* Windows 2003 Server
* Active Directory (Directory Master)
* DNS&DHCP integrated into AD
* WINS service
* Local clock synced to a ntp server
* If you plan to use SSL, also Enterprise Certification Authority would be handy (to issue certificates for SSL).
Sample users:
First Name: Tom
Last Name: Sawyer
User logon lame: toms@sfu.acme.com
Password: PASSword.
LDAP distinguished name: cn=Tom Sawyer,cn=Users,dc=sfu,dc=acme,dc=com
First Name: Huck
Last Name: Finn
User logon lame: huckf@sfu.acme.com
Password: PASSword.
LDAP distinguished name: cn=Huck Finn,cn=Users,dc=sfu,dc=acme,dc=com
Gentoo Linux:
Hostname: Gent
DNS Name: gent.sfu.acme.com
IP address: 192.168.1.28
Configuration details:
* USE settings: kerberos ldap samba sasl ssl (set them in the /etc/make.conf; I recommend to use the ufed tool for this)
* ACCEPT_KEYWORDS="~x86" (set them in the /etc/make.conf, too) - in this way, the latest available packages for the intel platform will be installed.
Before the Kerberos is configured, make sure, that you have synchronized local clock wth the ntp server. You can do it using the ntp-client module. It's configuration file is the /etc/conf.d/ntp-client.
Code: Select all
# /etc/conf.d/ntp-client
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-x86/net-misc/ntp/files/ntp-client.confd,v 1.2 2003/09/19 17:50:37 vapier Exp $
# Command to run to set the clock initially
NTPCLIENT_CMD="ntpdate"
# Options to pass to the above command
NTPCLIENT_OPTS="-b tik.cesnet.cz"
Code: Select all
# etc/krb5.conf
[libdefaults]
# renew_lifetime = 18000
default_realm = SFU.ACME.COM
default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc
default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc
dns_lookup_realm = true
dns_lookup_kdc = true
clockskew = 120
[realms]
SFU.ACME.COM = {
kdc = sfusrv.sfu.acme.com:88
admin_server = sfusrv.sfu.acme.com:464
}
[domain_realm]
.sfu.acme.com = SFU.ACME.COM
sfu.acme.com = SFU.ACME.COM
[kdc]
profile = /etc/krb5kdc/kdc.conf
[logging]
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmin.log
default = FILE:/var/log/krb5lib.log
[appdefaults]
pam = {
debug = false
forwardable = true
krb4_convert = false
}
Code: Select all
gent root # kinit toms
Password for toms@SFU.ACME.COM:
gent root # klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: toms@SFU.ACME.COM
Valid starting Expires Service principal
03/25/04 14:46:58 03/26/04 00:47:02 krbtgt/SFU.ACME.COM@SFU.ACME.COM
renew until 03/26/04 14:46:58
Code: Select all
#/etc/passwd
.
.
huckf:x:10004:10004:Local AD user:/home/huckf:/bin/bash
Code: Select all
#/etc/shadow
.
.
huckf:*K*:10004:0:::::
Now, we need to create a Kerberos principal and corresponding keytab file for our Linux workstation on the Windows server. Let's choose one of Windows user accounts for this. There will be added the attribute Kerberos Service Principal for the Linux computer to this user account.
BEWARE: It is not tolerable to create Kerberos Service Principal with the same name in more user accounts. In such case, Kerberos would not be able to authenticate it correctly.
Following command has to performed for each Linux computer on a different user account:
Code: Select all
C:> ktpass -princ nssldap/gent@SFU.ACME.COM -pass PASSword.
-mapuser toms@SFU.ACME.COM -out gent_keytab
Targeting domain controller: sfusrv.sfu.acme.com
Successfully mapped nssldap/linux to toms.
Key created.
Output keytab to gent_keytab:
Keytab version: 0x502
keysize 49 nssldap/linux@SFU.ACME.COM ptype 1 (KRB5_NT_PRINCIPAL) vno 3 etype 0x3 (D
ES-CBC-MD5) keylength 8 (0xd34c57321fd334b5)
Account toms has been set for DES-only encryption.
Code: Select all
gent root # ktutil
ktutil: rkt gent_keytab
ktutil: list
slot KVNO Principal
---- ---- -------------------------------------------------------
1 3 nssldap/gent@SFU.ACME.COM
ktutil: wkt /etc/krb5.keytab
ktutil: q
Let's now create a script for automatic update of the Kerberos ticket for the LDAP. After the command execution, the root's Kerberos ticket cache (/tmp/krb5cc_0) will be updated.
/sbin/kerbinit.sh
Code: Select all
#!/bin/sh
kinit -k -S ldap/sfusrv.sfu.acme.com nssldap/gent
chmod 600 /tmp/krb5cc_0
Code: Select all
gent root # klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: nssldap/gent@SFU.ACME.COM
Valid starting Expires Service principal
03/25/04 16:10:27 03/26/04 02:10:26 ldap/sfusrv.sfu.acme.com@ SFU.ACME.COM
renew until 03/26/04 16:10:27
You should add this script to the root's crontab file (/var/spool/cron/crontabs/root). Following example will call the kerbinit.sh every 2 hours:
Code: Select all
# /var/spool/cron/crontabs/root
# /etc/crontab
.
.
* */2 * * * sh /sbin/kerbinit.sh
Code: Select all
.
.
# This is a good place to load any misc.
# programs on startup ( 1>&2 )
sh /sbin/kerbinit.sh
LDAP configuration
Another important step is to make correct settings in the LDAP config file. In the Gentoo Linux there are actually two LDAP config files - /etc/ldap.conf and /etc/openldap/ldap.conf respectively. If you want to use only one file for the LDAP configuration, (in this case there is nothing wrong about that), you can make a symbolic link between them - as for example:
Code: Select all
ln -s /etc/ldap.conf /etc/openldap/ldap.conf
Code: Select all
LDAPCONF="/etc/ldap.conf"
Code: Select all
host sfusrv.sfu.acme.com
base dc=sfu,dc=acme,dc=com
# scope one
scope sub
# binddn cn=Tom Sawyer,cn=Users,dc=sfu,dc=acme,dc=com
# bindpw PASSword.
# rootbinddn cn= Tom Sawyer,cn=Users,dc=sfu,dc=acme,dc=com
# rootbind password is in the /etc/ldap.secret
# nss_map_objectclass shadowAccount user
# nss_map_attribute userPassword msSFU30Password
nss_map_objectclass posixAccount user
nss_map_attribute uidNumber msSFU30UidNumber
nss_map_attribute uid msSFU30Name
nss_map_attribute gidNumber msSFU30GidNumber
nss_map_attribute homeDirectory msSFU30HomeDirectory
nss_map_attribute loginShell msSFU30LoginShell
nss_map_attribute gecos msSFU30Gecos
nss_map_objectclass posixGroup group
nss_map_attribute gid msSFU30Name
nss_map_attribute uniqueMember msSFU30PosixMember
# nss_map_attribute uniqueMember member
# nss_map_attribute memberUid msSFU30MemberUid
pam_login_attribute msSFU30Name
pam_filter objectclass=User
pam_password ad
nss_base_passwd cn=Users,dc=sfu,dc=acme,dc=com
# nss_base_passwd dc=sfu,dc=acme,dc=com
nss_base_shadow dc=sfu,dc=acme,dc=com
nss_base_group cn=Users,dc=sfu,dc=acme,dc=com
# nss_base_group dc=sfu,dc=acme,dc=com
nss_base_hosts Computers,dc=sfu,dc=acme,dc=com
use_sasl on
sasl start_tls
# ssl on
# tls_cacertfile /etc/ssl/certs/cacert.cer
# sslpath /etc/ssl/certs/
# krb5_ccname FILE:/etc/.ldapcache
The lines beginning with "nss_base_passwd" and "nss_base_group" are determining the bases (or contexts in the LDAP tree), from which searches for users and groups are made. You can enter more than one base here. By the proper setting of the search bases, we can make LDAP searches more effective. Note, that if the nss_ldap was not compilled using the --enable-schema-mapping parameter, attributes mapping will not take place and the LDAP searches will be performed for the original unix parameters.
The lines containing the binddn, bindpw and rootbinddn (credentals for the authentifcation to the LDAP directory), are commented out here, as there will be used the Kerberos authentifcation.
The line beginning with scope determines, wheather the child parts of the LDAp contexts should be searched, too (sub - search in all sub-contexts, one - search only the current context).
Ending part of the ldap.conf file is containing settings for the sasl authentification (Simple Authentication and Security Layer) and basc encryption tls (Transport Layer Security).
To set up the ssl encryption, you have to make the Linux computer to trust the ssl certificate of the LDAP server, otherwise you can find the Unknown CA error message in the captured ssl handshake packets (use the Ethereal for it).
I am not sure, what is the proper procedure for making the Linux to trust to the ssl certificate. One of the promising solutions could be to copy the files named *.db from the working profile directory of the Mozilla browser to the /etc/ssl/certs directory. But first, you have to point the Mozilla to the secure LDAP port of the server and accept it's certificate permanently.
Testing LDAP access
You can test different modes of access to the LDAP directory using the ldapsearch command. Output of this command should be a list of LDAP objects (and their attributes), which are matched bz the LDAP request (in the following example it is the objectclass=user). In the beginning, try to enter most of the parameters explicitly on the command line - in this way the /etc/ldap.conf settings are bypassed. For debugging, you can also add the parameter -d N, where N is debug level (for example -d 5)
Code: Select all
gent root # ldapsearch -x -s one -b " dc=sfu,dc=acme,dc=com" -D "cn=Tom Sawyer,cn=Users,dc=sfu,dc=acme,dc=com" \
> -w PASSword. objectclass=user
Code: Select all
gent root # ldapsearch objectclass=user |grep msSFU30Name
Code: Select all
ip host gent
- GSS-API Token
GSS-API
krb5_blob
Kerberos
Ticket
The Name Switch System
Now, it is necessary to configure the Linux system to look for the user and group information in the LDAP directory, too. This should be made in the /etc/nsswitch.conf file by adding the keyword ldap to the lines for passwd a group.
Code: Select all
# /etc/nsswitch.conf:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/nsswitch.conf,v 1.4 2002/11/18 19:39:22 azarah Exp $
passwd: files ldap
shadow: files
group: files ldap
# passwd: db files nis
# shadow: db files nis
# group: db files nis
hosts: files dns
networks: files dns
services: db files
protocols: db files
rpc: db files
ethers: db files
netmasks: files
netgroup: files
bootparams: files
automount: files
aliases: files
You can test the functionality of the NSS by using for example the getent or id command:
Code: Select all
gent root # getent passwd
root:x:0:0:root:/root:/bin/bash
.
.
toms:x:10003:10002:Tom Sawyer:/home/toms:/bin/sh
gent root # id toms
uid=10003(toms) gid=10002(tstgroup) groups=10002(tstgroup)
The PAM configuration
To be able to authenticate users via the Kerberos, you have to add the Kerberos authentication module to the PAM configuration files. There are several configuration files, their names are corresponding to the names of the programs, which are performing the user authentication. I am listing here the most common PAM configuration files. These files are located in the /etc/pam.d directory. So you should append the lines referring to the pam_krb5.so module.
Note: The sufficient control token is defining, that for a successful authentication it is sufficient to be authenticated by the specified pam module (even in a case, when authentication made by previous "required" modules failed). The try_first_pass parameter is instructing the pam module, that the password supplied to the previous pam module should be tried first. In this way, there will not be invoked another prompt for the password. To debug the pam modules, you can also add the debug parameter, which will cause loggig of the debug messages into log file (/var/log/auth.log).
/etc/pam.d/login
Code: Select all
#%PAM-1.0
auth required /lib/security/pam_securetty.so
auth sufficient /lib/security/pam_krb5.so try_first_pass
auth required /lib/security/pam_stack.so service=system-auth
auth required /lib/security/pam_nologin.so
account sufficient /lib/security/pam_krb5.so
account required /lib/security/pam_stack.so service=system-auth
password sufficient /lib/security/pam_krb5.so
password required /lib/security/pam_stack.so service=system-auth
session sufficient /lib/security/pam_krb5.so
session required /lib/security/pam_stack.so service=system-auth
session optional /lib/security/pam_console.so
Code: Select all
#%PAM-1.0
auth sufficient /lib/security/pam_krb5.so debug
auth required /lib/security/pam_stack.so service=system-auth
account required /lib/security/pam_stack.so service=system-auth
password sufficient /lib/security/pam_krb5.so debug
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_stack.so service=system-auth
session sufficient /lib/security/pam_krb5.so
session required /lib/security/pam_stack.so service=system-auth
session required /lib/security/pam_limits.so
Code: Select all
#%PAM-1.0
auth required /lib/security/pam_env.so
auth sufficient /lib/security/pam_krb5.so try_first_pass
auth sufficient /lib/security/pam_unix.so try_first_pass likeauth nullok
auth required /lib/security/pam_deny.so
account sufficient /lib/security/pam_krb5.so debug
account required /lib/security/pam_unix.so
password required /lib/security/pam_krb5.so debug
password required /lib/security/pam_cracklib.so retry=3
password sufficient /lib/security/pam_unix.so nullok md5 shadow use_authtok
password required /lib/security/pam_deny.so
session required /lib/security/pam_limits.so
session required /lib/security/pam_unix.so
session sufficient /lib/security/pam_krb5.so
The samba configuration
The samba configuration is located in the main configuration file /etc/samba/smb.conf. Following is the example of the smb.conf for the example MS network and the SFUSRV Windows 2K3 server.
/etc/samba/smb.conf
Code: Select all
# Separate domain and username with '+', like DOMAIN+username
[global]
netbios name = GENT
server string = %h server (Samba %v)
socket options = TCP_NODELAY SO_RCVBUF=16384 SO_SNDBUF=16384
idmap uid = 10000-20000
idmap gid = 10000-20000
winbind enum users = yes
winbind enum groups = yes
winbind uid = 10000-20000
winbind gid = 10000-20000
winbind use default domain = yes
template shell = /bin/bash
template homedir = /home/%D/%U
workgroup = SFU
os level = 10
winbind enum groups = yes
socket address = 192.168.1.28
preferred master = no
winbind separator = +
max log size = 512
log file = /var/log/samba3/log.%m
dns proxy = no
realm = SFU.ACME.COM
security = ADS
encrypt passwords = yes
password server = sfusrv.sfu.acme.com
wins server = 192.168.1.20
wins proxy = no
# Shares section
[SharedDir]
comment = Shared directory
writeable = yes
path = /home/share
force user = huckf
Code: Select all
gent root # net ads join -U Administrator
Administrator password:
Using short domain name -- SFU
Joined 'GENT' to realm 'SFU.ACME.COM'
Final configuration
In the end, the needed services and daemons should be added to the list of the services launched at startup at the Linux computer. You should add these:
- * ntp-client - for the time synchroization
* samba - for sharing files via the SMB protocol
* nscd (Name Service Cache Daemon) - for alleviating the communication with the LDAP server and for speed-up of the LDAP searches
Code: Select all
rc-update add ntp-client default
rc-update add samba default
rc-update add nscd default




