Introduction

The Red Hat 9 GNU/Linux distribution is easy to setup as a DAS client. Red Hat provides updated Kerberos, PAM, and NIS binary RPM packages. Configuration is fairly simple. Red Hat 9 also supports the Name Service Cache Daemon, or NSCD, which is installed by default. This reduces the load on the NIS servers and the network by caching lookups for a period of time. It also helps with performance when the DAS-M (master) is unavailable.

Red Hat 9 comes with the MIT version of Kerberos V. Of all the distributions I tested, Red Hat, Fedora Core, and Mandrake were the simplest to setup as DAS clients. Red Hat also has a nice configuration tool called "authconfig" (or "authconfig-gtk") for setting up name services and authentication. Unfortunately, this tool does not configure PAM correctly for our particular application, so we will not use it. If you run "authconfig", it will overwrite your working config.

NOTE:   These instructions should also work for Red Hat 7.3 and Red Hat 8, and they may actually work on Red Hat 7.1 and 7.2 as well.

Assumptions

These Red Hat DAS client instructions assume the following:

The last point is VERY important. If you are running telnet, ftp, rlogind, apache, etc. with those services configured to allow authentication of users with plaintext over the network, there is not much point in using Kerberos for secure authentication. The assumption is that you will only be logging in remotely via SSH2 or SSL/TLS encrypted sessions. This does NOT, however, preclude you from using Kerberized versions of TELNET or RLOGIN as long as they are configured to disallow plaintext authentication methods.

Step-by-step Instructions

Step 1: Software Installation

Although some of the libraries and RPMs are already installed, we will get the latest RPM's from Red Hat and install ALL of the necessary RPM packages. At the time of this writing, these were the relevant packages:

Optional Packages:

In order to install/upgrade these packages, use this command from a newly-created directory containing the packages:

rpm -Uvh *.rpm

Step 2: Modify Configuration Files

Here is a list of the config files that must be modified:

Before you do anything else, backup the orginal config files to another directory, or add the .org extension to them.

First, let's add entries in /etc/hosts for the DAS servers. These will be used by ypbind (the NIS client):

10.10.22.42 das-m
10.10.22.40 das-s

Now, let's configure /etc/yp.conf with information about our NIS servers. This file is used by the ypbind daemon.

# /etc/yp.conf - ypbind configuration file
# Valid entries are
#
#domain NISDOMAIN server HOSTNAME
#       Use server HOSTNAME for the domain NISDOMAIN.
#
#domain NISDOMAIN broadcast
#       Use  broadcast  on  the local net for domain NISDOMAIN
#
#ypserver HOSTNAME
#       Use server HOSTNAME for the  local  domain.  The
#       IP-address of server must be listed in /etc/hosts.
#
ypserver das-m
ypserver das-s

Since we are setting up NIS client services for the first time, we must use the domainname command to set the NIS domain. Example:

[root@labdemo2 root]# domainname kerb.org
[root@labdemo2 root]# domainname
kerb.org

In order to set the NIS domain name correctly on system boot, we need to add the following line to the /etc/sysconfig/network config file:

NISDOMAIN=kerb.org

The next item is the /etc/nsswitch.conf file. Here is what it should look like:

#
# /etc/nsswitch.conf
#

passwd:     files nis
shadow:     files
group:      files nis
                                                                                                                               
hosts:      files dns nis
 
bootparams: files
 
ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files
 
netgroup:   files
 
publickey:  nisplus
 
automount:  files
aliases:    files

Note: Most of the remarks have been omitted for the sake of clarity and brevity.

Next, we need to edit or create the /etc/krb5.conf file. It should look like this:

[logging]
 default = FILE:/var/log/krb5libs.log
 kdc = FILE:/var/log/krb5kdc.log
 admin_server = FILE:/var/log/kadmind.log
 
[libdefaults]
 ticket_lifetime = 24000
 default_realm = KERB.ORG
 dns_lookup_realm = false
 dns_lookup_kdc = false
 
[realms]
 KERB.ORG = {
  kdc = das-m.kerb.org:88
  kdc = das-s.kerb.org:88
  admin_server = das-m.kerb.org:749
  default_domain = kerb.org
 }
 
[domain_realm]
 .kerb.org = KERB.ORG
 kerb.org = KERB.ORG
 
[kdc]
 profile = /var/kerberos/krb5kdc/kdc.conf
 
[appdefaults]
 pam = {
   debug = false
   ticket_lifetime = 36000
   renew_lifetime = 36000
   forwardable = true
   krb4_convert = false
 }

Now, all we have left is the PAM configuration. Here is what the config file needs to look like:

/etc/pam.d/system-auth

auth        required      /lib/security/$ISA/pam_env.so
auth        sufficient    /lib/security/$ISA/pam_unix.so likeauth
auth        sufficient    /lib/security/$ISA/pam_krb5.so use_first_pass minimum_uid=5000
auth        required      /lib/security/$ISA/pam_deny.so
 
account     required      /lib/security/$ISA/pam_unix.so
 
password    required      /lib/security/$ISA/pam_cracklib.so retry=3 type=
password    sufficient    /lib/security/$ISA/pam_unix.so use_authtok md5 shadow
password    required      /lib/security/$ISA/pam_deny.so
 
session     required      /lib/security/$ISA/pam_limits.so
session     required      /lib/security/$ISA/pam_unix.so
session     required      /lib/security/$ISA/pam_mkhomedir.so skel=/etc/skel/ umask=007
session     optional      /lib/security/$ISA/pam_krb5.so minimum_uid=5000

Depending on how you use your Red Hat system, you may also want to modify some of the other PAM config files in /etc/pam.d

Warning:  When you are altering the PAM config files, keep a root console open and test all your changes. Otherwise, you may be locked out of your own system.

Note: The "mkhomedir" PAM module is included so that every DAS user will automatically be given a home directory after their first login to the system. If you do not want this behavior, simply comment the line out.

Step 3: Start the DAS client services, and configure them to start automatically during boot

[root@labdemo2 root]# /etc/init.d/portmap start
Starting portmapper:                                       [  OK  ]
[root@labdemo2 root]# /etc/init.d/ypbind start
Binding to the NIS domain:                                 [  OK  ]
Listening for an NIS domain server..
[root@labdemo2 root]# /etc/init.d/nscd start
Starting nscd:                                             [  OK  ]
[root@labdemo2 root]# chkconfig portmap off
[root@labdemo2 root]# chkconfig ypbind off
[root@labdemo2 root]# chkconfig nscd off
[root@labdemo2 root]# chkconfig --level 345 portmap on
[root@labdemo2 root]# chkconfig --level 345 ypbind on
[root@labdemo2 root]# chkconfig --level 345 nscd  on

Step 4: Make Sure System Clock is Synchronized

You can setup time synchronization by setting up ntpd, or by using ntpdate. Please refer to the Client Time Synchronization section for details.

Step 5: Test

First, make sure that the host is able to bind to the NIS domain. This can be done with the following command:

[root@labdemo2 root]# ypwhich
das-m

You should see "das-m" or "das-s". You can test NIS client functionality with the following additional commands:

If you are not having any luck with this, use the ps and netstat commands to check that the portmapper and ypbind are both running.

NIS testing example:

[root@labdemo2 /]# ypwhich -m
hosts.byaddr das-m.kerb.org
hosts.byname das-m.kerb.org
group.bygid das-m.kerb.org
group.byname das-m.kerb.org
passwd.byname das-m.kerb.org
ypservers das-m.kerb.org
passwd.byuid das-m.kerb.org

[root@labdemo2 /]# ypcat hosts
4.2.2.3       genuity
10.10.22.1    defgate
10.10.22.68   oscar
4.2.2.1       genuity-pri
10.10.22.90   printer
4.2.2.2       genuity-alt

[root@labdemo2 /]# yppoll hosts.byname
Domain kerb.org is supported.
Map hosts.byname has order number 1066724878. [Tue Oct 21 16:27:58 2003]
The master server is das-m.kerb.org.

[root@labdemo2 /]# id kitty
uid=6000(kitty) gid=50000(labuser) groups=50000(labuser)

[root@labdemo2 /]# getent hosts
127.0.0.1       mysql.localdomain mysql
10.10.22.68   oscar
10.10.22.41   labdemo2.kerb.org labdemo2
10.10.22.42   das-m
10.10.22.40   das-s
4.2.2.3       genuity
10.10.22.1    defgate
10.10.22.68   oscar
4.2.2.1       genuity-pri
10.10.22.90   printer
4.2.2.2       genuity-alt

[root@labdemo2 /]# rpcinfo -p
   program vers proto   port
    100000    2   tcp    111  portmapper
    100000    2   udp    111  portmapper
    100007    2   udp    776  ypbind
    100007    1   udp    776  ypbind
    100007    2   tcp    779  ypbind
    100007    1   tcp    779  ypbind

Getent is an excellent tool. It returns the information for nsswitch.conf entities and includes info from files, NIS, or any other configured name service. For example, "getent hosts" will show you the local hosts file with the NIS host file appended. Use the command "man getent" for more details.

