RHEL7: utilizzare Kerberos per controllare l’accesso alle condivisioni di rete NFS

By | Dicembre 1, 2018

Nota: questo è un obiettivo d’esame RHCE 7.

Prerequisiti

Innanzitutto, devi configurare un KDC (Kerberos Distribution Center) chiamato kbserver.example.com.

Quindi, saranno necessari due server aggiuntivi: un server NFS (qui nfsserver.example.com) e un client NFS (qui nfsclient.example.com). Se hai solo due server/VM, raggruppa i server KDC e NFS sullo stesso computer.
Inoltre, per far funzionare Kerberos, la sincronizzazione NTP e la risoluzione del nome host devono funzionare.
È consigliabile configurare un server DNS principale, ma se non è disponibile o non funzionante, aggiungere le seguenti righe nel file /etc/hosts di ciascun server (sostituire gli indirizzi IP specificati con i propri):

192.168.1.11 kbserver.example.com
192.168.1.12 nfsserver.example.com
192.168.1.13 nfsclient.example.com

Attenzione: quando si aggiunge una nuova riga nel file /etc/hosts, è necessario scrivere il nome di dominio completo subito dopo l’indirizzo IP. Se si utilizzano uno o più alias e li si aggiunge prima del nome di dominio completo o se non si specifica il nome di dominio completo, Kerberos non funzionerà.

Configurazione del server NFS Kerberos

Prima di aggiungere la configurazione Kerberos, configura il server NFS (usa il nome host nfsserver.example.com come in questo tutorial).

Quindi, dovrai aggiungere la configurazione del client Kerberos (sostituisci kbclient.example.com con nfsserver.example.com come in questo tutorial).

Infine, aggiungi la parte NFS specifica ai principal:

# kadmin
Authenticating as principal root/admin@EXAMPLE.COM with password.
Password for root/admin@EXAMPLE.COM: kerberos
kadmin:  addprinc -randkey nfs/nfsserver.example.com
WARNING: no policy specified for host/kbclient.example.com@EXAMPLE.COM; defaulting to no policy
Principal "host/nfsserver.example.com@EXAMPLE.COM" created.

Crea una copia locale memorizzata per impostazione predefinita nel file /etc/krb5.keytab:

kadmin:  ktadd nfs/nfsserver.example.com
Entry for principal host/nfsserver.example.com with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type des3-cbc-sha1 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type arcfour-hmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type camellia256-cts-cmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type camellia128-cts-cmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type des-hmac-sha1 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsserver.example.com with kvno 2, encryption type des-cbc-md5 added to keytab WRFILE:/etc/krb5.keytab.
kadmin:  quit

Modifica il file /etc/exports e aggiungi l’opzione sec = krb5 (o l’opzione che vuoi, vedi nota):

/home/tools nfsclient.example.com(rw,no_root_squash,sec=krb5)
/home/guests nfsclient.example.com(rw,no_root_squash,sec=krb5)

Nota 1: l’opzione sec accetta quattro valori diversi: sec = sys (non utilizzata da Kerberos), sec = krb5 (solo autenticazione utente Kerberos), sec = krb5i (autenticazione utente Kerberos e verifica dell’integrità), sec = krb5p (autenticazione utente Kerberos, integrità controllo e crittografia del traffico NFS). Più alto è il livello, più si verifica un consumo di risorse.
Nota 2: Se si desidera utilizzare sec = sys (non utilizzare Kerberos), è necessario eseguire anche setsebool -P nfsd_anon_write 1

Esporta la nuova configurazione:

# exportfs -avr
exporting nfsclient.example.com:/home/guests
exporting nfsclient.example.com:/home/tools

Controlla la tua configurazione:

# showmount -e localhost
Export list for localhost:
/home/guests nfsclient.example.com
/home/tools  nfsclient.example.com

Attiva all’avvio e avvia il servizio nfs-secure-server (solo RHEL 7.0):

# systemctl enable nfs-secure-server && systemctl start nfs-secure-server

Nota: se si desidera ottenere maggiori informazioni nel file /var/log/messages, modificare il file /etc/sysconfig/nfs, assegnare la stringa “-vvv” alle variabili RPCIDMAPDARGS/RPCSVCGSSDARGS e riavviare i demoni nfs-idmap/nfs-secure-server.

Configurazione del client NFS Kerberos

Prima di aggiungere la configurazione Kerberos, configura il client NFS (usa il nome host nfsclient.example.com come in questo tutorial).

Quindi, dovrai aggiungere la configurazione del client Kerberos (sostituisci kbclient.example.com con nfsclient.example.com come in questo tutorial).

Infine, aggiungi la parte NFS specifica ai principal:

# kadmin
Authenticating as principal root/admin@EXAMPLE.COM with password.
Password for root/admin@EXAMPLE.COM: kerberos
kadmin:  addprinc -randkey nfs/nfsclient.example.com
WARNING: no policy specified for host/kbclient.example.com@EXAMPLE.COM; defaulting to no policy
Principal "host/nfsclient.example.com@EXAMPLE.COM" created.

Crea una copia locale memorizzata per impostazione predefinita nel file /etc/krb5.keytab:

kadmin:  ktadd nfs/nfsclient.example.com
Entry for principal host/nfsclient.example.com with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type des3-cbc-sha1 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type arcfour-hmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type camellia256-cts-cmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type camellia128-cts-cmac added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type des-hmac-sha1 added to keytab WRFILE:/etc/krb5.keytab.
Entry for principal host/nfsclient.example.com with kvno 2, encryption type des-cbc-md5 added to keytab WRFILE:/etc/krb5.keytab.
kadmin:  quit

Attiva all’avvio e avvia il servizio nfs-secure (solo RHEL 7.0):

# systemctl enable nfs-secure && systemctl start nfs-secure

Attiva all’avvio e avvia il target nfs-client (RHEL 7.1 e successivi):

# systemctl enable nfs-client.target && systemctl start nfs-client.target

Nota 1: dal momento che RHEL 7.1, il servizio nfs-secure viene avviato automaticamente se esiste un file /etc/krb5.keytab.
Nota 2: se si desidera ottenere maggiori informazioni nel file / var / log / messages, modificare il file / etc / sysconfig / nfs, assegnare la stringa “-vvv” alle variabili RPCIDMAPDARGS/RPCGSSDARGS e riavviare i demoni nfs-idmap/nfs-secure.
Nota 3: Con la release RHEL 7.3, il sistema Systemd init è in grado di utilizzare alias. Ad esempio, nfs.service è un collegamento simbolico/alias al file del servizio nfs-server.service. Ciò consente, ad esempio, di utilizzare il comando systemctl status nfs.service invece di systemctl status nfs-server.service.

Montare la directory remota:

# mount -t nfs4 -o sec=krb5 nfsserver.example.com:/home/tools /mnt

Nota 1: Se viene visualizzato il messaggio di errore “mount.nfs4: è stata specificata un’opzione di montaggio non corretta”, verificare di aver avviato i daemon corretti.
Nota 2: non è necessario specificare l’opzione rw, viene eseguita per impostazione predefinita.
Nota3: è possibile verificare quali condivisioni vengono esportate dal server NFS con il comando showmount -e nfsserver.example.com ma è necessario prima arrestare Firewalld sul server NFS (o aprire le 111 porte TCP e 20048 TCP sul server NFS) .
nota4: se non si specifica l’opzione sec, il meccanismo di sicurezza sarà negoziato in modo trasparente con il server remoto (vedere i dettagli qui).

Per impostare in modo permanente il montaggio, incolla la seguente riga nel file / etc / fstab:

nfsserver.example.com:/home/tools /mnt nfs4 sec=krb5

Passa all’utente user01:

# su - user01

Crea un ticket Kerberos:

$ kinit
Password for user01@EXAMPLE.COM: user01

Crea un file chiamato testFile:

$ cd /mnt
$ echo "This is a test." >testFile

Controlla il risultato:

$ ls -l
total 8
-rw-rw-r--. 1 user01 user01 16 Sep  7 16:42 testFile

One thought on “RHEL7: utilizzare Kerberos per controllare l’accesso alle condivisioni di rete NFS

  1. Pingback: Obiettivi esame RHCE 7 - prometheusproject

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.