&author.jht; StephenLangasek
vorlon@netexpress.net
(Jun 21 2001)
PAM based Distributed Authentication This chapter you should help you to deploy winbind based authentication on any PAM enabled Unix/Linux system. Winbind can be used to enable user level application access authentication from any MS Windows NT Domain, MS Windows 200x Active Directory based domain, or any Samba based domain environment. It will also help you to configure PAM based local host access controls that are appropriate to your Samba configuration. Features and Benefits A number of Unix systems (eg: Sun Solaris), as well as the xxxxBSD family and Linux, now utilize the Pluggable Authentication Modules (PAM) facility to provide all authentication, authorization and resource control services. Prior to the introduction of PAM, a decision to use an alternative to the system password database (/etc/passwd) would require the provision of alternatives for all programs that provide security services. Such a choice would involve provision of alternatives to such programs as: login, passwd, chown, etc. PAM provides a mechanism that disconnects these security programs from the underlying authentication/authorization infrastructure. PAM is configured either through one file /etc/pam.conf (Solaris), or by editing individual files that are located in /etc/pam.d. On PAM enabled Unix/Linux systems it is an easy matter to configure the system to use any authentication backend, so long as the appropriate dynamically loadable library modules are available for it. The backend may be local to the system, or may be centralised on a remote server. PAM support modules are available for: /etc/passwd- There are several PAM modules that interact with this standard Unix user database. The most common are called: pam_unix.so, pam_unix2.so, pam_pwdb.so and pam_userdb.so. Kerberos- The pam_krb5.so module allows the use of any Kerberos compliant server. This tool is used to access MIT Kerberos, Heimdal Kerberos, and potentially Microsoft Active Directory (if enabled). LDAP- The pam_ldap.so module allows the use of any LDAP v2 or v3 compatible backend server. Commonly used LDAP backend servers include: OpenLDAP v2.0 and v2.1, Sun ONE iDentity server, Novell eDirectory server, Microsoft Active Directory. NetWare Bindery- The pam_ncp_auth.so module allows authentication off any bindery enabled NetWare Core Protocol based server. SMB Password- This module, called pam_smbpass.so, will allow user authentication off the passdb backend that is configured in the Samba &smb.conf; file. SMB Server- The pam_smb_auth.so module is the original MS Windows networking authentication tool. This module has been somewhat outdated by the Winbind module. Winbind- The pam_winbind.so module allows Samba to obtain authentication from any MS Windows Domain Controller. It can just as easily be used to authenticate users for access to any PAM enabled application. RADIUS- There is a PAM RADIUS (Remote Access Dial-In User Service) authentication module. In most cases the administrator will need to locate the source code for this tool and compile and install it themselves. RADIUS protocols are used by many routers and terminal servers. Of the above, Samba provides the pam_smbpasswd.so and the pam_winbind.so modules alone. Once configured, these permit a remarkable level of flexibility in the location and use of distributed samba domain controllers that can provide wide are network bandwidth efficient authentication services for PAM capable systems. In effect, this allows the deployment of centrally managed and maintained distributed authentication from a single user account database. Technical Discussion All operating systems depend on the authentication sub-systems to provide for authenticated users credentials accecptable to the platform. Unix requires the provision of a user identifier (UID) as well as a group identifier (GID). These are both simple integer type numbers that are obtained from a password backend such as /etc/passwd. Users and groups on a Windows NT server are assigned a relative id (rid) which is unique for the domain when the user or group is created. To convert the Windows NT user or group into a unix user or group, a mapping between rids and unix user and group ids is required. This is one of the jobs that winbind performs. As winbind users and groups are resolved from a server, user and group ids are allocated from a specified range. This is done on a first come, first served basis, although all existing users and groups will be mapped as soon as a client performs a user or group enumeration command. The allocated unix ids are stored in a database file under the Samba lock directory and will be remembered. The rid to unix id database is the only location where the user and group mappings are stored by winbindd. If this file is deleted or corrupted, there is no way for winbindd to determine which user and group ids correspond to Windows NT user and group rids. If the PAM authentication module (loadable link library file) is located in the default location then it is not necessary to specify the path. In the case of Linux, the default location is /lib/security. If the module is located outside the default then the path must be specified as: auth required /other_path/pam_strange_module.so The following is an example /etc/pam.d/login configuration file. This example had all options been uncommented is probably not usable as it stacks many conditions before allowing successful completion of the login process. Essentially all conditions can be disabled by commenting them out except the calls to pam_pwdb.so. #%PAM-1.0 # The PAM configuration file for the `login' service # auth required pam_securetty.so auth required pam_nologin.so # auth required pam_dialup.so # auth optional pam_mail.so auth required pam_pwdb.so shadow md5 # account requisite pam_time.so account required pam_pwdb.so session required pam_pwdb.so # session optional pam_lastlog.so # password required pam_cracklib.so retry=3 password required pam_pwdb.so shadow md5 PAM allows use of replacable modules. Those available on a sample system include: $/bin/ls /lib/security pam_access.so pam_ftp.so pam_limits.so pam_ncp_auth.so pam_rhosts_auth.so pam_stress.so pam_cracklib.so pam_group.so pam_listfile.so pam_nologin.so pam_rootok.so pam_tally.so pam_deny.so pam_issue.so pam_mail.so pam_permit.so pam_securetty.so pam_time.so pam_dialup.so pam_lastlog.so pam_mkhomedir.so pam_pwdb.so pam_shells.so pam_unix.so pam_env.so pam_ldap.so pam_motd.so pam_radius.so pam_smbpass.so pam_unix_acct.so pam_wheel.so pam_unix_auth.so pam_unix_passwd.so pam_userdb.so pam_warn.so pam_unix_session.so The following example for the login program replaces the use of the pam_pwdb.so module which uses the system password database (/etc/passwd, /etc/shadow, /etc/group) with the module pam_smbpass.so which uses the Samba database which contains the Microsoft MD4 encrypted password hashes. This database is stored in either /usr/local/samba/private/smbpasswd, /etc/samba/smbpasswd, or in /etc/samba.d/smbpasswd, depending on the Samba implementation for your Unix/Linux system. The pam_smbpass.so module is provided by Samba version 2.2.1 or later. It can be compiled by specifying the options when running Samba's configure script. For more information on the pam_smbpass module, see the documentation in the source/pam_smbpass directory of the Samba source distribution. #%PAM-1.0 # The PAM configuration file for the `login' service # auth required pam_smbpass.so nodelay account required pam_smbpass.so nodelay session required pam_smbpass.so nodelay password required pam_smbpass.so nodelay The following is the PAM configuration file for a particular Linux system. The default condition uses pam_pwdb.so. #%PAM-1.0 # The PAM configuration file for the `samba' service # auth required pam_pwdb.so nullok nodelay shadow audit account required pam_pwdb.so audit nodelay session required pam_pwdb.so nodelay password required pam_pwdb.so shadow md5 In the following example the decision has been made to use the smbpasswd database even for basic samba authentication. Such a decision could also be made for the passwd program and would thus allow the smbpasswd passwords to be changed using the passwd program. #%PAM-1.0 # The PAM configuration file for the `samba' service # auth required pam_smbpass.so nodelay account required pam_pwdb.so audit nodelay session required pam_pwdb.so nodelay password required pam_smbpass.so nodelay smbconf=/etc/samba.d/smb.conf PAM allows stacking of authentication mechanisms. It is also possible to pass information obtained within one PAM module through to the next module in the PAM stack. Please refer to the documentation for your particular system implementation for details regarding the specific capabilities of PAM in this environment. Some Linux implmentations also provide the pam_stack.so module that allows all authentication to be configured in a single central file. The pam_stack.so method has some very devoted followers on the basis that it allows for easier administration. As with all issues in life though, every decision makes trade-offs, so you may want examine the PAM documentation for further helpful information. PAM Configuration in smb.conf There is an option in smb.conf called obey pam restrictions. The following is from the on-line help for this option in SWAT; When Samba is configured to enable PAM support (i.e. ), this parameter will control whether or not Samba should obey PAM's account and session management directives. The default behavior is to use PAM for clear text authentication only and to ignore any account or session management. Note that Samba always ignores PAM for authentication in the case of encrypt passwords = yes. The reason is that PAM modules cannot support the challenge/response authentication mechanism needed in the presence of SMB password encryption. Default: obey pam restrictions = no Password Synchronisation using pam_smbpass.so pam_smbpass is a PAM module which can be used on conforming systems to keep the smbpasswd (Samba password) database in sync with the unix password file. PAM (Pluggable Authentication Modules) is an API supported under some Unices, such as Solaris, HPUX and Linux, that provides a generic interface to authentication mechanisms. For more information on PAM, see The linux PAM homepage. This module authenticates a local smbpasswd user database. If you require support for authenticating against a remote SMB server, or if you're concerned about the presence of suid root binaries on your system, it is recommended that you use pam_winbind instead. Options recognized by this module are as follows: Options recognized by pam_mkpass debuglog more debugging infoauditlike debug, but also logs unknown usernamesuse_first_passdon't prompt the user for passwords; take them from PAM_ items insteadtry_first_passtry to get the password from a previous PAM module, fall back to prompting the useruse_authtoklike try_first_pass, but *fail* if the new PAM_AUTHTOK has not been previously set. (intended for stacking password modules only)not_set_passdon't make passwords used by this module available to other modules.nodelaydon't insert ~1 second delays on authentication failure.nulloknull passwords are allowed.nonullnull passwords are not allowed. Used to override the Samba configuration.migrateonly meaningful in an "auth" context; used to update smbpasswd file with a password used for successful authentication.smbconf=filespecify an alternate path to the &smb.conf; file.
Thanks go to the following people: Andrew Morgan, for providing the Linux-PAM framework, without which none of this would have happened Christian Gafton and Andrew Morgan again, for the pam_pwdb module upon which pam_smbpass was originally based Luke Leighton for being receptive to the idea, and for the occasional good-natured complaint about the project's status that keep me working on it :) . The following are examples of the use of pam_smbpass.so in the format of Linux /etc/pam.d/ files structure. Those wishing to implement this tool on other platforms will need to adapt this appropriately. Password Synchonisation Configuration A sample PAM configuration that shows the use of pam_smbpass to make sure private/smbpasswd is kept in sync when /etc/passwd (/etc/shadow) is changed. Useful when an expired password might be changed by an application (such as ssh). #%PAM-1.0 # password-sync # auth requisite pam_nologin.so auth required pam_unix.so account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password required pam_smbpass.so nullok use_authtok try_first_pass session required pam_unix.so Password Migration Configuration A sample PAM configuration that shows the use of pam_smbpass to migrate from plaintext to encrypted passwords for Samba. Unlike other methods, this can be used for users who have never connected to Samba shares: password migration takes place when users ftp in, login using ssh, pop their mail, etc. #%PAM-1.0 # password-migration # auth requisite pam_nologin.so # pam_smbpass is called IF pam_unix succeeds. auth requisite pam_unix.so auth optional pam_smbpass.so migrate account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password optional pam_smbpass.so nullok use_authtok try_first_pass session required pam_unix.so Mature Password Configuration A sample PAM configuration for a 'mature' smbpasswd installation. private/smbpasswd is fully populated, and we consider it an error if the smbpasswd doesn't exist or doesn't match the Unix password. #%PAM-1.0 # password-mature # auth requisite pam_nologin.so auth required pam_unix.so account required pam_unix.so password requisite pam_cracklib.so retry=3 password requisite pam_unix.so shadow md5 use_authtok try_first_pass password required pam_smbpass.so use_authtok use_first_pass session required pam_unix.so Kerberos Password Integration Configuration A sample PAM configuration that shows pam_smbpass used together with pam_krb5. This could be useful on a Samba PDC that is also a member of a Kerberos realm. #%PAM-1.0 # kdc-pdc # auth requisite pam_nologin.so auth requisite pam_krb5.so auth optional pam_smbpass.so migrate account required pam_krb5.so password requisite pam_cracklib.so retry=3 password optional pam_smbpass.so nullok use_authtok try_first_pass password required pam_krb5.so use_authtok try_first_pass session required pam_krb5.so
Distributed Authentication The astute administrator will realize from this that the combination of pam_smbpass.so, winbindd, and a distributed passdb backend, such as ldap, will allow the establishment of a centrally managed, distributed user/password database that can also be used by all PAM (eg: Linux) aware programs and applications. This arrangement can have particularly potent advantages compared with the use of Microsoft Active Directory Service (ADS) in so far as reduction of wide area network authentication traffic. Common Errors PAM can be a very fickle and sensitive to configuration glitches. Here we look at a few cases from the Samba mailing list. pam_winbind problem I have the following PAM configuration: auth required /lib/security/pam_securetty.so auth sufficient /lib/security/pam_winbind.so auth sufficient /lib/security/pam_unix.so use_first_pass nullok auth required /lib/security/pam_stack.so service=system-auth auth required /lib/security/pam_nologin.so account required /lib/security/pam_stack.so service=system-auth account required /lib/security/pam_winbind.so password required /lib/security/pam_stack.so service=system-auth When I open a new console with [ctrl][alt][F1], then I cant log in with my user "pitie". I've tried with user "scienceu+pitie" also. Answer: The problem may lie with your inclusion of pam_stack.so service=system-auth. That file often contains a lot of stuff that may duplicate what you're already doing. Try commenting out the pam_stack lines for auth and account and see if things work. If they do, look at /etc/pam.d/system-auth and copy only what you need from it into your /etc/pam.d/login file. Alternatively, if you want all services to use winbind, you can put the winbind-specific stuff in /etc/pam.d/system-auth.