mercredi 10 février 2010
Xen - Migration du Squid sous Debian Lenny 5.0.3 (Authentification: Squid +OpenLdap)
Par david techer, mercredi 10 février 2010 à 20:08 :: Xen

Objectifs
Le but ici est de déplacer le service squid présent sur monroe (voir schémas ci-dessous) sur une nouvelle machine xenifiée. Mon Squis actuel est sous Ubuntu 8.0.4. J'ai décidé de basculer mon squid sur une Lenny.Les étapes sont donc successivement
- Création du domaine invité
- Installation du squid3;
- Modification de la règles de firewall pour le réseau 192.168.1.0/24
Rappel de l'ancienne configuration
Voici la configuration actuelle. Actuellement pour le réseau 192.168.1.0, les requêtes http sont dirigés vers monroe. La machine étant déjà  assez chargée, on va donc migrer le squid ailleurs sur une machine Xen hébergé surmelina
.
Concernant la base MySQL sur melina-xen01, le travail a déjà  fait (consulter ce billet).

Future configuration (si possible)
On va essayer de migrer vers ça surmelina-xen02
.

1. Le domaine invité qui accueillera Squid
1.1 Création du domaine invité
Depuis melina, on crée donc la nouvelle machine
melina:~# xen-create-image --hostname=melina-xen02 --ip=192.168.2.250 --role=udev
General Information
--------------------
Hostname : melina-xen02
Distribution : lenny
Partitions : swap 128Mb (swap)
/ 20Gb (ext3)
Image type : full
Memory size : 512Mb
Kernel path : /boot/vmlinuz-2.6.26-2-xen-686
Initrd path : /boot/initrd.img-2.6.26-2-xen-686
Networking Information
----------------------
IP Address 1 : 192.168.2.250 [MAC: 00:16:3E:12:D3:BD]
Netmask : 255.255.255.0
Broadcast : 192.168.2.255
Gateway : 192.168.2.253
Creating swap on /dev/xen-vm/melina-xen02-swap
Done
Creating ext3 filesystem on /dev/xen-vm/melina-xen02-disk
Done
Installation method: debootstrap
Done
Running hooks
Done
Role: udev
File: /etc/xen-tools/role.d/udev
Role script completed.
Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done
Logfile produced at:
/var/log/xen-tools/melina-xen02.log
1.2 Démarrage du domaine invité
On démarre et on se connecte ensuite au domainemelina:~# xm create -c /etc/xen/machines/melina-xen02.cfg -cIl est dès lors possible de se connecter en SSH
2. SQUID
2.1 Installation de Squid
Rien de plus simple queapt-get update apt-get install squid3Avant de passer à  la configuration de Squid avec OpenLDAP, pour la suite il faut effectuer quelques tests avec l'utilitaire
squid_ldap_auth
, afin de s'assurer d'avoir fournis les bons paramètres à  l'utilitaire. Cette commande figurera par la suite dans la configuration de squid
Donc pour la suite, une petite lecture s'impose
man squid_ldap_authOn lit un peu tout ça et on y go pour la suite.
2.2 Test de squid_ldap_auth
Un test pour interroger l'annuaire grà ¢ce à  la commande
/usr/lib/squid3/squid_ldap_auth -b dc=chezdavid,dc=local -f "uid=%s" -h 192.168.2.1 -p 389 [LOGIN] [PASSWORD]Il faut donc saisir la commande "/usr/lib/squid3/squid_ldap_auth -b dc=chezdavid,dc=local -f "uid=%s" -h 192.168.2.1 -p 389" puis sur la nouvelle ligne son login et son mot de passe, tous deux espacé d'un blanc. La commande renverra donc "OK" en cas de succès.
J'ai respectivement reproduit un mauvais (respectivement bon) test sur la figure ci-dessous

Test pour squid_ldap_auth
2.3 Authentification pour Squid + OpenLDAP
Je n'ai pas trop trifouillé la configuration. J'ai juste mis ce dont j'ai besoinmelina-xen02:~# grep -vE '^(#|$)' /etc/squid3/squid.conf acl manager proto cache_object acl localhost src 127.0.0.1/32 acl to_localhost dst 127.0.0.0/8 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT http_access allow manager localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost auth_param basic program /usr/lib/squid3/squid_ldap_auth -b dc=chezdavid,dc=local -f "uid=%s" -h 192.168.2.1 -p 389 auth_param basic children 5 auth_param basic realm Web-Proxy sur DavidGIS auth_param basic credentialsttl 2 hours acl ldapauth proxy_auth REQUIRED acl authenticated proxy_auth REQUIRED http_access allow authenticated http_access allow ldapauth http_access deny all icp_access deny all htcp_access deny all http_port 3128 hierarchy_stoplist cgi-bin ? access_log /var/log/squid3/access.log squid refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern (cgi-bin|\?) 0 0% 0 refresh_pattern . 0 20% 4320 icp_port 3130 coredump_dir /var/spool/squid3
3. Règles pour le firewall
iptables -t nat -A PREROUTING -i eth0 -s 192.168.1.2/24 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.250:3128 iptables -A FORWARD -p tcp -i eth0 --dport 3128 -j ACCEPT