Next, make sure than you can login as a DAS user to the Kerberos realm with kinit. You should do this as a local user, root or another one will work just as well. Here is an example:

[root@labdemo2 /]# kinit kitty
Password for kitty@KERB.ORG:
[root@labdemo2 /]# klist -e
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: kitty@KERB.ORG
 
Valid starting     Expires            Service principal
11/03/03 14:25:43  11/04/03 00:25:43  krbtgt/KERB.ORG@KERB.ORG
        Etype (skey, tkt): Triple DES cbc mode with HMAC/sha1, Triple DES cbc mode with HMAC/sha1
 
 
Kerberos 4 ticket cache: /tmp/tkt0
klist: You have no tickets cached
[root@labdemo2 /]# kdestroy
[root@labdemo2 /]# klist
klist: No credentials cache found (ticket cache FILE:/tmp/krb5cc_0)
 
 
Kerberos 4 ticket cache: /tmp/tkt0
klist: You have no tickets cached

Now you know that the Kerberos client programs are working correctly. Next, we will make sure that NIS, PAM, and Kerberos together can login a user from a console or SSH login. You will do this by obtaining a console login prompt. Enter the user "kitty" and then your Kerberos password. You should be logged on. Type klist and make sure that you have a Kerb ticket. Use the kpasswd command to change your Kerb password. Now logout, and try logging back in. You should have no problems.

You will also want to make sure that you can login as a local user or as root from the console. Now, from a remote machine, SSH to the Red Hat host and login as a local user. Then logout, and login as user "kitty". You should be able to login with your Kerb password.

Step 6: Security

First of all, you should probably consider using a packet-filter like iptables on your Red Hat machine to limit who can connect to which ports, as well as shutting off any unnecessary services. Whether you use a packet filter or not, the TCP Wrappers system can be used to add some security. In our case, the use of NIS and the Portmapper have added a potentially vulnerable service to our system. We can minimize the portmapper vulnerability by restricting who can connect to it with TCP wrappers. To do this, all you need to do is create (or edit) the /etc/hosts.allow file so that it looks like this:

#
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the '/usr/sbin/tcpd' server.
#
 
# Secure the Portmapper to our LAN
portmap : 127. 10.10.22. : ALLOW
portmap : ALL : DENY

This limits who can connect to the portmapper to the loopback and the 10.10.22.0/24 network. Of course, you may have other restricted services listed in the file.

If you are going to use iptables (which is usually a good idea), some special allowances need to be made for the NIS/ Portmapper setup. A NIS client has to be able to make UDP requests and receive UDP replies. By default, most packet-filters do not handle this well. Iptables is perfectly capable of dealing with this scenario if you employ it as a "stateful" packet filter for both TCP and UDP traffic. This means that traffic (UDP/TCP/ICMP) that originates from the DAS client will also allow responses back through. Traffic that orginates elsewhere can connect to the host only if it is explicitly allowed in the firewall rules. Below is an excerpt of an iptables firewall config that allows NIS, Kerberos, NTP, and DNS client traffic, as well as PING and TRACEROUTE:

# Load connection tracking modules:
modprobe ip_conntrack
modprobe ip_conntrack_ftp
 
# Flush all chains, delete user-defined chains, and zero all counters
iptables -F
iptables -X
iptables -Z
 
# Default action if packets match no rules in chain
iptables -P INPUT DROP

# Make sure that NEW tcp connections are SYN packets
iptables -A INPUT -i $IFACE -p tcp ! --syn -m state --state NEW -j DROP
 
# Allow hosts on the LAB network to PING the us. Outbound PING is allowed via
# connection tracking, and traceroute works as well.
iptables -A INPUT -s $LABNET -d $IPADDR -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -s any/0 -d $IPADDR -p icmp --icmp-type destination-unreachable -j ACCEPT
iptables -A INPUT -s any/0 -d $IPADDR -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT
 
# Allow inbound TCP port for SSH connection
iptables -A INPUT -s $DASNET -d $IPADDR -p tcp --dport 22 -j ACCEPT
 
# Connection Tracking - Allow TCP and UDP connections initiated by server
iptables -A INPUT -s any/0 -d $IPADDR -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -s any/0 -d $IPADDR -p udp -m state --state ESTABLISHED -j ACCEPT

Note that the only externally initiated "inbound" traffic allowed is PING and SSH. To support the UDP traffic from Kerberos, NTP, NIS/Portmapper, and DNS, the connection tracking modules are required. To see the complete iptables firewall config, click here. If you want the packet filter to start automatically on boot, then you will need to configure this in the startup scripts. Use chkconfig to disable the built-in iptables script that comes with Red Hat. The built in scripts do not support our DAS client properly, so we will not use them. To disable the built-in iptables script:

[root@labdemo2 /]# chkconfig iptables off
[root@labdemo2 /]# chkconfig --list iptables
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off

Final Note:  If you write your own firewall script and then have problems with your DAS client, such as NIS or Kerberos errors, try removing the firewall before diving into any other troubleshooting.

The iptables -L -n -v command can also be a useful way of determining whether or not the packet filter is to blame.



Limiting the "su" command:

Once you setup an application server or client system to use DAS, it is possible for a DAS user to login to many different systems. By default, that user can try to use the su command to obtain a root shell. If the root password on that machine is poorly chosen, you could have a compromise. Therefore, you may want to keep DAS users from using the su command. This is very simple to configure on Red Hat:

Make sure that any local users who need to be able to use the su command are added to the "wheel" group. Here is the command:

[root@labdemo2 root]# usermod -G wheel vano
[root@labdemo2 root]# grep wheel /etc/group
wheel:x:10:root,vano

Now, modify the /etc/pam.d/su config file by un-commenting the pam_wheel.so entry so that the file looks like this:

#%PAM-1.0
auth       sufficient   /lib/security/$ISA/pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth       sufficient   /lib/security/$ISA/pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth       required     /lib/security/$ISA/pam_wheel.so use_uid
auth       required     /lib/security/$ISA/pam_stack.so service=system-auth
account    required     /lib/security/$ISA/pam_stack.so service=system-auth
password   required     /lib/security/$ISA/pam_stack.so service=system-auth
session    required     /lib/security/$ISA/pam_stack.so service=system-auth
session    optional     /lib/security/$ISA/pam_xauth.so

Now, on this system only user "vano" and "root" can use the su command, DAS users cannot.

Step 7: Create Home Directories for DAS Users (optional)

Red Hat 9 includes the pam_mkhomedir PAM module. As long as you include it in your /etc/pam.d/system-auth config file, you will not manually have to create directories and skeleton entries for DAS users before they can use any given DAS Client host. However, you may want to control who can use the system by creating the home directories manually for those who need them. As root, here is how you would do that:

[root@labdemo2 home]# mkdir /home/kitty
[root@labdemo2 home]# cp -rv /etc/skel/.[a-z]* /home/kitty
[root@labdemo2 home]# id kitty
uid=6000(kitty) gid=50000(labuser) groups=50000(labuser)
[root@labdemo2 skel]# chown -R kitty:labuser /home/kitty
[root@labdemo2 home]# chmod 0750 /home/kitty
[root@labdemo2 home]# ls -ald /home/kitty
drwxr-x---    3 kitty    labuser      4096 Nov  3 16:18 /home/kitty

Operational/Performance Notes

Note 1 - Client performance was very responsive when the DAS-M server was unavailable and the DAS-S server was available.

Note 2 - When both DAS servers are unavailable, boot, local user, and root logins are successful. Local user login is delayed about 5 seconds.

Note 3 - In any situtation where one or both DAS servers are unavailable, using nscd improves responsiveness, since it caches both postive and negative queries.

Note 4 - Disk quotas for DAS users worked correctly, whether DAS servers were available or not. While the DAS servers are not available, root will not be able to edit a DAS user's quota. Quota, repquota, and edquota all use the Name Service Switch system that is configured by /etc/nsswitch.conf.

Note 5 - cron and at may not work for a DAS user when the DAS servers are unavailable. Mail delivery will fail if the output of a job is to be mailed to the local host with a "no such user" type of error. Also, crond may consider the cron job of a DAS user to be "orphaned" if it cannot find the name. If this happens, crond will continue processing other crontabs, but will stop processing the crontabs of DAS users. When the DAS is available again, the DAS user can fix this by deleting his cron job and re-submitting it. Another alternative is for the root user on the host to restart crond. In all cases, checking /var/log/cron should give you some clues.

Note 6 - If you must do administrative work on a DAS client host while it is disconnected from the network, it may cause some annoying delays with some tasks. If this is an issue, simply stop the ypbind daemon. You could also reconfigure the /etc/nsswitch.conf file so that NIS is not referenced.

Note 7 - Kerberized rlogin client sessions were tested for a DAS user. Both the encrypted and non-encrypted versions worked without any problems.


References

RH 9 Manual - PAM
RH 9 Manual - Kerb5
RH 9 Manual - Securing the Portmapper