Blame SOURCES/README.wsrep_sst_rsync_tunnel

584bfd
socat tunnel for encrypted rsync SST
584bfd
====================================
584bfd
584bfd
`wsrep_sst_rsync_tunnel` is an extension of the rsync-based [SST](http://galeracluster.com/documentation-webpages/glossary.html#term-state-snapshot-transfer)
584bfd
implementation that ships with mariadb. Its purpose is to encrypt
584bfd
communication between the donor and the joiner during an SST.
584bfd
584bfd
Encryption is implemented by means of a socat tunnel, using OPENSSL
584bfd
addresses. It can be configured via the regular openssl flags exposed
584bfd
by socat.
584bfd
584bfd
584bfd
## How to configure the script
584bfd
584bfd
This SST script can configured by setting a few keys in your favorite
584bfd
mariadb option file in addition to the usual galera settings.
584bfd
584bfd
    [mysqld]
584bfd
    ...
584bfd
    bind_address=<node-name>
584bfd
    wsrep_sst_method=rsync_tunnel
584bfd
    ...
584bfd
    
584bfd
    [sst]
584bfd
    tca=/path/to/your/ca-file.crt
584bfd
    tcert=/path/to/node/certificate.crt
584bfd
    tkey=/path/to/node/key.key
584bfd
    sockopt=<openssl-address-options-as-per-socat-manual>
584bfd
584bfd
When a joiner node requests an SST, `wsrep_sst_rsync_tunnel` uses
584bfd
socat to listen to incoming SSL connections on port 4444 in lieu of
584bfd
the original rsync daemon. Received data will be forwarded to the
584bfd
rscynd daemon started locally to replicate the database.
584bfd
584bfd
When a donor node serves the SST, `wsrep_sst_rsync_tunnel` makes
584bfd
a series of rsync calls that target a locally started socat daemon.
584bfd
The daemon tunnels all rsync traffic into an encrypted SSL connection
584bfd
that targets the joiner's end of the socat tunnel.
584bfd
584bfd
Encryption parameters are specified under the `[sst]` group in the
584bfd
mariadb option file, where `tkey` and `tcert` are respectively the key
584bfd
and the certificate that are used by both sides of the socat tunnel.
584bfd
Each node typically has a different key and cert. Both key and
584bfd
certificate can be combined into a single PEM file and referenced by
584bfd
`tcert`. Option `tca` holds a list of the trusted signing
584bfd
certificates.
584bfd
584bfd
In case you need to tweak the creation of the SSL connection, you can
584bfd
pass valid socat options (as per socat manual) via the `sockopt` key.
584bfd
For debugging purpose, the exact socat command that is being executed
584bfd
shows up in the mariadb log file.
584bfd
584bfd
Note that socat verifies that the certificate's commonName matches
584bfd
that of the host that is being targeted. The target name comes from
584bfd
the value configured in `bind_address`, so it's important that it
584bfd
matches the certificate's commonName. An IP address can be used for
584bfd
`bind_address`, but you may get into trouble in case different
584bfd
hostnames resolve to the same IP (e.g. multiple networks per host).
584bfd
584bfd
584bfd
## Examples of use
584bfd
584bfd
Suppose you're running a 3-node galera cluster
584bfd
`node1.my.cluster`, `node2.my.cluster`, `node3.my.cluster`.
584bfd
584bfd
### Scenario: using self-signed certificates
584bfd
584bfd
On each node, create a key and a certificate, and bundle them into a
584bfd
single PEM file. For instance on `node1.my.cluster`:
584bfd
584bfd
    openssl genrsa -out /tls/mysql-$(hostname -f).key 2048
584bfd
    openssl req -new -key /tls/mysql-$(hostname -f).key -x509 -days 365000 -subj "/CN=$(hostname -f)" -out /tls/mysql-$(hostname -f).crt -batch
584bfd
    cat /tls/mysql-$(hostname -f).key /tls/mysql-$(hostname -f).crt > /tls/mysql.pem
584bfd
584bfd
Then, on each node, create a cafile that will contain all the certs to
584bfd
trust:
584bfd
584bfd
    for n in node1.my.cluster node2.my.cluster node3.my.cluster; do
584bfd
       ssh $n 'cat /tls/mysql-$(hostname -f).crt' >> /tls/all-mysql.crt
584bfd
    done
584bfd
584bfd
Once you have those two files on each host, you can configure the SST
584bfd
appropriately. For instance from `/etc/my.cnf.d/galera.cnf`:
584bfd
584bfd
    [mysqld]
584bfd
    ...
584bfd
    
584bfd
    [sst]
584bfd
    tca=/tls/all-mysql.crt
584bfd
    tcert=/tls/mysql.pem
584bfd
584bfd
### Scenario: using self-signed certificates, without verification
584bfd
584bfd
By default, when socat tries to establish a SSL connection to a peer,
584bfd
it also verifies that it can trust the peer's certificate. If for some
584bfd
reason you need to disable that feature, you can amend the previous
584bfd
configuration with a sockopt option:
584bfd
584bfd
    [mysqld]
584bfd
    ...
584bfd
    
584bfd
    [sst]
584bfd
    tca=/tls/all-mysql.crt
584bfd
    tcert=/tls/mysql.pem
584bfd
    sockopt="verify=0"
584bfd
584bfd
The associated sockopt value is passed to socat when
584bfd
the donor or the joiner configures his part of the tunnel.
584bfd
584bfd
Note: please do not do so in production, this is inherently insecure
584bfd
as you will not verify the identity of the peer you're connecting to!
584bfd
584bfd
### Scenario: using certificates from a CA
584bfd
584bfd
Suppose you have a FreeIPA service which generated a key file and a
584bfd
certificate file for the three galera nodes, respectively located at
584bfd
/tls/mysql.key and /tls/mysql.crt.
584bfd
584bfd
Assuming that the certificate for the FreeIPA server is available at
584bfd
/etc/ipa/ca.crt, you can configure you galera servers as follows:
584bfd
584bfd
    [sst]
584bfd
    tca=/etc/ipa/ca.crt
584bfd
    tcert=/tls/mysql.crt
584bfd
    tkey=/tls/mysql.key
584bfd
584bfd
## License
584bfd
584bfd
Copyright © 2017 [Damien Ciabrini](https://github.com/dciabrin).
584bfd
This work is derived from the original `wsrep_rsync_sst`, copyright
584bfd
© 2010-2014 [Codership Oy](https://github.com/codership).
584bfd
Released under the GNU GPLv2.