Curs: | SambasobreLDAP, LinuxAdministracioAvancada, SeguretatXarxesInformàtiques |
Fitxers: | Ldap2.pdf,AutenticacioiAutoritzacionsLinux.pdf |
Repositori SVN: | https://[email protected]/svn/iceupc/SambaSobreLDAP |
Usuari: | anonymous |
Paraula de pas: | sense paraula de pas |
Autors: | Sergi Tur Badenas, Lluís Pérez Vidal |
PAM (Pluggable Authentication Modules) és un mecanisme flexible per l'autenticació d'usuaris. Permet utilitzar sistemes d'autenticació diferents al sistema tradicional d'autenticació (fitxer /etc/passwords) sense necessitat de canviar el disseny de les aplicacions. PAM permet desenvolupar programes amb independència de l'esquema d'autenticació utilitzant mòduls d'autenticació en temps d'execució i no haver de tornar a compilar per canviar l'esquema d'autenticació.
PAM és un invent de SUN (especificació amb diferents implementacions). Linux-PAM és la implementació de PAM a Linux.
Consulteu:
LPI_107.1._Gestió_d'usuaris_i_comptes_de_grup_i_els_fitxers_de_sistema_relacionats#Esquemes_d.27autenticaci.C3.B3
NOTA: Observeu que només amb la base de dades d'usuaris, grups i paraules de pas, a les qual podem accedir amb NSSwitch no hi ha prou per a treballar amb usuaris. A més cal definir com es fan processos com l'autenticació/login, com es gestionen les sessions d'usuari, com es gestionen les comptes d'usuari, etc. Tot això és el que fa PAM però sense lligar-se a cap tecnologia concreta
El més possible és que PAM ja estigui instal·lat ja que el suporten gairebé totes les distribucions. Si no tenim PAM segurament estem utilitzant una distribució Linux molt antiga.
La configuració de PAM es duu a terme amb els fitxers de la carpeta /etc/pam.d.
NOTA: Alguns sistemes poden tenir la configuració de PAM tota al fitxer /etc/pam.conf.
Cada fitxer d'aquesta carpeta representa un servei/aplicació que fa ús de PAM.Per exemple el fitxer:
/etc/pam.d/login
Configura l'ús de PAM per l'aplicació login.
NOTA: Els comentaris en els fitxers de configuració de PAM es fan amb el caràcter #.
Cada fitxer té les normes que s'apliquen per un servei (aplicació) “PAM-aware” i conté una llista ordenada de normes on cada línia o norma té la següent sintaxi:
type control module-path module-arguments
Com podem veure disposem de 4 tokens amb les seves respectives opcions:
Hi ha una segona sintaxi més complicada per al token control amb parells de valors:
[value1=action1 value2=action2 ...]
On valueN correspon a l'error de retorn per la funció invocada pel mòdul. Els valors possibles són:
La llista completa es pot trobar a /usr/include/security/_pam_types.h.
L'acció N pot ser:
o
Aquesta segona forma de sintaxi permet controlar de forma més granular PAM (però també està més propera al perfil de programador que no pas al perfil d'administrador). Les equivalències amb la sintaxi anterior són:
Si la configuració de PAM està tota al fitxer /etc/pam.conf la configuració canvia una mica. En comptes de tenir un fitxer /etc/pam.d/login:
auth required pam_unix.so nulok
Tindreu un fitxer /etc/pam.conf amb:
login auth required pam_unix.so nulok
Qualsevol error de sintaxi implica un error en l'autenticació (per seguretat). L'error corresponent es mostra al sistema de logs syslog.
Les normes dels fitxers de configuració poden ser apilades per tal d'utilitzar més d'un mòdul a l'autenticar. L'orde de la pila és important segons els tipus de directiva de control que utilitzem (l'ordre dels mòduls required no és important en canvi, amb els indicadors de control sufficient i requisite l'ordre si és important. Per exemple el següent fitxer de configuració de rlogin utilitza cinc mòduls auth:
auth required pam_nologin.so auth required pam_securetty.so auth required pam_env.so auth sufficient pam_rhosts_auth.so auth required pam_stack.so service=system-auth
Abans que és pugui fer un rlogin és verifica que no existeixi el fitxer /etc/nologin no existeixi (pam_nologin.so), que no s'estigui entrant com a root (pam_securetty.so) i es pugui carregar qualsevol variable d'entorn (pam_env.so). Finalment és mira d'autenticar amb l'autenticació de rhosts (pam_rhosts_auth.so) que si falla es pot ignorar (sufficient) i provar amb l'autenticació del sistema (pam_stack.so service=system-auth).
El servei other és el servei per defecte i el que utilitzaran tots els serveis que no estiguin específicament configurats a PAM. Si executem
$ cat /etc/pam.d/other ............ @include common-auth @include common-account @include common-password @include common-session
Veurem que delega el comportament als fitxers common-auth, common-account, common-password, i common-session.
$ cat /etc/pam.d/common-aut ......................... auth required pam_unix.so nullok_secure
$ cat /etc/pam.d/common-auth cat /etc/pam.d/common-auth
$ cat /etc/pam.d/common-password ........ password required pam_unix.so nullok obscure min=4 max=8 md5
Algunes distribucions tenen la configuració de PAM en aquest fitxer però en la majoria de casos es reparteix la configuració en diferents fitxers de la carpeta /etc/pam.d.
En aquesta carpeta es guarden els fitxers de configuració de PAM.
$ sudo joe /etc/pam.d/common-session
I afegiu:
session required pam_mkhomedir.so skel=/etc/skel umask=0022
Un exemple de com queda el fitxer:
$ cat /etc/pam.d/common-session # # /etc/pam.d/common-session - session-related modules common to all services # # This file is included from other service-specific PAM config files, # and should contain a list of modules that define tasks to be performed # at the start and end of sessions of *any* kind (both interactive and # non-interactive). # # As of pam 1.0.1-6, this file is managed by pam-auth-update by default. # To take advantage of this, it is recommended that you configure any # local modules either before or after the default block, and use # pam-auth-update to manage selection of other modules. See # pam-auth-update(8) for details. # here are the per-package modules (the "Primary" block) session [default=1] pam_permit.so # here's the fallback if no module succeeds session requisite pam_deny.so # prime the stack with a positive return value if there isn't one already; # this avoids us returning an error just because nothing sets a success code # since the modules above will each just jump around session required pam_permit.so # The pam_umask module will set the umask according to the system default in # /etc/login.defs and user settings, solving the problem of different # umask settings with different shells, display managers, remote sessions etc. # See "man pam_umask". session optional pam_umask.so # and here are more per-package modules (the "Additional" block) session required pam_unix.so session required pam_mkhomedir.so skel=/etc/skel umask=0022 session optional pam_ldap.so session optional pam_ck_connector.so nox11 # end of pam-auth-update config
Vegeu també Crear la home al iniciar una sessió amb Samba
Per comprovar el funcionament
$ su sergitur Contrasenya: Creant el directori '/home/sergitur'. ...
El següent esquema ens mostra la flexibilitat de PAM:
Vegeu també:
Els mòduls que ja venen suportats per defecte són proveïts pel paquet libpam-modules:
$ dpkg -l | grep pam ii libpam-modules 0.79-4 Pluggable Authentication Modules for PAM ii libpam-runtime 0.79-4 Runtime support for the PAM library ii libpam0g 0.79-4 Pluggable Authentication Modules library
I es localitzen o instal·len a la carpeta /lib/security:
$ dpkg -L libpam-modules | grep lib/security /lib/security/pam_access.so /lib/security/pam_debug.so /lib/security/pam_deny.so /lib/security/pam_env.so /lib/security/pam_filter.so /lib/security/pam_ftp.so /lib/security/pam_group.so /lib/security/pam_issue.so /lib/security/pam_lastlog.so /lib/security/pam_limits.so /lib/security/pam_listfile.so /lib/security/pam_localuser.so /lib/security/pam_mail.so /lib/security/pam_mkhomedir.so /lib/security/pam_motd.so /lib/security/pam_nologin.so /lib/security/pam_permit.so /lib/security/pam_rhosts_auth.so /lib/security/pam_rootok.so /lib/security/pam_securetty.so /lib/security/pam_selinux.so /lib/security/pam_shells.so /lib/security/pam_stress.so /lib/security/pam_succeed_if.so /lib/security/pam_tally.so /lib/security/pam_time.so /lib/security/pam_unix.so /lib/security/pam_userdb.so /lib/security/pam_warn.so /lib/security/pam_wheel.so /lib/security/pam_xauth.so /lib/security/pam_unix_acct.so /lib/security/pam_unix_auth.so /lib/security/pam_unix_passwd.so /lib/security/pam_unix_session.so
Podeu consultar com funcionen alguns del mòduls més habituals a http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/sag-module-reference.html. Un altre recurs interesant amb exemples és http://www.linuxtopia.org/online_books/espaniol/centos_linux_guides/centos_linux_reference_guide/s1-pam-sample-simple.html
Consulteu:
Cracklib#Configuraci.C3.B3_de_PAM
TODO
As our example, we'll install and configure mod_auth_pam, an Apache module that allows you to authenticate users of your webserver using PAM. For the purpose of this example, I'll assume you have apache installed. If it's not installed already you should be able find installation packages from your distributor.
Our goal will be to configure a restricted area of our webserver, a family/ directory, to authenticate users via PAM. This directory contains private family information, and should only be accessible to members of the user group family.
First, you'll want to download mod_auth_pam from http://blank.pages.de/pam/mod_auth_pam/. The following commands will compile mod_auth_pam (you must be logged in as root): ~# tar xzf mod_auth_pam.tar.gz
~# cd mod_auth_pam−1.0a ~/mod_auth_pam−1.0a# make ~/mod_auth_pam−1.0a# make install
If you have any trouble installing the mod_auth_pam module, make sure you've installed your distribution's apache−dev package. After you've installed mod_auth_pam, you'll need to restart apache. Apache can usually by restarted by typing the following command (again, you must be root): ~# /etc/init.d/apache restart
The PAM configuration for Apache is stored in /etc/pam.d/httpd. The default configuration (which was installed when you installed mod_auth_pam) is secure, but it uses a module (pam_pwdb.so) which may not be available on many systems. (Besides, configuring it from scratch will be fun!) So delete the /etc/pam.d/httpd file, and start with a fresh one. 5.4.1. Deciding how to configure PAM If we're going to configure how PAM deals with Apache's authentication requests, we need to figure out exactly what we need PAM to check for. First, we want PAM to make sure the user's password matches their password in the standard unix password database. This sounds like the 'auth' type and the pam_unix.so module. We'll want the module's control type to be set to 'required', so authentication will fail without a correct password. Here's what the first line of our /etc/pam.d/httpd looks like:
auth required pam_unix.so
Secondly, we must make sure that the users account is valid (i.e. their password has not expired or any such nastiness). This is the 'account' type and is also provided by the pam_unix.so module. Again, we'll set this module's control type to 'required'. After adding this line, our /etc/pam.d/httpd configuration looks like this:
auth required pam_unix.so account required pam_unix.so
It's not terribly sophisticated, but it does the job. It ought to be a good start for learning how to configure PAM services. 5.5. Configuring Apache Now that PAM is configured to authenticate apache's requests, we'll configure apache to properly utilize PAM authentication to restrict access to the family/ directory. To do so, add the following lines to your httpd.conf (usually stored in /etc/apache/ or /etc/httpd):
<Directory /var/www/family> AuthPAM_Enabled on AllowOverride None AuthName "Family Secrets" AuthType "basic" require group family </Directory>
You may need to replace /var/www/ with the default location of web documents, which is often /home/httpd/. Wherever that is, you'll need to create the family directory. Before we test our setup, I'll take a moment to explain the Apache configuration you just entered. The <Directory> directive is used to encapsulate configuration data for this directory. Inside this directive, we've enabled PAM authentication ("AuthPAM_enabled on"), turned off any overriding of this configuration ("AllowOverride none"), named this authentication zone "Family Secrets" ("AuthName "Family Secrets""), set the http authentication (not the PAM authentication) type to the default ("AuthType "basic""), and required the user group family ("require group family"). 5.6. Testing our setup Now that we've got everything setup up properly, it's time to revel in our success. Fire up your favorite web browser and head over to http://your−domain/family/ (replacing your−domain with, well, your domain). You are now an uber−authenticator!
Si feu una cerca als repositoris, veureu la llarga llista de mòduls possibles que es poden instal·lar:
$ sudo apt-cache search libpam libpam libpam-ccreds - Pam module to cache authentication credentials libpam-chroot - Chroot Pluggable Authentication Module for PAM libpam-cracklib - PAM module to enable cracklib support libpam-devperm - PAM module to change device ownership on login libpam-doc - Documentation of PAM libpam-dotfile - A PAM module which allows users to have more than one password libpam-encfs - PAM module to automatically mount encfs filesystems on login libpam-foreground - create lockfiles describing which users own which console libpam-heimdal - PAM module for Heimdal Kerberos 5 libpam-http - a PAM module to authenticate via http/https libpam-krb5 - PAM module for MIT Kerberos libpam-ldap - Pluggable Authentication Module allowing LDAP interfaces libpam-modules - Pluggable Authentication Modules for PAM libpam-mount - PAM module that can mount volumes for a user session libpam-musclecard - PAM module for MuscleCard Framework libpam-mysql - PAM module allowing authentication from a MySQL server libpam-ncp - PAM module allowing authentication from a NetWare server libpam-openafs-kaserver - AFS distributed filesystem kaserver PAM module libpam-openafs-session - PAM Module to get AFS tokens and set up PAG libpam-opie - Use OTPs for PAM authentication libpam-p11 - PAM module for using PKCS#11 smart cards libpam-passwdqc - replacement for the pam_cracklib module libpam-pgsql - PAM module to authenticate using a PostgreSQL database libpam-poldi - PAM module allowing authentication using a OpenPGP smartcard libpam-pwdfile - PAM module allowing authentication via an /etc/passwd-like file libpam-pwgen - a password generator libpam-radius-auth - The PAM RADIUS authentication module libpam-runtime - Runtime support for the PAM library libpam-shishi - PAM module for Shishi Kerberos v5 libpam-ssh - enable SSO behavior for ssh and pam libpam-tmpdir - automatic per-user temporary directories libpam-umask - adjust users' default umask using PAM libpam-unix2 - Blowfish-capable PAM module
Com podeu veure normalment els paquets s'anomenen libpam-xxx.
Hi han mòduls per a tots tipus d'autenticacions: