Il plugin di autenticazione PAM

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

A partire dalla versione 5.2.10, MariaDB include il plugin di autenticazione PAM. PAM è l'acronimo di Pluggable Authentication Modules e si tratta di un framework di autenticazione per Linux, FreeBSD, Solaris e altri sistemi operativi.

Nota: Windows non usa PAM, perciò il plugin non funzionerà su tale sistema. Tuttavia, un client Windows può connettersi a un server MariaDB che gira su Linux o Solaris, per esempio che utilizza PAM.

Casi d'uso

PAM rende possibile l'implementazione di diversi scenari di autenticazione, di diversa complessità. Per esempio:

  • Autenticazione usando le password di /etc/shadow (questo è ciò che solitamente PAM fa per i normali login da shell, per pop3, imap e per molti altri servizi);
  • Autentitazione tramite LDAP;
  • Autenticazione tramite le passphrase di SSH;
  • Autenticazione tramite una password che funziona una sola volta (anche con un SMS di conferma!);
  • Combinare diversi moduli di autenticazione, dove il login ha successo se uno o se tutti passano il controllo;
  • Scadenza delle passsword;
  • Mappare i nomi utente;
  • Limitare l'accesso per ora, data, giorno della settimana, etc.
  • Log dei tentativi di accesso;
  • E così via, questo elenco non è esaustivo.

Installazione

Il plugin non viene caricato per default; è possibile installarlo così:

MariaDB [test]> INSTALL PLUGIN pam SONAME 'auth_pam.so';

oppure aggiungendo --plugin-load=auth_pam.so alla riga di comando del server, o alla sezione [mysqld] nel file my.cnf.

Similmente a tutti gli altri Plugin di Autenticazione, per creare un utente MariaDB che si autentichi con PAM, si usi il comando:

CREATE USER nome_utente@nome_hostIDENTIFIED VIA pam

oppure, ad esempio:

GRANT SELECT ON db.* TO serg IDENTIFIED VIA pam

Opzionalmente, è possibile specificare un nome di servizio PAM service name, ad esempio:

CREATE USER test_pam IDENTIFIED VIA pam USING 'mariadb_mtr';

Questa riga (copiata testualmente dalla test suite) crea un utente che dovrà autenticarsi via PAM, utilizzando il servizio mariadb_mtr.

Se il nome del servizio non è specificato, verrà usato "mysql" come servizio di default per PAM.

PAM Configuration

The PAM plugin tells MariaDB to delegate the authentication to the PAM subsystem. How exactly the authentication is performed depends on how PAM was configured. Typically, PAM configuration can be found in /etc/pam.d/ or in /etc/pam.conf. The syntax of these configuration files is described in your OS manual, for example, in man pam.d. A minimal example, that we use in our test suite, is

auth            required        pam_mariadb_mtr.so pam_test
account         required        pam_mariadb_mtr.so

This needs to be put in /etc/pam.d/mariadb_mtr — file name must match the name of the PAM service. This simple configuration file instructs the PAM subsystem that for successful authentication it is required that pam_mariadb_mtr.so module (our testing pam module) returns a success. And for an account to be valid, it is required that pam_mariadb_mtr.so module returns a success. You can find many other examples in your /etc/pam.d/ directory.

Note: if you configure PAM to use pam_unix.so and notice that MariaDB needs to run as a root user to be able to access /etc/shadow — try to upgrade your PAM installation. Newer versions of PAM do not require pam_unix.so to be run as root.

Dialog plugin

PAM authentication uses a dialog client plugin to communicate with the user. This allows MariaDB to support arbitrarily complex PAM configurations with regular or one-time passwords, challenge-response, multiple questions, or just about anything else. There is no need to install or enable anything — the dialog plugin is loaded by the client library completely automatically and transparently for the application.

User name mapping

Although PAM modules usually do not do that, PAM may change the user name in the process of authentication. For example, according to the PAM specification, one may start authenticating as John and end up being authenticated as Jim.

The MariaDB PAM authentication plugin fully supports it — the original user name is returned by the SQL function USER(), while the authenticated user name (if changed) is returned by the SQL function CURRENT_USER(), and it is the latter which defines what privileges are available to a connected user.

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.