Outils pour utilisateurs

Outils du site


Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
320kerberos:50_apache [le 15/02/2010 à 09:21] prof320kerberos:50_apache [le 30/06/2018 à 15:58] (Version actuelle) prof
Ligne 1: Ligne 1:
 ====== Configuration d'apache-krb ====== ====== Configuration d'apache-krb ======
 Le serveur ''apache-krb.maison.mrs'' va fournir un service http nécessitant une authentification kerberos. Nous allons donc installer ce qui est nécessaire : Le serveur ''apache-krb.maison.mrs'' va fournir un service http nécessitant une authentification kerberos. Nous allons donc installer ce qui est nécessaire :
-  * un système de synchronisation de l'horloge (NTP). Nous ne verrons ici comment faire, ce n'est pas le sujet principal ;+  * un système de synchronisation de l'horloge (NTP) ;
   * un serveur apache classique ;   * un serveur apache classique ;
   * les composants kerberos nécessaires.   * les composants kerberos nécessaires.
 +
 ===== Installation d'apache ===== ===== Installation d'apache =====
 Nous installons un Apache « prefork » classique : Nous installons un Apache « prefork » classique :
Ligne 74: Ligne 75:
  
 Cette opération a permis la création d'une clé secrète qui doit être partagée avec le service http situé sur ''apache-krb.maison.mrs'' C'est grâce à cette clé que l'utilisateur pourra dialoguer en langage kerberos avec le service http. Souvenez-vous de ce que l'on a vu dans le [[:320kerberos:05_le_but]]. Cette opération a permis la création d'une clé secrète qui doit être partagée avec le service http situé sur ''apache-krb.maison.mrs'' C'est grâce à cette clé que l'utilisateur pourra dialoguer en langage kerberos avec le service http. Souvenez-vous de ce que l'on a vu dans le [[:320kerberos:05_le_but]].
 +
 +''kadmin'' va encore une fois nous servir :
 +<code>
 +kerberos:~# kadmin -p chris/admin
 +Authenticating as principal chris/admin with password.
 +Password for chris/admin@MAISON.MRS: 
 +kadmin:  ktadd -k krb5-http.keytab HTTP/apache-krb.maison.mrs
 +Entry for principal HTTP/apache-krb.maison.mrs with kvno 3, encryption type AES-256 CTS mode with 96-bit SHA-1 HMAC added to keytab WRFILE:krb5-http.keytab.
 +Entry for principal HTTP/apache-krb.maison.mrs with kvno 3, encryption type ArcFour with HMAC/md5 added to keytab WRFILE:krb5-http.keytab.
 +Entry for principal HTTP/apache-krb.maison.mrs with kvno 3, encryption type Triple DES cbc mode with HMAC/sha1 added to keytab WRFILE:krb5-http.keytab.
 +Entry for principal HTTP/apache-krb.maison.mrs with kvno 3, encryption type DES cbc mode with CRC-32 added to keytab WRFILE:krb5-http.keytab.
 +kadmin:  quit
 +</code>
 +
 +Nous avons créé dans le répertoire courant un fichier nommé ''krb5-http.keytab'' qui contient quatre entrées, fonction des divers algorithmes de chiffrement possibles. La commande ''klist'' permet de le vérifier :
 +
 +<code>
 +kerberos:~# klist -e -k krb5-http.keytab 
 +Keytab name: WRFILE:krb5-http.keytab
 +KVNO Principal
 +---- --------------------------------------------------------------------------
 +   3 HTTP/apache-krb.maison.mrs@MAISON.MRS (AES-256 CTS mode with 96-bit SHA-1 HMAC) 
 +   3 HTTP/apache-krb.maison.mrs@MAISON.MRS (ArcFour with HMAC/md5) 
 +   3 HTTP/apache-krb.maison.mrs@MAISON.MRS (Triple DES cbc mode with HMAC/sha1) 
 +   3 HTTP/apache-krb.maison.mrs@MAISON.MRS (DES cbc mode with CRC-32) 
 +</code>
 +Il nous faut déménager **par un moyen sécurisé** ce fichier sur ''apache-krb.maison.mrs'', par exemple avec ssh :
 +<code>
 +kerberos:~# scp krb5-http.keytab  root@apache-krb.maison.mrs:/etc/apache2/
 +...
 +root@apache-krb.maison.mrs's password: 
 +krb5-http.keytab                            100%  322     0.3KB/  00:00    
 +kerberos:~# rm krb5-http.keytab 
 +</code>
 +Nous aurions également pu utiliser la commande ''kadmin'' directement sur ''apache-krb.maison.mrs'' pour obtenir le keytab sur place.
  
 === sur apache-krb === === sur apache-krb ===
-Pas +Première chose à faire, rendre le « keytab » lisible par ''www-data''
 +<code> 
 +apache-krb:/etc/apache2# chown www-data:www-data krb5-http.keytab  
 +apache-krb:/etc/apache2# chmod 400 krb5-http.keytab  
 +apache-krb:/etc/apache2# ls -l krb5-http.keytab  
 +-r-------- 1 www-data www-data 322 févr. 15 10:55 krb5-http.keytab 
 +</code> 
 ===== Configuration d'apache ===== ===== Configuration d'apache =====
 +Nous allons maintenant modifier la configuration du serveur par défaut, pour nécessiter l'authentification kerberos :
 +<html><pre class="code">
 +apache-krb:/etc/apache2# cat sites-available/default
 +&lt;VirtualHost *:80>
 + ServerAdmin webmaster@localhost
 +
 + DocumentRoot /var/www
 + &lt;Directory />
 + Options FollowSymLinks
 + AllowOverride None
 + &lt;/Directory>
 + &lt;Directory /var/www/>
 +<span class="hly">                AuthName "Secure Access"
 +                AuthType Kerberos
 +                Krb5Keytab /etc/apache2/krb5-http.keytab
 +                KrbMethodK5Passwd off
 +                KrbSaveCredentials on
 +                require valid-user</span>
 +
 + AllowOverride None
 + Order allow,deny
 + allow from all
 + &lt;/Directory>
 +...
 +&lt;/VirtualHost>
 +</pre></html>
 +Pour les diverses options de configuration disponibles pour le module ''auth_kerb'', je vous invite à visiter la documentation (succincte) disponible sur [[http://modauthkerb.sourceforge.net/|le site du projet]] ou de lire le fichier (non moins succinct) ''/usr/share/doc/libapache2-mod-auth-kerb/README.gz''.
 +
 +L'option ''KrbMethodK5Passwd off'' fait que si l'utilisateur ne dispose pas déjà de son TGT, les portes du service lui sont irrémédiablement fermées.
 +===== Configuration du client =====
 +Il n'y a pas grand chose à faire si ce n'est de s'assurer que le navigateur web sait gérer la négociation kerberos. Au moins ''Firefox'' sait le faire, mais sa configuration par défaut ne le permet peut-être pas. Le mieux est de s'en assurer en allant sur l'URI ''about:config'' et en s'assurant que l'on a quelque chose de la forme :
 +  network.negotiate-auth.trusted-uris;https://,http://
 +Ici, toute demande d'URI faisant référence aux protocoles http et https sera autorisée à effectuer la négociation kerberos.
 +===== Vérifions =====
 +Un petit coup de ''wireshark'' ne sera pas du luxe.
 +==== Dans une console ====
 +Obtention du TGT :
 +  chris@pchris:~$ kinit chris
 +  Password for chris@MAISON.MRS: 
 +==== Dans Firefox ====
 +  http://apache-krb.maison.mrs
 +Ça marche, on le sait, on a déjà fait.
 +==== Re dans la console ====
 +<code>
 +chris@pchris:~$ klist
 +Ticket cache: FILE:/tmp/krb5cc_1000
 +Default principal: chris@MAISON.MRS
 +
 +Valid starting     Expires            Service principal
 +02/15/10 11:45:27  02/15/10 21:45:27  krbtgt/MAISON.MRS@MAISON.MRS
 + renew until 02/16/10 11:45:22
 +02/15/10 11:45:42  02/15/10 21:45:27  HTTP/apache-krb.maison.mrs@MAISON.MRS
 + renew until 02/16/10 11:45:22
 +</code>
 +Nous constatons que désormais nous avons bien, en plus du TGT, le ticket d'accès au service HTTP sur ''apache-krb.maison.mrs''.
 +==== Le snif ====
 +Nous avons pu capturer ce qu'il s'est passé et nous voyons ceci (débarrassé des paquets ARP, NTP et autres TCP inutiles à la compréhension) :
 +<code>
 +No.     Time        Source                Destination           Protocol Info
 +...
 +      3 0.000209    192.168.0.16          192.168.0.133         KRB5     AS-REQ
 +      4 0.000811    192.168.0.133         192.168.0.16          KRB5     KRB Error: KRB5KDC_ERR_PREAUTH_REQUIRED
 +...
 +      7 5.152873    192.168.0.16          192.168.0.133         KRB5     AS-REQ
 +      8 5.154053    192.168.0.133         192.168.0.16          KRB5     AS-REP
 +...
 +     16 19.545409   192.168.0.16          192.168.0.134         HTTP     GET / HTTP/1.1 
 +...
 +     18 19.547868   192.168.0.134         192.168.0.16          HTTP     HTTP/1.1 401 Authorization Required  (text/html)
 +...
 +     20 19.562570   192.168.0.16          192.168.0.133         KRB5     TGS-REQ
 +     21 19.564939   192.168.0.133         192.168.0.16          KRB5     TGS-REP
 +     22 19.566770   192.168.0.16          192.168.0.134         HTTP     GET / HTTP/1.1 
 +</code>
 +Les trames 3 à 8 correspondent à la demande et à l'obtention du TGT (commande ''kinit''), ce n'est pas nouveau.
 +
 +La trame 16 correspond à une demande HTTP ingénue de la part du client. La trame 18 correspond à l'erreur 401 ''Authorization Required''. Dans la réponse HTTP, il n'y a rien de plus que le HTML normalement destiné à afficher l'erreur, comme nous l'avons vu au début de ce chapitre :
 +<code>
 +Frame 18 (719 bytes on wire, 719 bytes captured)
 +...
 +Hypertext Transfer Protocol
 +    HTTP/1.1 401 Authorization Required\r\n
 +        [Expert Info (Chat/Sequence): HTTP/1.1 401 Authorization Required\r\n]
 +            [Message: HTTP/1.1 401 Authorization Required\r\n]
 +            [Severity level: Chat]
 +            [Group: Sequence]
 +        Request Version: HTTP/1.1
 +        Response Code: 401
 +    Date: Mon, 15 Feb 2010 10:45:42 GMT\r\n
 +    Server: Apache/2.2.14 (Debian)\r\n
 +    WWW-Authenticate: Negotiate\r\n
 +    Vary: Accept-Encoding\r\n
 +    Content-Encoding: gzip\r\n
 +    Content-Length: 346\r\n
 +        [Content length: 346]
 +    Keep-Alive: timeout=15, max=100\r\n
 +    Connection: Keep-Alive\r\n
 +    Content-Type: text/html; charset=iso-8859-1\r\n
 +    \r\n
 +    Content-encoded entity body (gzip): 346 bytes -> 488 bytes
 +Line-based text data: text/html
 +    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n
 +    <html><head>\n
 +    <title>401 Authorization Required</title>\n
 +    </head><body>\n
 +    <h1>Authorization Required</h1>\n
 +    <p>This server could not verify that you\n
 +    are authorized to access the document\n
 +    requested.  Either you supplied the wrong\n
 +    credentials (e.g., bad password), or your\n
 +    browser doesn't understand how to supply\n
 +    the credentials required.</p>\n
 +    <hr>\n
 +    <address>Apache/2.2.14 (Debian) Server at apache-krb.maison.mrs Port 80</address>\n
 +    </body></html>\n
 +</code>
 +Notre renard de feu, rusé par nature et qui plus est averti que dans ce cas là il doit aller regarder du côté de kerberos, va constater la présence du TGT de ''chris'' et lancer une demande de ticket (TGS-REQ) dans la trame 20 :
 +<html><pre class="code">
 +Frame 20 (761 bytes on wire, 761 bytes captured)
 +...
 +Kerberos TGS-REQ
 +    Pvno: 5
 +    MSG Type: TGS-REQ (12)
 +    padata: PA-TGS-REQ
 +        Type: PA-TGS-REQ (1)
 +            Value: 6E82022730820223A003020105A10302010EA20703050000... AP-REQ
 +                Pvno: 5
 +                MSG Type: AP-REQ (14)
 +                Padding: 0
 +                APOptions: 00000000
 +                    .0.. .... .... .... .... .... .... .... = Use Session Key: Do NOT use the session key to encrypt the ticket
 +                    ..0. .... .... .... .... .... .... .... = Mutual required: Mutual authentication is NOT required
 +                Ticket
 +                    Tkt-vno: 5
 +                    Realm: MAISON.MRS
 +                    Server Name (Unknown): krbtgt/MAISON.MRS
 +                        Name-type: Unknown (0)
 +                        Name: krbtgt
 +                        Name: MAISON.MRS
 +                    enc-part aes256-cts-hmac-sha1-96
 +                        Encryption type: aes256-cts-hmac-sha1-96 (18)
 +                        Kvno: 1
 +                        enc-part: 50AB88CDE4D868AACA1BDD95C155FCD1BB24764BF57551E1...
 +                Authenticator aes256-cts-hmac-sha1-96
 +                    Encryption type: aes256-cts-hmac-sha1-96 (18)
 +                    Authenticator data: 2C7936EF34EF6EB1AB7BE53F70E870987591510EB7B0FC90...
 +    KDC_REQ_BODY
 +        Padding: 0
 +        KDCOptions: 00810000 (Renewable, Canonicalize)
 +            .0.. .... .... .... .... .... .... .... = Forwardable: Do NOT use forwardable tickets
 +            ..0. .... .... .... .... .... .... .... = Forwarded: This is NOT a forwarded ticket
 +            ...0 .... .... .... .... .... .... .... = Proxiable: Do NOT use proxiable tickets
 +            .... 0... .... .... .... .... .... .... = Proxy: This ticket has NOT been proxied
 +            .... .0.. .... .... .... .... .... .... = Allow Postdate: We do NOT allow the ticket to be postdated
 +            .... ..0. .... .... .... .... .... .... = Postdated: This ticket is NOT postdated
 +            .... .... 1... .... .... .... .... .... = Renewable: This ticket is RENEWABLE
 +            .... .... ...0 .... .... .... .... .... = Opt HW Auth: False
 +            .... .... .... ..0. .... .... .... .... = Constrained Delegation: This is a normal request (no constrained delegation)
 +            .... .... .... ...1 .... .... .... .... = Canonicalize: This is a request for a CANONICALIZED ticket
 +            .... .... .... .... .... .... ..0. .... = Disable Transited Check: Transited checking is NOT disabled
 +            .... .... .... .... .... .... ...0 .... = Renewable OK: We do NOT accept renewed tickets
 +            .... .... .... .... .... .... .... 0... = Enc-Tkt-in-Skey: Do NOT encrypt the tkt inside the skey
 +            .... .... .... .... .... .... .... ..0. = Renew: This is NOT a request to renew a ticket
 +            .... .... .... .... .... .... .... ...0 = Validate: This is NOT a request to validate a postdated ticket
 +        Realm: MAISON.MRS
 +        Server Name (Service and Host): HTTP/apache-krb.maison.mrs
 +            Name-type: Service and Host (3)
 +            Name: HTTP
 +            Name: apache-krb.maison.mrs
 +        till: 2010-02-15 20:45:27 (UTC)
 +        Nonce: 1266230742
 +        Encryption Types: aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 des3-cbc-sha1 rc4-hmac des-cbc-crc des-cbc-md5 des-cbc-md4
 +            Encryption type: aes256-cts-hmac-sha1-96 (18)
 +            Encryption type: aes128-cts-hmac-sha1-96 (17)
 +            Encryption type: des3-cbc-sha1 (16)
 +            Encryption type: rc4-hmac (23)
 +            Encryption type: des-cbc-crc (1)
 +            Encryption type: des-cbc-md5 (3)
 +            Encryption type: des-cbc-md4 (2)
 +</pre></html>
 +Le serveur ''kerberos'' va répondre dans la trame 21 :
 +<html><pre class="code">
 +Frame 21 (744 bytes on wire, 744 bytes captured)
 +...
 +Kerberos TGS-REP
 +    Pvno: 5
 +    MSG Type: TGS-REP (13)
 +    Client Realm: MAISON.MRS
 +    Client Name (Principal): chris
 +        Name-type: Principal (1)
 +        Name: chris
 +    Ticket
 +        Tkt-vno: 5
 +        Realm: MAISON.MRS
 +        Server Name (Service and Host): HTTP/apache-krb.maison.mrs
 +            Name-type: Service and Host (3)
 +            Name: HTTP
 +            Name: apache-krb.maison.mrs
 +        enc-part aes256-cts-hmac-sha1-96
 +            Encryption type: aes256-cts-hmac-sha1-96 (18)
 +            Kvno: 3
 +            enc-part: 726E9E662C728E522451A0E630596656899C08CFF04F6F04...
 +    enc-part aes256-cts-hmac-sha1-96
 +        Encryption type: aes256-cts-hmac-sha1-96 (18)
 +        enc-part: 7FEDC49B008108F3E775207CB937C1DE83828023F9FCFE54...
 +</pre></html>
 +Et notre renard va re-formuler sa requête avec cette fois-ci ce qu'il faut dedans pour satisfaire l'indien dans la trame 22 :
 +<html><pre class="code">
 +Frame 22 (1504 bytes on wire, 1504 bytes captured)
 +...
 +Hypertext Transfer Protocol
 +    GET / HTTP/1.1\r\n
 +        [Expert Info (Chat/Sequence): GET / HTTP/1.1\r\n]
 +            [Message: GET / HTTP/1.1\r\n]
 +            [Severity level: Chat]
 +            [Group: Sequence]
 +        Request Method: GET
 +        Request URI: /
 +        Request Version: HTTP/1.1
 +    Host: apache-krb.maison.mrs\r\n
 +    User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7\r\n
 +    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
 +    Accept-Language: fr-fr,fr;q=0.8,en;q=0.5,en-us;q=0.3\r\n
 +    Accept-Encoding: gzip,deflate\r\n
 +    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n
 +    Keep-Alive: 300\r\n
 +    Connection: keep-alive\r\n
 +    If-Modified-Since: Mon, 15 Feb 2010 08:38:55 GMT\r\n
 +    If-None-Match: "45d72-b1-47f9f8c2b05c0"\r\n
 +    [truncated] Authorization: Negotiate YIICqAYGKwYBBQUCoIICnDCCApigHzAdBgkqhkiG9xIBAgIGBSsFAQUCBgkqhkiC9xIBAgKiggJzBIICb2CCAmsGCSqGSIb3EgECAgEAboICWjCCAlagAwIBBaEDAgEOogcDBQAAAAAAo4IBb2GCAWswggFnoAMCAQWhDBsKTUFJU09OLk1SU6IoMCagAwIBA6EfMB0bBE
 +        GSS-API Generic Security Service Application Program Interface
 +            OID: 1.3.6.1.5.5.2 (SPNEGO - Simple Protected Negotiation)
 +            SPNEGO
 +                negTokenInit
 +                    mechTypes: 3 items
 +                        MechType: 1.2.840.113554.1.2.2 (KRB5 - Kerberos 5)
 +                        MechType: 1.3.5.1.5.2 (SNMPv2-SMI::org.5.1.5.2)
 +                        MechType: 1.2.840.48018.1.2.2 (MS KRB5 - Microsoft Kerberos 5)
 +                    mechToken: 6082026B06092A864886F71201020201006E82025A308202...
 +                    krb5_blob: 6082026B06092A864886F71201020201006E82025A308202...
 +                        KRB5 OID: 1.2.840.113554.1.2.2 (KRB5 - Kerberos 5)
 +                        krb5_tok_id: KRB5_AP_REQ (0x0001)
 +                        Kerberos AP-REQ
 +                            Pvno: 5
 +                            MSG Type: AP-REQ (14)
 +                            Padding: 0
 +                            APOptions: 00000000
 +                                .0.. .... .... .... .... .... .... .... = Use Session Key: Do NOT use the session key to encrypt the ticket
 +                                ..0. .... .... .... .... .... .... .... = Mutual required: Mutual authentication is NOT required
 +                            Ticket
 +                                Tkt-vno: 5
 +                                Realm: MAISON.MRS
 +                                Server Name (Service and Host): HTTP/apache-krb.maison.mrs
 +                                    Name-type: Service and Host (3)
 +                                    Name: HTTP
 +                                    Name: apache-krb.maison.mrs
 +                                enc-part aes256-cts-hmac-sha1-96
 +                                    Encryption type: aes256-cts-hmac-sha1-96 (18)
 +                                    Kvno: 3
 +                                    enc-part: 726E9E662C728E522451A0E630596656899C08CFF04F6F04...
 +                            Authenticator aes256-cts-hmac-sha1-96
 +                                Encryption type: aes256-cts-hmac-sha1-96 (18)
 +                                Authenticator data: FAC8A2377494B396884927BE3726631FA66EFD41C98DC227...
 +    \r\n
 +</pre></html>
 +Voilà, c'est aussi compliqué que ça, mais ça fonctionne quand même.
  
Configuration d'apache-krb: Dernière modification le: 15/02/2010 à 09:21 par prof