PAM - Not just for cooking


WHAT THIS PAGE COVERS

For a detailed look at PAM and how to use it, go to your local RedHat Linux machine and look under /usr/doc/pam-(whichever version)/   There is very good documentation in both html and postscript form there.  This is a good thing because the man pages for pam are very scarce.
Because of that good documentation this is going to be more of a PAM crash course.  90% of what you actually need to know about pam to use it efficiently will be here.  The other 10%, if needed, will be the so many 'what if' questions that I won't be able to cover them here without making this as big as the documentation. Some of the documentation in this document, came from their web pages.


Linux-PAM (Pluggable Authentication Modules for Linux) is a suite of shared libraries that enable the local system administrator to choose how applications authenticate users.  These libraries are written up into what are called modules.  Each module has it's own test, rules, and criteria.  The system administrator is then able to setup configuration files to check users and programs, and based on the responses of these modules, either authenticate, or reject that user and/or program.

In this how-to we are going to treat the libraries and modules as black boxes.  These black boxes are going to tell us one of two things.  Yes my test was passed, or No my test wasn't passed.  Other aspects of modules, such as how to write them, are beyond the scope of this how-to.


Where Do I Start?

For starters there are two places you should be concerned with. Where your modules are, and where your configuration files are.  Just one warning, this is one of the differences between a RedHat distribution, and a Debian distribution.  I'm only going to tell you where the RedHat files are so that you don't have them both in your head trying to remember which is which.  Just remember that if you are on a Debian based distribution, that it isn't in the same place.

Modules:

/lib/security

Configuration Files:

/etc/pam.d

You need to know the modules directory, so you can actually see what modules you have, and also so that you have the correct path in your configuration files.


Configuration File Structure

A general configuration line of a /etc/pam.d/ configuration file has the following form:

module-type control-flag module-path arguments

Below is the explanation for each of these 'tokens' from the PAM Administrators Guide mentioned above.  It has been slightly modified.  

module-type

One of (currently) four types of module. The four types are as follows:

control-flag

The control-flag is used to indicate how the PAM library will react to the success or failure of the module it is associated with.  Since modules can be stacked (modules of the same type execute in series, one after another), the control-flags determine the relative importance of each module.  The application is not made aware of the individual success or failure of modules listed in the `/etc/pam.conf' file.  Instead, it receives a summary success or fail response from the Linux-PAM library. The order of execution of these modules is that of the entries in the /etc/pam.conf file; earlier entries are executed before later ones.  As of Linux-PAM v0.60, this control-flag can be defined with one of two syntax's.

The simpler (and historical) syntax for the control-flag is a single keyword defined to indicate the severity of concern associated with the success or failure of a specific module. There are four such keywords: required, requisite, sufficient and optional.

The Linux-PAM library interprets these keywords in the following manner:

module-path

The path-name of the dynamically loadable object file; the pluggable module itself. If the first character of the module path is `/', it is assumed to be a complete path. If this is not the case, the given module path is appended to the default module path: /lib/security

args

The args are a list of tokens that are passed to the module when it is invoked. Much like arguments to a typical Linux shell command. Generally, valid arguments are optional and are specific to any given module. Invalid arguments are ignored by a module, however, when encountering an invalid argument, the module is required to write an error to syslog(3). The following are optional arguments which are likely to be understood by any module. Arguments (including these) are in general optional.


Example 1

For our first example we will walk through what happens when you do just a n 'su'

<>cat /etc/pam.d/su

#%PAM-1.0
auth required     /lib/security/pam_pwdb.so shadow nullok
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so shadow use_authtok nullok
session required /lib/security/pam_pwdb.so
session optional /lib/security/pam_xauth.so


When you do an 'su' a chain of events happens.  First the su program contacts PAM.  PAM looks and finds the configuration file for su, then starts to go through it line by line.

The first line tell it that it needs to authorize this person.  So the pam_pwdb module asks the user for his password.  The user types in the password, and the module proceeds to check it.  You will see that there are two arguments with this module, and neither of them are in our args list.  This is because each module can have their own arguments, the list above simply shows four of the most common ones.  These two tell the module to look in the shadow file for the passwords, and that it's ok to check the password even if the user didn't put one in.

The second line checks the status of the users account.  It might do anything from warn them that their password is about to expire, not let them in if their account has expires, or simply be silent and let the user in.

The third line does a password check and tells the user if their password isn't very good.

The fifth line updates any password authentication associated with that user.

The sixth line simply logs the username and service-type to syslog.

The seventh line authorizes any x-windows programs.  As you can see this is optional and won't stop anything, though it does send out a warning if it doesn't pass.


Example 2

For our other example we will go through what happens when you do a regular login.  Several of these lines are the same as above.  For completeness sake I will still say what is going on, so please pardon my repetition.

<>cat /etc/pam.d/login

#%PAM-1.0
auth required     /lib/security/pam_securetty.so
auth required /lib/security/pam_nologin.so
auth sufficient /lib/security/pam_afs.so ignore_root
auth required /lib/security/pam_pwdb.so try_first_pass shadow nullok
account required /lib/security/pam_pwdb.so
password required /lib/security/pam_cracklib.so
password required /lib/security/pam_pwdb.so shadow nullok use_authtok
session required /lib/security/pam_pwdb.so
session optional /lib/security/pam_console.so

The first line is an extra security measure that only allows root to log in from certain areas.  All other users are ignored by it.

The second line checks to see if the nologin file exists.  If it does, then only root is allowed to login.  This is for letting root do maintenance without having to remain in single user mode.

The third line asks the user for their AFS password.  It then checks this password with the AFS server.  If it passes then the user is given an AFS token.  If the user is root, then this module is skipped. Since this is flagged as sufficient, if the user's password works, then PAM skips down to the fifth line (skipping all other auth modules).  If the users password does not work, then PAM doesn't worry about this module and moves down to the next line.

The fourth line takes the password that was supplied in line three and runs it's checks on it.  If it passes, then it gives it's ok.  If the password doesn't pass (or in the case of root, one wasn't asked for) then the module asks the user for a password.  It then runs this new password through it's tests.

The fifth line checks the status of the users account.  It might do anything from warn them that their password is about to expire, not let them in if their account has expires, or simply be silent and let the user in.

The sixth line does a password check and tells the user if their password isn't very good.

The seventh line updates any password authentication associated with that user.

The eighth line simply logs the username and service-type to syslog.

The seventh line authorizes any console programs.  As you can see this  is optional and won't stop anything, though it does send out a warning if  it doesn't pass.


dawson@fnal.gov
Back to How To
August 29, 2000