martes, mayo 03, 2011

Forzando phpmyadmin sobre SSL en Ubuntu Lucid (10.04)

Un día me quedé sin conexión a Internet así que decidí tomar prestada la de algún vecino.  Después de algunas horas de trabajo, me vino un extraño pensamiento ... '¿y si mi vecino captura todos los passwords que pasan por su red como lo hago yo?' He entrado a los phpmyadmins de tres servidores haciendo modificaciones, fácilmente pudo capturar tres credenciales de root.

Resulta que no está bien documentado en la red cómo asegurar phpmyadmin en un Ubuntu Lucid.

Tengo que crear las llaves de seguridad
# apt-get update
# apt-get upgrade
# apt-get install openssl
# mkdir /etc/ssl/localcerts
# openssl req -new -x509 -days 365 -nodes -out /etc/ssl/localcerts/apache.pem -keyout /etc/ssl/localcerts/apache.key
# chmod 600 /etc/ssl/localcerts/apache*

Habilitar el módulo SSL del Apache
# cd /etc/apache2/mods-enabled
# ln -s ../mods-available/ssl.* .

Habilitar el sitio por default SSL de Apache
# cd /etc/apache2/sites-enabled
# ln -s ../sites-available/default-ssl .

Modificar default-ssl
<IfModule mod_ssl.c>
- <VirtualHost _default_:443>
------
  <IfModule mod_ssl.c>
+ <VirtualHost *:443>

Modificar /etc/apache2/ports.conf
<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
+   NameVirtualHost *:443
    Listen 443
</IfModule>

Adaptar /etc/apache2/conf.d/phpmyadmin.conf, aquí yo envuelvo la configuración dentro de un VirtualHost con el nombre de mi servidor, en este ejemplo my.servername.com
+<VirtualHost *:443>
+       ServerName my.servername.com
+       ServerAdmin webmaster@servername.com
+
+ DocumentRoot /var/www
  Alias /phpmyadmin /usr/share/phpmyadmin
al inicio y
+   #   SSL Engine Switch:
+   #   Enable/Disable SSL for this virtual host.
+   SSLEngine on
+
+   #   A self-signed (snakeoil) certificate can be created by installing
+   #   the ssl-cert package. See
+   #   /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
+   #   If both key and certificate are stored in the same file, only the
+   #   SSLCertificateFile directive is needed.
+   SSLCertificateFile    /etc/ssl/localcerts/apache.pem
+   SSLCertificateKeyFile /etc/ssl/localcerts/apache.key
+</VirtualHost>
al final. Reiniciamos el servidor y probamos.

Parece mucho trabajo para algo que debería de ser aún más simple, sin embargo, los beneficios en seguridad valen la pena.

Mas info en: Creating a Self-Signed Certificate, phpmyadmin Documentation, Configure Apache to support multiple SSL sites on a single IP address

Actualizado 20 enero 2013 me faltó incluir una forma para obligar a phpmyadmin editando config.inc.php

// poner esto hasta abajo
$cfg['ForceSSL'] = true;

No hay comentarios.: