Ricerca nel sito web

Proteggi il server FreeIPA con il certificato SSL Let's Encrypt


FreeIPA è una potente soluzione open source creata per fornire un modo centralizzato di gestire l'autenticazione, gli archivi di identità, le policy e le policy di autorizzazione in un dominio basato su Linux. Abbiamo una serie di articoli che parlano dell'installazione di FreeIPA Server su diverse distribuzioni Linux. In questa guida discuteremo di come proteggere l'interfaccia web del server FreeIPA utilizzando i certificati SSL gratuiti Let's Encrypt.

Come prerequisito avrai bisogno di un'installazione funzionante di FreeIPA Server sul tuo sistema. Puoi fare riferimento alle nostre guide nei link seguenti:

  • Installa FreeIPA Server su Rocky Linux 8/CentOS 8
  • Installa FreeIPA Server su CentOS 7
  • Installa e configura il server FreeIPA su Rocky Linux 8

Una volta installato FreeIPA Server, conferma che funziona ottenendo il ticket Kerberos come utente amministratore:

$ sudo kinit admin
Password for [email :

$ sudo klist
Ticket cache: KCM:0
Default principal: admin@COMPUTINGFORGEEKS.COM

Valid starting       Expires              Service principal
08/02/202317:42:38  08/03/2023 17:42:31  krbtgt/COMPUTINGFORGEEKS.COM@COMPUTINGFORGEEKS.COM

Installa il repository EPEL e Certbot

Sui sistemi basati su RHEL i pacchetti Certbot sono disponibili nel repository EPEL. Certbot è pensato per essere utilizzato per ottenere i certificati Let's Encrypt e, successivamente, per continuare a rinnovare i certificati HTTPS del sito.

Installa epel-release utilizzando il seguente comando:

$ sudo yum install epel-release
Dependencies resolved.
======================================================================================================================================================================================================
 Package                                            Architecture                                 Version                                           Repository                                    Size
======================================================================================================================================================================================================
Installing:
 epel-release                                       noarch                                       8-13.el8                                          extras                                        23 k

Transaction Summary
======================================================================================================================================================================================================
Install  1 Package

Total download size: 23 k
Installed size: 35 k
Is this ok [y/N]: y

Successivamente installa certbot con il comando successivo:

$ sudo yum install certbot python3-certbot-apache
....
Transaction Summary
======================================================================================================================================================================================================
Install  36 Packages

Total download size: 5.7 M
Installed size: 20 M
Is this ok [y/N]: y

Conferma che l'installazione dello strumento certibot è andata a buon fine:

$ certbot --version
certbot x.y.z

Proteggi il server FreeIPA con il certificato SSL Let's Encrypt

Richiederemo i certificati Let's Encrypt SSL anziché utilizzare i certificati autofirmati del server.

Eseguire il backup delle chiavi private e dei certificati attuali del server FreeIPA prima di procedere:

sudo cp -r /var/lib/ipa/certs{,.bak}
sudo cp -r /var/lib/ipa/private{,.bak}

Installa l'editor di file git, vim o nano

sudo yum -y install vim nano

Metodo 1: Proteggi il server FreeIPA con Let's Encrypt utilizzando il metodo manuale

Seguire i passaggi seguenti.

Scarica e installa i certificati Let's Encrypt CA

Crea la directory dei certificati:

sudo su -
mkdir freeipa-certs
cd freeipa-certs

Scarica Crittografiamo i certificati CA:

CERTS=("isrgrootx1.pem" "isrg-root-x2.pem" "lets-encrypt-r3.pem" "lets-encrypt-e1.pem" "lets-encrypt-r4.pem" "lets-encrypt-e2.pem")
for CERT in "${CERTS[@]}"
do
  curl -o $CERT "https://letsencrypt.org/certs/$CERT"
done

Installa i certificati Let's Encrypt CA nell'archivio certificati FreeIPA:

CERTS=("isrgrootx1.pem" "isrg-root-x2.pem" "lets-encrypt-r3.pem" "lets-encrypt-e1.pem" "lets-encrypt-r4.pem" "lets-encrypt-e2.pem")
for CERT in "${CERTS[@]}"
do
  ipa-cacert-manage install $CERT
done

Output del comando previsto:

Installing CA certificate, please wait
Verified CN=ISRG Root X1,O=Internet Security Research Group,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
Installing CA certificate, please wait
Verified CN=ISRG Root X2,O=Internet Security Research Group,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
Installing CA certificate, please wait
Verified CN=R3,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
Installing CA certificate, please wait
Verified CN=E1,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
Installing CA certificate, please wait
Verified CN=R4,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
Installing CA certificate, please wait
Verified CN=E2,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful

Aggiorna i database dei certificati IPA locali con i certificati dal server:

$ sudo ipa-certupdate
Systemwide CA database updated.
Systemwide CA database updated.
The ipa-certupdate command was successful

Ottieni certificati Let's Encrypt

Interrompi il servizio httpd per rilasciare la porta 80 necessaria per ottenere i certificati.

sudo systemctl stop httpd

Quindi esegui Certbot per ottenere i certificati Let's Encrypt:

EMAIL="your-email-address"
DOMAIN="idm.example.com"
sudo certbot certonly --standalone --preferred-challenges http --agree-tos -n -d $DOMAIN -m $EMAIL

Assicurati che il comando per la generazione del certificato abbia esito positivo:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Requesting a certificate for idm.example.com
Performing the following challenges:
http-01 challenge for idm.example.com
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/idm.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/idm.example.com/privkey.pem
   Your certificate will expire on 2023-10-27. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

I tuoi certificati dovrebbero essere archiviati nella directory /etc/letsencrypt/live/idm.example.com:

$ ls /etc/letsencrypt/live/idm.example.com
cert.pem  chain.pem  fullchain.pem  privkey.pem  README

Avvia il server httpd dopo aver confermato che sono stati generati i certificati richiesti:

sudo systemctl restart httpd

Aggiungi Let's Encrypt SSL certificati da utilizzare nell'interfaccia utente Web FreeIPA:

DOMAIN="idm.example.com" # Set correct IdM hostname
sudo ipa-server-certinstall -w -d /etc/letsencrypt/live/$DOMAIN/privkey.pem /etc/letsencrypt/live/$DOMAIN/cert.pem --pin=''

Output dell'esecuzione del comando:

Directory Manager password:

Please restart ipa services after installing certificate (ipactl restart)
The ipa-server-certinstall command was successful

Riavvia i servizi FreeIPA

$ sudo ipactl restart
Restarting Directory Service
Restarting krb5kdc Service
Restarting kadmin Service
Restarting httpd Service
Restarting ipa-custodia Service
Restarting pki-tomcatd Service
Restarting ipa-otpd Service
ipa: INFO: The ipactl command was successful

La conferma del certificato SSL attualmente utilizzato può essere effettuata dal terminale o dal browser web.

Utilizzo di OpenSSL:

$ openssl s_client -showcerts -verify 5 -connect $(hostname -f):443
verify depth is 5
CONNECTED(00000003)
depth=2 C = US, O = Internet Security Research Group, CN = ISRG Root X1
verify return:1
depth=1 C = US, O = Let's Encrypt, CN = R3
verify return:1
depth=0 CN = idm.example.com
verify return:1
---
Certificate chain
 0 s:CN = idm.example.com
   i:C = US, O = Let's Encrypt, CN = R3
-----BEGIN CERTIFICATE-----


Dalla console Web:

Metodo 2: proteggere il server FreeIPA con Let's Encrypt utilizzando lo script bash

Se la tua preferenza è l'installazione automatizzata dei certificati Let's Encrypt, clona il codice dello script di gestione Let's Encrypt ufficiale di FreeIPA da github:

$ git clone https://github.com/freeipa/freeipa-letsencrypt.git
Cloning into 'freeipa-letsencrypt'...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 71 (delta 6), reused 13 (delta 4), pack-reused 48
Unpacking objects: 100% (71/71), 18.71 KiB | 299.00 KiB/s, done.

Passa alla directory creata:

cd freeipa-letsencrypt

Modifica lo script renew-le.sh e imposta la variabile EMAIL:

$ vim renew-le.sh
EMAIL="input-your-email-address"

All'interno dello script setup-le.sh l'FQDN del server FreeIPA è impostato sul nome host del server:

FQDN=$(hostname -f)

Assicurati che il comando seguente restituisca il nome host come FQDN:

$ hostname -f
idm.example.com

Esegui lo script setup-le.sh per preparare la macchina:

sudo bash setup-le.sh

Lo script eseguirà le seguenti azioni:

  • Installa i certificati Let's Encrypt CA nell'archivio certificati FreeIPA
  • Richiedi un nuovo certificato per l'interfaccia web di FreeIPA

Esempio di output dell'esecuzione del comando:

...
Installing CA certificate, please wait
Verified CN=R4,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful
--2023-07-29 14:46:06--  https://letsencrypt.org/certs/lets-encrypt-e2.pem
Resolving letsencrypt.org (letsencrypt.org)... 34.194.149.67, 68.183.23.220, 2a05:d014:275:cb01:8909:43f0:2069:7b77, ...
Connecting to letsencrypt.org (letsencrypt.org)|34.194.149.67|:443... connected.
GnuTLS: Resource temporarily unavailable, try again.
GnuTLS: Resource temporarily unavailable, try again.
GnuTLS: Resource temporarily unavailable, try again.
HTTP request sent, awaiting response... 200 OK
Length: 1021 [application/x-pem-file]
Saving to: ‘/etc/ssl/idm.example.com/lets-encrypt-e2.pem’

/etc/ssl/idm.example.com/lets- 100%[================================================================================>]    1021  --.-KB/s    in 0s

2023-07-29 14:46:06 (13.3 MB/s) - ‘/etc/ssl/idm.example.com/lets-encrypt-e2.pem’ saved [1021/1021]

Installing CA certificate, please wait
Verified CN=E2,O=Let's Encrypt,C=US
CA certificate successfully installed
The ipa-cacert-manage command was successful

Riavvia il servizio httpd:

sudo systemctl restart httpd

Conferma che l'esecuzione del comando ipa-certupdate ha avuto esito positivo:

$ sudo ipa-certupdate
Systemwide CA database updated.
Systemwide CA database updated.
The ipa-certupdate command was successful

Modifica del file di configurazione del server Web Apache per impostare il certificato e la chiave SSL (Non consigliato)

Se sei interessato solo a utilizzare Let's Encrypt SSL nelle pagine del browser, puoi modificare manualmente il file ssl.conf e impostare le seguenti direttive:

$ sudo vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/letsencrypt/live/idm.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/idm.example.com/privkey.pem

Riavvia il servizio httpd:

sudo systemctl restart httpd

Verifica che lo stato sia in esecuzione:

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/httpd.service.d
           └─ipa.conf
   Active: active (running) since Thu 2023-07-29 23:00:51 EAT; 17s ago
     Docs: man:httpd.service(8)
  Process: 39925 ExecStartPre=/usr/libexec/ipa/ipa-httpd-kdcproxy (code=exited, status=0/SUCCESS)
 Main PID: 39928 (httpd)
   Status: "Running, listening on: port 443, port 80"
    Tasks: 265 (limit: 101105)
   Memory: 332.4M
   CGroup: /system.slice/httpd.service
           ├─39928 /usr/sbin/httpd -DFOREGROUND
           ├─39929 /usr/sbin/httpd -DFOREGROUND
           ├─39930 (wsgi:kdcproxy) -DFOREGROUND
           ├─39931 (wsgi:kdcproxy) -DFOREGROUND
           ├─39932 (wsgi:ipa)      -DFOREGROUND
           ├─39933 (wsgi:ipa)      -DFOREGROUND
           ├─39934 (wsgi:ipa)      -DFOREGROUND
           ├─39935 (wsgi:ipa)      -DFOREGROUND
           ├─39936 /usr/sbin/httpd -DFOREGROUND
           ├─39937 /usr/sbin/httpd -DFOREGROUND
           └─39938 /usr/sbin/httpd -DFOREGROUND

Jul 29 23:00:51 idm.example.com systemd[1]: Starting The Apache HTTP Server...
Jul 29 23:00:51 idm.example.com ipa-httpd-kdcproxy[39925]: ipa: INFO: KDC proxy enabled
Jul 29 23:00:51 idm.example.com ipa-httpd-kdcproxy[39925]: ipa-httpd-kdcproxy: INFO     KDC proxy enabled
Jul 29 23:00:51 idm.example.com systemd[1]: Started The Apache HTTP Server.
Jul 29 23:00:52 idm.example.com httpd[39928]: Server configured, listening on: port 443, port 80

Rinnovo del certificato FreeIPA Let's Encrypt

Ogni volta che i certificati SSL vengono rinnovati, esegui i comandi seguenti per aggiornarli su FreeIPA end:s

DOMAIN="idm.example.com" # Set correct IdM hostname
sudo ipa-server-certinstall -w -d /etc/letsencrypt/live/$DOMAIN/privkey.pem /etc/letsencrypt/live/$DOMAIN/cert.pem --pin=''

Inserisci la password del Gestore Directory come richiesto:

Directory Manager password:
The ipa-server-certinstall command was successful

Quindi procedere al riavvio dei servizi FreeIPA dopo aver installato il certificato:

sudo ipactl restart

Dovresti quindi avere un utilizzo funzionante di Let's Encrypt SSL sulla configurazione del tuo server FreeIPA. Gli avvisi SSL sulla tua navigazione quando accedi alla dashboard web di FreeIPA dovrebbero scomparire. Ci piacerebbe creare più contenuti sull'amministrazione del server FreeIPA e sull'integrazione con servizi di terze parti. Rimani connesso per gli aggiornamenti!

Altre guide su FreeIPA:

  • Modifica la durata massima della scadenza della password dell'utente FreeIPA > 90 giorni
  • Esegui il server FreeIPA nei contenitori Docker/Podman
  • Gestisci utenti e gruppi in FreeIPA utilizzando la CLI
  • Come configurare l'autenticazione LDAP Jenkins FreeIPA
  • Configura l'autenticazione LDAP GitLab FreeIPA

Articoli correlati: