review HowtoSquid
This commit is contained in:
parent
11156e4bfc
commit
047402b92e
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
categories: web
|
||||
title: Howto Composer
|
||||
...
|
||||
|
||||
* Documentation : <https://getcomposer.org/doc/00-intro.md#locally>
|
||||
|
||||
# Installation
|
||||
|
||||
Composer ne disposant pas de paquet Debian pour la version stable (Jessie a l'heure actuelle), nous conseillions son installation en mode local (dans le $HOME de votre application) afin de le mettre a jour en meme temps que votre code.
|
||||
|
||||
~~~
|
||||
wget -4 https://getcomposer.org/installer
|
||||
sha384sum installer
|
||||
mkdir bin
|
||||
php installer --install-dir=bin --filename=composer
|
||||
php bin/composer --version
|
||||
~~~
|
|
@ -75,45 +75,6 @@ Il reste évidemment à rediriger les requêtes HTTP en sortie vers Squid avec I
|
|||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8888
|
||||
~~~
|
||||
|
||||
### Monitoring
|
||||
|
||||
Afin de détecter des oublis ou des éventuelles attaques, il sera intéressant d'ajouter la configuration suivante au logiciel _log2mail_ :
|
||||
|
||||
~~~
|
||||
file = /var/log/squid3/access.log
|
||||
pattern = "TCP_DENIED/403"
|
||||
mailto = ADRESSE-MAIL-ALERTE
|
||||
template = /etc/log2mail/template.squid
|
||||
~~~
|
||||
|
||||
template.squid
|
||||
|
||||
~~~
|
||||
From: %f
|
||||
To: %t
|
||||
Subject: Squid Alert - URL non autorisee
|
||||
|
||||
Dernieres URLs non autorisees
|
||||
|
||||
We have matched your pattern "%m" in "%F" %n times:
|
||||
|
||||
%l
|
||||
|
||||
Eventuellement autoriser l'access dans la whitelist ou verifier dangerosite de la requete.
|
||||
|
||||
Yours,
|
||||
log2mail.
|
||||
~~~
|
||||
|
||||
On n'oubliera pas d'ajouter l'utilisateur _log2mail_ dans le groupe _proxy_ pour qu'il puisse lire ce fichier (sinon _log2mail_ plante !!) :
|
||||
|
||||
~~~
|
||||
# adduser log2mail proxy
|
||||
Adding user `log2mail' to group `proxy' ...
|
||||
Adding user log2mail to group proxy
|
||||
Done.
|
||||
~~~
|
||||
|
||||
## Tips
|
||||
|
||||
### Squid est lent / indispo
|
||||
|
@ -144,4 +105,4 @@ En cas d'erreur 417 sur des Expect 100-continue, ajouter la directive :
|
|||
|
||||
~~~
|
||||
ignore_expect_100 on
|
||||
~~~
|
||||
~~~
|
||||
|
|
10
HowtoPHP.md
10
HowtoPHP.md
|
@ -13,7 +13,7 @@ PHP peut s'utiliser en CLI (ligne de commande), via mod_php (module intégré à
|
|||
## Installation
|
||||
|
||||
~~~
|
||||
# apt install php-cli php-curl php-mysql php-pgsql php-mcrypt php-ldap php-imap php-gd php-ssh2 php-gettext libphp-phpmailer composer
|
||||
# apt install php php-cli php-curl php-mysql php-pgsql php-mcrypt php-ldap php-imap php-gd php-ssh2 php-gettext composer libphp-phpmailer
|
||||
|
||||
$ php -v
|
||||
PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
|
||||
|
@ -28,7 +28,7 @@ Composer version 1.2.2 2016-11-03 17:43:15
|
|||
> *Note* : Pour Debian 8, on a PHP 5.6 qu'il faut installer ainsi (et il n'y a pas de package pour _composer_) :
|
||||
>
|
||||
> ~~~
|
||||
> # apt install php5-cli php5-curl php5-mysql php5-pgsql php5-mcrypt php5-ldap php5-imap php5-gd php5-ssh2 php-gettext libphp-phpmailer
|
||||
> # apt install php5 php5-cli php5-curl php5-mysql php5-pgsql php5-mcrypt php5-ldap php5-imap php5-gd php5-ssh2 php-gettext libphp-phpmailer
|
||||
> ~~~
|
||||
|
||||
|
||||
|
@ -179,7 +179,7 @@ D'autres options de FPM sont intéressantes :
|
|||
slowlog = log/$pool.log.slow
|
||||
request_slowlog_timeout = 5s
|
||||
|
||||
pm.status_path = /fpm-status
|
||||
pm.status_path = /fpm_status
|
||||
request_terminate_timeout = 60s
|
||||
chroot = /home/foo
|
||||
access.log = log/$pool.access.log
|
||||
|
@ -226,6 +226,8 @@ DocumentRoot /home/bench/www/
|
|||
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/home/foo/www/"
|
||||
~~~
|
||||
|
||||
#### Configuration mod_php
|
||||
|
||||
## Composer
|
||||
|
||||
* Documentation : <https://getcomposer.org/doc/>
|
||||
|
@ -276,3 +278,5 @@ $ php bin/composer --version
|
|||
PHP Warning: putenv() has been disabled for security reasons
|
||||
Composer version 1.5.1 2017-08-09 16:07:22
|
||||
~~~
|
||||
|
||||
|
||||
|
|
234
HowtoSquid.md
234
HowtoSquid.md
|
@ -1,25 +1,237 @@
|
|||
# Howto Squid
|
||||
---
|
||||
categories: web
|
||||
title: Howto Squid
|
||||
|
||||
Documentation officielle : <http://www.squid-cache.org/Versions/v3/3.4/cfgman/>
|
||||
* Documentation : <http://www.squid-cache.org/Versions/v3/3.5/cfgman/>
|
||||
* Rôle Ansible : <https://forge.evolix.org/projects/ansible-roles/repository/show/squid>
|
||||
|
||||
[Squid](http://www.squid-cache.org/) est serveur proxy HTTP/HTTPS.
|
||||
|
||||
# Installation
|
||||
## Installation
|
||||
|
||||
~~~
|
||||
# apt install squid3 squidclient
|
||||
# apt install squid squidclient
|
||||
|
||||
$ /usr/sbin/squid -v | head -3
|
||||
Squid Cache: Version 3.5.23
|
||||
Service Name: squid
|
||||
Debian linux
|
||||
|
||||
# systemctl status squid
|
||||
● squid.service - LSB: Squid HTTP Proxy version 3.x
|
||||
Loaded: loaded (/etc/init.d/squid; generated; vendor preset: enabled)
|
||||
Docs: man:systemd-sysv-generator(8)
|
||||
Main PID: 20892 (squid)
|
||||
CGroup: /system.slice/squid.service
|
||||
├─20890 /usr/sbin/squid -YC -f /etc/squid/squid.conf
|
||||
├─20892 (squid-1) -YC -f /etc/squid/squid.conf
|
||||
├─20893 (logfile-daemon) /var/log/squid/access.log
|
||||
└─20894 (pinger)
|
||||
~~~
|
||||
|
||||
# Configuration
|
||||
> *Note* : Pour Debian 8, il faut installer ainsi :
|
||||
>
|
||||
> ~~~
|
||||
> # apt install squid3 squidclient
|
||||
> ~~~
|
||||
|
||||
`/etc/squid3/squid.conf` :
|
||||
|
||||
## Configuration
|
||||
|
||||
La configuration par défaut est dans le fichier `/etc/squid/squid.conf`.
|
||||
|
||||
Nous utilisons une configuration alternative en spécifiant via `/etc/default/squid` :
|
||||
|
||||
~~~
|
||||
TODO
|
||||
CONFIG=/etc/squid/evolinux-defaults.conf
|
||||
SQUID_ARGS="-YC -f $CONFIG"
|
||||
~~~
|
||||
|
||||
`/etc/squid/evolinux-defaults.conf`:
|
||||
|
||||
~~~
|
||||
http_port 127.0.0.1:3128
|
||||
coredump_dir /var/spool/squid
|
||||
max_filedescriptors 4096
|
||||
|
||||
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
|
||||
acl Whitelist_domains dstdom_regex -i "/etc/squid/evolinux-whitelist-defaults.conf"
|
||||
acl Whitelist_domains dstdom_regex -i "/etc/squid/evolinux-whitelist-custom.conf"
|
||||
include /etc/squid/evolinux-acl.conf
|
||||
|
||||
http_access deny !Safe_ports
|
||||
http_access deny CONNECT !SSL_ports
|
||||
http_access allow localhost manager
|
||||
http_access deny manager
|
||||
include /etc/squid/evolinux-httpaccess.conf
|
||||
http_access allow localhost
|
||||
http_access deny all
|
||||
|
||||
refresh_pattern ^ftp: 1440 20% 10080
|
||||
refresh_pattern ^gopher: 1440 0% 1440
|
||||
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
|
||||
refresh_pattern . 0 20% 4320
|
||||
|
||||
logformat combined %>a %[ui %[un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
|
||||
access_log /var/log/squid/access.log combined
|
||||
|
||||
include /etc/squid/evolinux-custom.conf
|
||||
~~~
|
||||
|
||||
### Configuration en mode Proxy local
|
||||
|
||||
Pour sécuriser un serveur, on peut installer un proxy HTTP en local.
|
||||
Cela permet d'interdire ou de garder des traces des requêtes HTTP faites vers l'extérieur
|
||||
|
||||
`/etc/squid/evolinux-custom.conf` :
|
||||
|
||||
~~~
|
||||
http_port 8888 transparent
|
||||
cache deny all
|
||||
ignore_expect_100 on
|
||||
tcp_outgoing_address 192.0.2.42
|
||||
~~~
|
||||
|
||||
Le fichier `/etc/squid/evolinux-whitelist-defaults.conf` contiendra les noms de domaine autorisés en sortie :
|
||||
|
||||
~~~
|
||||
^mirror.evolix.org$
|
||||
^security.debian.org$
|
||||
^pub.evolix.net$
|
||||
~~~
|
||||
|
||||
> *Note* : la liste des noms de domaine autorisés en sortie peut-être trouvée sur https://forge.evolix.org/project/ansibles-roles/repository...
|
||||
|
||||
|
||||
Le fichier `/etc/squid/evolinux-acl.conf` contient les adresses IPv4 locales :
|
||||
|
||||
~~~
|
||||
acl LOCAL src 192.0.2.42/32
|
||||
~~~
|
||||
|
||||
`/etc/squid/evolinux-httpaccess.conf` :
|
||||
|
||||
~~~
|
||||
http_access deny !Whitelist_domains
|
||||
http_access allow LOCAL
|
||||
~~~
|
||||
|
||||
Il reste évidemment à rediriger les requêtes HTTP en sortie vers Squid avec IPTables :
|
||||
|
||||
~~~
|
||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner proxy -j ACCEPT
|
||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 192.0.2.42 -j ACCEPT
|
||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 127.0.0.1 -j ACCEPT
|
||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8888
|
||||
~~~
|
||||
|
||||
### Configuration en mode Proxy pour réseau local
|
||||
|
||||
`/etc/squid/evolinux-custom.conf` :
|
||||
|
||||
~~~
|
||||
http_port 3128 transparent
|
||||
error_directory /usr/share/squid3/errors/custom
|
||||
email_err_data on
|
||||
cache_mgr proxy@example.com
|
||||
negative_ttl 0
|
||||
cache deny badreq
|
||||
coredump_dir /var/spool/squid3
|
||||
cache_dir ufs /var/spool/squid3 800 16 256
|
||||
cache_mem 128 MB
|
||||
maximum_object_size_in_memory 512 KB
|
||||
maximum_object_size 64 MB
|
||||
~~~
|
||||
|
||||
Le fichier `/etc/squid/evolinux-whitelist-defaults.conf` contiendra les noms de domaine autorisés en sortie :
|
||||
|
||||
~~~
|
||||
^mirror.evolix.org$
|
||||
^security.debian.org$
|
||||
^pub.evolix.net$
|
||||
~~~
|
||||
|
||||
> *Note* : la liste des noms de domaine autorisés en sortie peut-être trouvée sur https://forge.evolix.org/project/ansibles-roles/repository...
|
||||
|
||||
|
||||
Le fichier `/etc/squid/evolinux-acl.conf` contient les adresses IPv4 locales :
|
||||
|
||||
~~~
|
||||
acl badreq http_status 400
|
||||
acl LOCAL src 192.0.2.42/32
|
||||
~~~
|
||||
|
||||
`/etc/squid/evolinux-httpaccess.conf` :
|
||||
|
||||
~~~
|
||||
http_access deny !Whitelist_domains
|
||||
http_access allow LOCAL
|
||||
~~~
|
||||
|
||||
|
||||
# FAQ
|
||||
## Administration
|
||||
|
||||
Vérification de la syntaxe de la configuration actuelle :
|
||||
|
||||
~~~
|
||||
# squid -k parse
|
||||
~~~
|
||||
|
||||
## Monitoring
|
||||
|
||||
### Log2mail
|
||||
|
||||
Afin de détecter des oublis ou des éventuelles attaques, il sera intéressant d'ajouter la configuration suivante au logiciel _log2mail_ :
|
||||
|
||||
~~~
|
||||
file = /var/log/squid3/access.log
|
||||
pattern = "TCP_DENIED/403"
|
||||
mailto = ADRESSE-MAIL-ALERTE
|
||||
template = /etc/log2mail/template.squid
|
||||
~~~
|
||||
|
||||
template.squid
|
||||
|
||||
~~~
|
||||
From: %f
|
||||
To: %t
|
||||
Subject: Squid Alert - URL non autorisee
|
||||
|
||||
Dernieres URLs non autorisees
|
||||
|
||||
We have matched your pattern "%m" in "%F" %n times:
|
||||
|
||||
%l
|
||||
|
||||
Eventuellement autoriser l'access dans la whitelist ou verifier dangerosite de la requete.
|
||||
|
||||
Yours,
|
||||
log2mail.
|
||||
~~~
|
||||
|
||||
On n'oubliera pas d'ajouter l'utilisateur _log2mail_ dans le groupe _proxy_ pour qu'il puisse lire ce fichier (sinon _log2mail_ plante !!) :
|
||||
|
||||
~~~
|
||||
# adduser log2mail proxy
|
||||
Adding user `log2mail' to group `proxy' ...
|
||||
Adding user log2mail to group proxy
|
||||
Done.
|
||||
~~~
|
||||
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
### Infos à propos de Squid
|
||||
|
||||
|
@ -36,14 +248,10 @@ En utilisation intensive, si vous obtenez un message '''WARNING! Your cache is r
|
|||
c'est qu'il est nécessaire d'augmenter le maximum de fichiers ouverts... mais ce problème est normalement résolu
|
||||
depuis Debian Lenny où l'on trouve un '''ulimit -n 65535''' dans le script d'init (c'était à ajouter en ''Etch'').
|
||||
|
||||
### Vérification de la configuration avant un start ou un reload :
|
||||
|
||||
~~~
|
||||
# squid3 -k parse
|
||||
~~~
|
||||
|
||||
### Résolution DNS
|
||||
|
||||
Squid "cache" les nameserver de /etc/resolv.conf car il gère son propre resolver : <http://wiki.squid-cache.org/Features/Dnsserver>
|
||||
Voir aussi <https://www.jethrocarr.com/2014/07/05/funny-tasting-squid-resolver/>
|
||||
En conséquence, si vous changez votre /etc/resolv.conf vous devez recharger Squid !
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ cache_mgr proxy@example.com
|
|||
|
||||
# Don't cache errors
|
||||
negative_ttl 0
|
||||
acl badreq <http_status> 400
|
||||
acl badreq http_status 400
|
||||
cache deny badreq
|
||||
|
||||
# Gestion du cache
|
||||
|
|
Loading…
Reference in a new issue