MySQL : Différence entre versions

De Wiki NCad
Aller à : navigation, rechercher
(Validation)
(Validation)
Ligne 95 : Ligne 95 :
 
=== Validation ===
 
=== Validation ===
  
{{ Box Console | objet=mysql> show variables like "%ssl%";<br />
+
{{ Box Console | objet=mysql> show variables like "%ssl%";<br /><code>
+---------------+--------------------------+<br />
+
+---------------+--------------------------+<br />
| Variable_name | Value                    |<br />
+
| Variable_name | Value                    |<br />
+---------------+--------------------------+<br />
+
+---------------+--------------------------+<br />
| have_openssl  | YES                      |<br />
+
| have_openssl  | YES                      |<br />
| have_ssl      | YES                      |<br />
+
| have_ssl      | YES                      |<br />
| ssl_ca        | /etc/mysq/ssl/ca.crt    |<br />
+
| ssl_ca        | /etc/mysq/ssl/ca.crt    |<br />
| ssl_capath    |                          |<br />
+
| ssl_capath    |                          |<br />
| ssl_cert      | /etc/mysql/ssl/mysql.crt |<br />
+
| ssl_cert      | /etc/mysql/ssl/mysql.crt |<br />
| ssl_cipher    |                          |<br />
+
| ssl_cipher    |                          |<br />
| ssl_key      | /etc/mysql/ssl/mysql.key |<br />
+
| ssl_key      | /etc/mysql/ssl/mysql.key |<br />
+---------------+--------------------------+<br />
+
+---------------+--------------------------+<br />
7 rows in set (0.02 sec) }}
+
7 rows in set (0.02 sec)</code> }}
  
 
<br />
 
<br />
  
 
mysql> show status like 'Ssl_cipher';
 
mysql> show status like 'Ssl_cipher';

Version du 5 février 2014 à 03:45

SSL

Autorité de certification

Création de la clé privée

  • On se place dans le dossier /etc/ssl/private qui contient les clés et certificats privées :
ICON Terminal.png

cd /etc/ssl/private

  • On génère la clé privée :
ICON Terminal.png

sudo openssl genrsa -out ca.key 2048

Cette clé va nous permettre de signer nos propres certificats.

Création du certificat auto-signé

  • On lance la création de certificat auto-signé :
ICON Terminal.png

openssl req -new -x509 -nodes -days 365 -key ca.key -out ca.crt
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
- - - --
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:Paris
Locality Name (eg, city) []:Paris
Organization Name (eg, company) [Internet Widgits Pty Ltd]:NCad Network
Organizational Unit Name (eg, section) []:Autorité de certification
Common Name (e.g. server FQDN or YOUR name) []:10.0.0.47
Email Address []:tech@ncad.fr

Certificat serveur

  • On génère la clé privée :
ICON Terminal.png

sudo openssl genrsa -out mysql.key 2048

  • On génère le certificat :
ICON Terminal.png

sudo openssl req -new -key mysql.key -out mysql.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
- - - - -
Country Name (2 letter code) [AU]:FR
State or Province Name (full name) [Some-State]:Paris
Locality Name (eg, city) []:Paris
Organization Name (eg, company) [Internet Widgits Pty Ltd]:NCad Network
Organizational Unit Name (eg, section) []:Intranet Goulouxiou
Common Name (e.g. server FQDN or YOUR name) []:10.0.0.47
Email Address []:tech@ncad.fr

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:Le soleil est noir.
An optional company name []:NCad Network

  • On signe notre certificat à l'aide du certificat auto-signé de notre autorité de certification (précédemment créée) :
ICON Terminal.png

openssl x509 -req -in mysql.csr -days 365 -CA ca.crt -CAkey ca.key -set_serial 01 -out mysql.crt
Signature ok
subject=/C=FR/ST=Paris/L=Paris/O=NCad Network/OU=Intranet
Goulouxiou/CN=10.0.0.47/emailAddress=tech@ncad.fr
Getting CA Private Key

COnfiguration du serveur MySQL

  • On déplace les certificats crées dans /etc/ssl/private vers /etc/mysql/ssl
ICON Terminal.png

sudo mkdir -p /etc/mysql/ssl
cp /etc/ssl/private/ca.* /etc/mysql/ssl
cp /etc/ssl/private/mysql.* /etc/mysql/ssl

  • On applique les permissions et droits mysql sur les certificats :
ICON Terminal.png

sudo chown mysql:mysql /etc/mysql/ssl -R

  • On édite le fichier /etc/apparmor.d/usr.sbin.mysqld et on y insère les éléments suivants :


  • On édite le fichier de configuration /etc/mysql/my.cf et on y insère dans la section [] :


  • Dans le même fichier, on insère les éléments suivants dans la section [] :

Validation

ICON Terminal.png

mysql> show variables like "%ssl%";
<code>

+---------------+--------------------------+


mysql> show status like 'Ssl_cipher';