feat: add pam-pkcs11 configuration
Recommends libpam-pkcs11 package. Add configuration for Safenet module (pam_pkcs11.conf) Add UID mapper generator (pkcs11_generate_uids) Configure certificates for pam_pkcs11 from postinst.
This commit is contained in:
1
Notes.md
1
Notes.md
@@ -124,6 +124,7 @@ On introduit les fonctionnalités pas à pas:
|
|||||||
- configuration PKCS#11 avec `pam_sss`
|
- configuration PKCS#11 avec `pam_sss`
|
||||||
- suppression de `pam_krb5` et `pam_pkcs11`
|
- suppression de `pam_krb5` et `pam_pkcs11`
|
||||||
|
|
||||||
|
Voir [Notes_pkcs11.md](Notes_pkcs11.md) pour la configuration `pam_pkcs11`.
|
||||||
|
|
||||||
[GNOME Configuration - Simple Greeter Configuration]: https://help.gnome.org/admin/gdm/stable/configuration.html.en#greeterconfiguration
|
[GNOME Configuration - Simple Greeter Configuration]: https://help.gnome.org/admin/gdm/stable/configuration.html.en#greeterconfiguration
|
||||||
[GNOME - Add a greeter logo to the login screen]: https://help.gnome.org/admin/system-admin-guide/stable/login-logo.html.en
|
[GNOME - Add a greeter logo to the login screen]: https://help.gnome.org/admin/system-admin-guide/stable/login-logo.html.en
|
||||||
|
|||||||
186
Notes_pkcs11.md
Normal file
186
Notes_pkcs11.md
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
Configuration pam-pkcs11
|
||||||
|
========================
|
||||||
|
|
||||||
|
Thierry Tallagrand à la rescousse !
|
||||||
|
|
||||||
|
Installation:
|
||||||
|
|
||||||
|
```
|
||||||
|
# apt install libpam-pkcs11
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouts des certificats Orange, parce que pam-pcs11 utilise son propre trousseau:
|
||||||
|
```
|
||||||
|
# mkdir /etc/pki/nssdb
|
||||||
|
# orange-certupdate /etc/pki/nssdb
|
||||||
|
# cp /usr/share/ca-certificates/orange/* /etc/pam_pkcs11/cacerts
|
||||||
|
# (cd /etc/pam_pkcs11/cacerts && pkcs11_make_hash_link)
|
||||||
|
```
|
||||||
|
|
||||||
|
Création d'une configuration spécifique `/etc/pam_pkcs11/pam_pkcs11.conf`
|
||||||
|
pour le dongle Safenet, en s'inspirant du fichier d'exemple de la documentation
|
||||||
|
dans `/usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example`.
|
||||||
|
Il y a trois parties dans ce fichier:
|
||||||
|
|
||||||
|
- les paramètres globaux de pam-pkcs11
|
||||||
|
- la description du module Safenet
|
||||||
|
- la définition du (des) mapper(s) certificat -> utilisateur.
|
||||||
|
|
||||||
|
Pour bien comprendre le rôle des différentes propriétés top-level et des
|
||||||
|
modules, voir le fichier `/usr/share/doc/libpam-pkcs11/README.gz`. Pour
|
||||||
|
une présentation de ce qu'est un mapper, les deux processus de login
|
||||||
|
quand on utilise un mapper (important), et la description des mappers
|
||||||
|
fournis, voir `/usr/share/doc/libpam-pkcs11/README.mappers.gz`.
|
||||||
|
|
||||||
|
On utilise le mapper `uid` parce que cette propriété est présente dans
|
||||||
|
le champ 'Subject' du certificat `Auth`, elle est reconnue automatiquement.
|
||||||
|
On aura besoin d'un fichier de mapping qui fait correspondre la valeur
|
||||||
|
de l'UID du certificat avec le nom d'un utilisateur local sur la machine.
|
||||||
|
La correspondance est triviale, les UID sont en majuscule et les utilisateurs
|
||||||
|
en minuscules:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cat /etc/pam_pkcs11/uid_mapping
|
||||||
|
ABCD1234 -> abcd1234
|
||||||
|
```
|
||||||
|
|
||||||
|
Voir le script `/usr/bin/pkcs11_generate_uids` pour générer ce fichier
|
||||||
|
automatiquement à partir de la définition des utilisateur locaux dans
|
||||||
|
`/etc/passwd`.
|
||||||
|
|
||||||
|
Une fois le fichier de mapping en place, on peut le tester avec la
|
||||||
|
commande `pklogin_finder` après avoir inséré le dongle:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pklogin_finder
|
||||||
|
[...]
|
||||||
|
DEBUG:mapper_mgr.c:213: unloading mapper module list
|
||||||
|
DEBUG:mapper_mgr.c:137: calling mapper_module_end() uid
|
||||||
|
DEBUG:mapper_mgr.c:148: Module uid is static: don’t remove
|
||||||
|
DEBUG:pkcs11_lib.c:1490: logout user
|
||||||
|
DEBUG:pkcs11_lib.c:1497: closing the PKCS #11 session
|
||||||
|
DEBUG:pkcs11_lib.c:1503: releasing keys and certificates
|
||||||
|
DEBUG:pklogin_finder.c:169: releasing pkcs #11 module…
|
||||||
|
DEBUG:pklogin_finder.c:172: Process completed
|
||||||
|
[...]
|
||||||
|
DEBUG:pklogin_finder.c:151: Certificate is valid and maps to user tmzf5455
|
||||||
|
```
|
||||||
|
|
||||||
|
Le module pam-pkcs11 est maintenant configuré, il reste à le faire
|
||||||
|
prendre en compte par GDM:
|
||||||
|
```
|
||||||
|
$ update-alternatives --config gdm-smartcard
|
||||||
|
|
||||||
|
There are 3 choices for the alternative gdm-smartcard (providing /etc/pam.d/gdm-smartcard).
|
||||||
|
Selection Path Priority Status
|
||||||
|
|
||||||
|
0 /etc/pam.d/gdm-smartcard-sssd-exclusive 50 auto mode
|
||||||
|
1 /etc/pam.d/gdm-smartcard-pkcs11-exclusive 30 manual mode
|
||||||
|
2 /etc/pam.d/gdm-smartcard-sssd-exclusive 50 manual mode
|
||||||
|
3 /etc/pam.d/gdm-smartcard-sssd-or-password 40 manual mode
|
||||||
|
|
||||||
|
Press to keep the current choice[*], or type selection number:
|
||||||
|
```
|
||||||
|
|
||||||
|
Choisir 1) pour `gdm-smartcard-pkcs11-exclusive` et valider. Important: il faut
|
||||||
|
aussi que GDM permette le login par smartcard, voir les notes concernant GDM.
|
||||||
|
|
||||||
|
|
||||||
|
Voir [l'article original sur le wiki](
|
||||||
|
https://yourdev.tech.orange/linux-article/login-with-pki/) avec screenshots.
|
||||||
|
|
||||||
|
|
||||||
|
Saisie du compte avec GDM
|
||||||
|
=========================
|
||||||
|
|
||||||
|
Avec la première tentative de configuration issue directement de
|
||||||
|
`pam_pkcs11.conf.example`, on constate lorsque le dongle PKI est inséré
|
||||||
|
que GDM demande la saisie explicite du nom de l'utilisateur avant de
|
||||||
|
demander le PIN. C'est différent du mode habituel sans PKCS#11 où
|
||||||
|
GDM propose l'utilisateur (liste), et il n'y a que le mot de passe
|
||||||
|
à saisir.
|
||||||
|
|
||||||
|
Le comportement observé correspond au premier mode de fonctionnement
|
||||||
|
décrit dans `/usr/share/doc/libpam-pkcs11/README.mappers.gz`:
|
||||||
|
```
|
||||||
|
Normal pam-pkcs11 login process involves the following procedures
|
||||||
|
- Enter login
|
||||||
|
- Ask for PIN
|
||||||
|
- Open and validate certificate
|
||||||
|
- Map certificate into an user (*)
|
||||||
|
- Check if login and user matches (**)
|
||||||
|
```
|
||||||
|
|
||||||
|
alors que ce qu'on voudrait c'est le deuxième mode:
|
||||||
|
```
|
||||||
|
An alternate way of working is by mean of not providing user name:
|
||||||
|
- Detect if a card is inserted
|
||||||
|
- Ask for PIN
|
||||||
|
- Open and validate certificate
|
||||||
|
- Map certificate into an user (*)
|
||||||
|
- open session for deduced login
|
||||||
|
```
|
||||||
|
|
||||||
|
On passe de l'un a l'autre avec la propriétés top-level `card_only` qui
|
||||||
|
est décrité dans `/usr/share/doc/libpam-pkcs11/README.gz`:
|
||||||
|
```
|
||||||
|
card_only
|
||||||
|
Always try to get the userid from the certificate, don't prompt for the
|
||||||
|
user name if the card is present, and if the token is present, then we
|
||||||
|
must use it to authenticate.
|
||||||
|
|
||||||
|
wait_for_card
|
||||||
|
This option needs card_only to be set. This will make the system wait
|
||||||
|
for the token to be inserted on login, or after login it will require
|
||||||
|
the same token be inserted to unlock the system.
|
||||||
|
```
|
||||||
|
|
||||||
|
La documentation dit aussi que dans le deuxième mode il faut aussi le
|
||||||
|
module `pam-mkhomedir.so` pour créer dynamiquement le compte utilisateur,
|
||||||
|
ce n'est pas forcément ce qu'on veut, à voir si ça marche sans avec
|
||||||
|
un compte existant.
|
||||||
|
|
||||||
|
Néanmoins, avec `card_only = true;` dans `pam_pkcs11.conf`, GDM continue à
|
||||||
|
demander un identifiant, bref il semble que cela ne fonctionne pasn au moins
|
||||||
|
sur Hirsute ... Bug dans GDM ? Fonctionnalité non prise en compte ?
|
||||||
|
|
||||||
|
|
||||||
|
Activer PKCS#11 dans GDM
|
||||||
|
========================
|
||||||
|
|
||||||
|
Trois opérations à faire:
|
||||||
|
|
||||||
|
- basculer l'alternative `gdm-smartcard` sur `gdm-smartcard-pkcs11-exclusive`
|
||||||
|
- activer l'authentification par smartcard dans `dconf` pour GDM
|
||||||
|
- redémarrer le service
|
||||||
|
|
||||||
|
soit:
|
||||||
|
|
||||||
|
```
|
||||||
|
# update-alternatives --set gdm-smartcard /etc/pam.d/gdm-smartcard-pkcs11-exclusive
|
||||||
|
# sed -Ei 's/(enable-smartcard-authentication)=.*/\1=true/' /etc/dconf/db/gdm.d/03-smartcard
|
||||||
|
# dconf update
|
||||||
|
# systemctl restart gdm3
|
||||||
|
```
|
||||||
|
|
||||||
|
Il faudrait un script pour automatiser cela ...
|
||||||
|
|
||||||
|
Limitations
|
||||||
|
===========
|
||||||
|
|
||||||
|
Le paquet `libpam-pkcs11` ne fournit pas de configuration pour `pam-auth-update`
|
||||||
|
dans `/usr/share/pam-configs`, donc l'authentification PKCS#11 ne peut pas
|
||||||
|
être ajoutée automatiquement dans `/etc/pam.d/common-auth`. Par conséquent, elle
|
||||||
|
ne sera disponible que dans GDM via `/etc/pam.d/gdm-smartcard`, si on la voulait
|
||||||
|
aussi en mode console il faudrait bricoler dans la configuration PAM ...
|
||||||
|
|
||||||
|
Dans `gdm-smartcard-pkcs11-exclusive`, il n'y a que le module `pam_pkcs11.so`,
|
||||||
|
donc après authentification par token on n'obtiendra pas de TGT Kerberos. Il
|
||||||
|
faudrait bricoler pour rajouter `pam_krb5.so`, sans aucune garantie que ça
|
||||||
|
marche, le problème étant 1) faire circuler le PIN et 2) faire comprendre à
|
||||||
|
`pam_krb5.so` qu'il s'agit d'un PIN et pas d'un mot de passe... Autant essayer
|
||||||
|
de faire cela avec SSSD.
|
||||||
|
|
||||||
|
Contrairement à ce que `pkcs11-exclusive` laisse entendre, si le dongle n'est
|
||||||
|
pas présent dans le port USB, on peut toujours se connecter par login/password
|
||||||
|
(mais Kerberos foonctionnera-t'il si `pam_krb5.so` est présent ?)
|
||||||
3
debian/control
vendored
3
debian/control
vendored
@@ -20,7 +20,8 @@ Depends: ${misc:Depends},
|
|||||||
orange-krb5,
|
orange-krb5,
|
||||||
orange-dongle-aladdin
|
orange-dongle-aladdin
|
||||||
Recommends:
|
Recommends:
|
||||||
krb5-auth-dialog
|
krb5-auth-dialog,
|
||||||
|
libpam-pkcs11
|
||||||
Suggests:
|
Suggests:
|
||||||
orange-yourdev-ldap,
|
orange-yourdev-ldap,
|
||||||
orange-yourdev-setup,
|
orange-yourdev-setup,
|
||||||
|
|||||||
19
debian/postinst
vendored
19
debian/postinst
vendored
@@ -7,12 +7,31 @@ case "$1" in
|
|||||||
if [ -x /usr/bin/dconf ] ; then
|
if [ -x /usr/bin/dconf ] ; then
|
||||||
dconf update
|
dconf update
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Configure NSS for pam-pkcs11
|
||||||
|
mkdir -p /etc/pki/nssdb
|
||||||
|
orange-certupdate /etc/pki/nssdb || true
|
||||||
|
|
||||||
|
# configure pam-pkcs11
|
||||||
|
if [ -d /etc/pam_pkcs11 ] ; then
|
||||||
|
# add Orange certificates
|
||||||
|
mkdir -p /etc/pam_pkcs11/cacerts
|
||||||
|
cp /usr/share/ca-certificates/orange/* /etc/pam_pkcs11/cacerts
|
||||||
|
(cd /etc/pam_pkcs11/cacerts && pkcs11_make_hash_link ) || true
|
||||||
|
# generate uid mapping from /etc/passwd
|
||||||
|
pkcs11_generate_uids || true
|
||||||
|
# Note: PAM module pkcs11 cannot be configured using command
|
||||||
|
# pam-auth-update because package libpam-pkcs11 does not provide
|
||||||
|
# a config file in dir /usr/share/pam-configs.
|
||||||
|
fi
|
||||||
|
|
||||||
# Configure PAM for credential cache
|
# Configure PAM for credential cache
|
||||||
apt-mark manual libpam-ccreds >/dev/null || true
|
apt-mark manual libpam-ccreds >/dev/null || true
|
||||||
if [ -e /usr/share/pam-configs/ccreds-check ] ; then
|
if [ -e /usr/share/pam-configs/ccreds-check ] ; then
|
||||||
pam-auth-update --force --package --enable \
|
pam-auth-update --force --package --enable \
|
||||||
ccreds-check ccreds-save || true
|
ccreds-check ccreds-save || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Configure PAM for Kerberos
|
# Configure PAM for Kerberos
|
||||||
if [ -e /usr/share/pam-configs/krb5 ] ; then
|
if [ -e /usr/share/pam-configs/krb5 ] ; then
|
||||||
pam-auth-update --force --package --enable krb5 || true
|
pam-auth-update --force --package --enable krb5 || true
|
||||||
|
|||||||
60
etc/pam_pkcs11/pam_pkcs11.conf
Normal file
60
etc/pam_pkcs11/pam_pkcs11.conf
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# Configuration for pam_pkcs11 using the Safenet dongle.
|
||||||
|
#
|
||||||
|
# see /usr/share/doc/libpam-pkcs11/README.gz for description of
|
||||||
|
# top-level configuration properties and common module properties.
|
||||||
|
#
|
||||||
|
# see /usr/share/doc/libpam-pkcs11/README.mapper.gz for presentation
|
||||||
|
# of what is a cert mapper, the two different login process using a
|
||||||
|
# mapper (important), and a description of provided mappers.
|
||||||
|
#
|
||||||
|
# see /usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example
|
||||||
|
# for a full configuration file with all modules and mappers.
|
||||||
|
#
|
||||||
|
pam_pkcs11 {
|
||||||
|
|
||||||
|
nullok = true;
|
||||||
|
debug = true;
|
||||||
|
use_first_pass = false;
|
||||||
|
try_first_pass = false;
|
||||||
|
use_authtok = false;
|
||||||
|
card_only = true;
|
||||||
|
use_pkcs11_module = safenet;
|
||||||
|
use_mappers = uid,null;
|
||||||
|
|
||||||
|
# Aladdin SAFENET
|
||||||
|
pkcs11_module safenet {
|
||||||
|
module = /usr/lib/libeToken.so
|
||||||
|
description = "Aladdin safenet";
|
||||||
|
slot_num = 0;
|
||||||
|
#slot_description = "none";
|
||||||
|
support_threads = false;
|
||||||
|
ca_dir = /etc/pam_pkcs11/cacerts;
|
||||||
|
crl_dir = /etc/pam_pkcs11/crls;
|
||||||
|
nss_dir = /etc/pki/nssdb;
|
||||||
|
cert_policy = ca,signature;
|
||||||
|
token_type = "Smart card";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# uid - Maps Subject Unique Identifier field (if exist) to login
|
||||||
|
mapper uid {
|
||||||
|
debug = true;
|
||||||
|
module = internal;
|
||||||
|
# module = /lib/x86_64-linux-gnu/pam_pkcs11/uid_mapper.so;
|
||||||
|
ignorecase = false;
|
||||||
|
mapfile = file:///etc/pam_pkcs11/uid_mapping;
|
||||||
|
#mapfile = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Null ( no map ) mapper. when user as finder matchs to NULL or "nobody"
|
||||||
|
mapper null {
|
||||||
|
debug = true;
|
||||||
|
# module = /lib/x86_64-linux-gnu/pam_pkcs11/null_mapper.so;
|
||||||
|
module = internal ;
|
||||||
|
# select behavior: always match, or always fail
|
||||||
|
default_match = false;
|
||||||
|
# on match, select returned user
|
||||||
|
default_user = nobody ;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
usr/sbin/pkcs11_generate_uids
Executable file
19
usr/sbin/pkcs11_generate_uids
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Written by Michel Decima
|
||||||
|
# Copyright 2021 Orange
|
||||||
|
#
|
||||||
|
# Generate uid mapping for pam_pkcs11 using /etc/passwd
|
||||||
|
#
|
||||||
|
|
||||||
|
(( EUID == 0 )) || { echo 2>&1 "Not root." ; exit 1 ; }
|
||||||
|
|
||||||
|
mkdir -p /etc/pam_pkcs11
|
||||||
|
# generate uid mapping for uppercase login ABCD1234 -> abcd1234
|
||||||
|
getent -s files passwd \
|
||||||
|
| awk -F: '
|
||||||
|
/[a-z]{4}[0-9]{4}/ {
|
||||||
|
printf "%s -> %s\n", toupper($1), $1
|
||||||
|
}' \
|
||||||
|
>> /etc/pam_pkcs11/uid_mapping
|
||||||
|
sort -u -o /etc/pam_pkcs11/uid_mapping /etc/pam_pkcs11/uid_mapping
|
||||||
Reference in New Issue
Block a user