210.2. PAM authentication
210.2 PAM authentication
Weight: 3
Description: The candidate should be able to configure PAM to support authentication using various available methods. This includes basic SSSD functionality.
Key Knowledge Areas:
PAM configuration files, terms and utilities
passwd and shadow passwords
Use sssd for LDAP authentication
Terms and Utilities:
/etc/pam.d/
pam.conf
nsswitch.conf
pam_unix, pam_cracklib, pam_limits, pam_listfile, pam_sss
sssd.conf
Having Control over users and Authenticatios and auditing is so important. But there is not just one Authentication source which alway we use. There are different authentication sources like traditionamunix shadow file, LDAP servers, old Nis.
PAM (Pluggable Authentication Modules)
PAM is a kind of abstaraction layer which seats between programs and different kinds of Authentication sources, and handles the process of negotiating with authentication source and take the result back to the program.

This way developers do not need to find out how to design their programs to deal with different authentication sources and they just concentrate on their programs and use pam. From another perspective when a new authentication source implemented, there is no need to change programs, just implement a new pammodule and use it again and again, this way pam bring kind of mobilabilty for programs too.
PAM Architecure

Any program like passwd, or su which deal with username and password use pam. To do that, the program should work with pam library file pam_lib . PAM by itself is using configuration files /etc/pam.d. PAM is modular and uses differnt modules which are placed in /lib/security .
For example lets check login tool to findout if it uses pam or not(CentOS 7) :
libpam andlibpam_misc bring passwd tool to the pam.
/etc/pam.d
The /etc/pam.d/ directory contains the PAM configuration files for each PAM-aware application. In earlier versions of PAM, the /etc/pam.conf file was used, but this file is now deprecated and is only used if the /etc/pam.d/ directory does not exist:
Every binary which has some thing to do with pam need to have a configuration file.There are some generic configuration files also. Configuration files define what should exactly happen. PAM Configuration File Format is like this :
1-Service: It defines what service, this line of configuration is about. Like ssh, or FTP. This way /etc/pam.conf file becomes a one huge file with many lines, that doesn't seem so good which is why in many moder linux distrobutions each service has its own configuration file with its name inside /etc/pam.d directory, as you can see above. Lets take a look at one of them before countinue:
system-auth is a generic configuration file that is included almost in every process that do some thing with authentication.
2- module-interface: Four types of PAM module interface are available. Each of these corresponds to a different aspect of the authorization process:
auth: This module interface authenticates use. For example, it requests and verifies the validity of a password. Modules with this interface can also set credentials, such as group memberships or Kerberos tickets.
account: This module interface verifies that access is allowed. For example, it may check if a user account has expired or if a user is allowed to log in at a particular time of day.
password: This module interface is used for changing user passwords.
session: This module interface configures and manages user sessions. Modules with this interface can also perform additional tasks that are needed to allow access, like mounting a user's home directory and making the user's mailbox available. For better understandning take a look at control.
3- control-flag : All PAM modules generate a success or failure result when called. Control flags tell PAM what do with the result. Modules can be stacked in a particular order, and the control flags determine how important the success or failure of a particular module is to the overall goal of authenticating the user to the service.
There are several simple flags, which use only a keyword to set the configuration:
requisite : The module result must be successful for authentication to continue. However, if a test fails at this point, the user is notified immediately with a message reflecting the first failed
requiredorrequisitemodule test.required :The module result must be successful for authentication to continue. If the test fails at this point, the user is not notified until the results of all module tests that reference that interface are complete.
sufficient : The module result is ignored if it fails. However, if the result of a module flagged
sufficientis successfuland no previous modules flaggedrequiredhave failed, then no other results are required and the user is authenticated to the service.optional : The module result is ignored. A module flagged as
optionalonly becomes necessary for successful authentication when no other modules reference the interface.include : Unlike the other controls, this does not relate to how the module result is handled. This flag pulls in all lines in the configuration file which match the given parameter and appends them as an argument to the module.
4-pam module name : The module name provides PAM with the name of the pluggable module containing the specified module interface. The directory name is omitted because the application is linked to the appropriate version of libpam, which can locate the correct version of the module.
5- module arguments : PAM uses _arguments _to pass information to a pluggable module during authentication for some modules. For example:
Invalid arguments are generally ignored and do not otherwise affect the success or failure of the PAM module. Some modules, however, may fail on invalid arguments. Most modules report errors to the/var/log/securefile.
Now that we now the format of PAM configuration file lets take a look at another one:
As you can see there are some generic configuration files like password-auth wich might be included and used in other configuration files again and again.
/lib/security or /lib64/security
There is a place for pam modules itself:
If new way of authentication has been invented(Like finger print reader), there is a place which requied module should be placed and integrated with pam configuration files.
For lPIC2 exam we are required to know some of these modules:
pam_unix
pam_cracklib
pam_limits
pam_listfile
pam_sss
pam_unix: This module configures authentication via /etc/passwd and /etc/shadow.
The pam_unix.so module supports the following management groups:
Most of services which need authentication include pam_unix.so . As an example we can add options to that inorder to remember last 3 user's password and dose not let user to set them again.
And fortunatley there is no need to do any thing else. Test it by creating a user and set different passwords for that 3 times and on forth effort try to set the first password which you have used, it won't let you.
pam_cracklib : This plugin provides strength-checking for passwords. This is done by performing a number of checks to ensure passwords are not too weak. It checks the password against dictonaries, the previous password(s) and rules about the use of numbers, upper and lowercase and other characters. Based on your distro pam_cracklib name might be name different.
For example we can set minimum charachters wich are required for a password, by the way you can see the name of`_pamcracklib.so` has been changed here in CentOS7 and that is pam\_pwquality.so :
pam_limits : The pam_limits PAM module sets limits on the system resources that can be obtained in a user-session. Users of uid=0 are affected by this limits, too. By default limits are taken from the /etc/security/limits.confconfig file. Then ndividual files from the/etc/security/limits.d/directory are read.
As you can see pam__limists.so is used in session module, so instead of manipulating that module which would have effects on other services we put our setting inside /etc/security/limits.conf :
For example, adding line below at the end of /etc/security/limits.conf can avoid pooruser from loging more than once :
For testing, create pooruser and try to ssh to the system more than once, see the results.
pam_listfile : This module allows or denies an action based on the presence of the item in a listfile. A listfile is a textfile containing a list of usernames, one username per line. The type of item can be set via the configuration parameter item and can have the value of user, tty, rhost, ruser, group, or shell. The sense configuration parameter determines whether the entries in the list are allowed. Possible values are allow and deny.
Right now no package or service is currently using pam_list file, for testing lets install a FTP server:
The thing that it does is denying every user which his name/ her name is inside /etc/vsftpd/ftpusers. see:
For testing , start vsftp service, create a pooruser and add it to this list, then try to login to the ftp server with pooruser.
sssd
sssd is a centeral service in the authentication process, that determines how exactly the authentication is going to happen. sssd can authenticate us against LDAP, ActiveDirectory, Nis , ... . sssd is especialy developed to do that. Lets just take a look at it inorder to have a better understanding of pam_sss. Here we just chek the service and read sample configuration file:
We need to configure and start sssd serviceif have a plan to use it but leave it for now.
pam_sss.so : is the PAM interface to the System Security Services daemon (SSSD). Errors and results are logged through syslog.
nsswitch.conf
nsswitch determines the order that files or services are used to perform either Authentication or Authorative responses to some thing on the system. We typically nsswitch.conf is edited when we are dealing with DNS entries. (We have talked about nsswitch when we talked about BIND DNS in previous course).
The Authentication order and nsswitch can effect how authentication takes place on our system, including wehther pam any modules are involved ,since they are files. So one way for troubleshooting pam if it not applied, is by controlling nsswitch and the see the order of files.
That is all.
Last updated