Syncing Zentyal CA between two Zentyal servers

This document describes the procedure to set up CA sync between two Zentyal servers. We will use for this rsync being run in a cron job.
We will use root in the side that starts the connection (provided script will be run by cron) and ebox for the side that receives it. We could use any other user, but using user ebox avoid having to create extra unneeded configurations. For the sake of the example we’ll be referring to two servers here:

  1. (Server A) The server on which the CA existed previously, and from which the files for the CA will be taken.
  2. (Server B). The secondary server to which we want to export the CA which exists on Server A.

In order to better understand the procedure we must keep in mind that:
Zentyal CA files are stored on /var/lib/zentyal/CA
This folder has these permissions:

1drwx r-x --x 9 ebox ebox

ebox user has as his home the folder /var/lib/zentyal/

  • With this information, we’ll proceed to follow these steps:Check that rsync is installed in server B, and if not install it.
1sudo apt-get install rsync
  • Check if root has a rsa key in server B. If it did not have, create if with ssh-keygen
1if [ ! -f /root/.ssh/id_rsa.pub ] ; then /usr/bin/ssh-keygen" ; else echo "Key Already exists" ; fi

 

  • Create folder /var/lib/zentyal/.ssh/ and create file authorized_keys
1sudo mkdir -p /var/lib/zentyal/.ssh/
2sudo touch /var/lib/zentyal/.ssh/authorized_keys
  • Chown both to ebox.ebox:
1sudo chown -R ebox.ebox /var/lib/zentyal/.ssh/
  • Copy the root public key to /var/lib/zentyal/.ssh/authorized_keys of server A. Given ebox user has no password you will have to do it by hand, as long as you won’t be able to do it with ssh-copy-id . Thus, open /root/.ssh/id_rsa.pub and paste its contents into /var/lib/zentyal/.ssh/authorized_keys of server A.
  • Test that you can ssh without using password from root as ebox user:
1sudo ssh ebox@SERVER-A-IP
  • Now you can:

1. Limit connections from IP:

To do so edit in SERVER A /var/lib/zentyal/.ssh/authorized_keys, and add prior to the ssh-rsa this:

1from="SERVER-B-IP" ssh-rsa dasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5YvxjwERVVXs2mUEes5mDpoDMX9pUAwKqPCS5C
2LyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr2XkkFUYUOdUniYc99NsIxY1/51+/jjhfg
3jhfg/Pr5jqH+jhfjfgj/jhfgjh+9kErROS1z root@hostname

2.  Ensuring that only rsync is used for this ssh connection:
To do so edit in SERVER A /var/lib/zentyal/.ssh/authorized_keys, and add prior to the ssh-rsa this:

1command="/usr/share/bin/check_command.sh” ssh-rsa fdasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5YvxjwERV
2VXs2mUEes5mDpoDMX9pUAwKqPCS5CLyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr
32XkkFUYUOdUniYc99NsIxY1/51+/jjhfgjhfg/Pr5jqH+jhfjfgj/jhfgjh+9kErROS1z root@hostname

Now, you must add the script it mentions this line (script taken from http://troy.jdmz.net/rsync/index.html)

01#!/bin/sh
02 
03case "$SSH_ORIGINAL_COMMAND" in
04*\&*)
05echo "Rejected"
06;;
07*\(*)
08echo "Rejected"
09;;
10*\{*)
11echo "Rejected"
12;;
13*\;*)
14echo "Rejected"
15;;
16*\<*)
17echo "Rejected"
18;;
19*\`*)
20echo "Rejected"
21;;
22*\|*)
23echo "Rejected"
24;;
25rsync\ --server*)
26$SSH_ORIGINAL_COMMAND
27;;
28*)
29echo "Rejected"
30;;
31esac

If you use both, separate them with a “,”:

1from="SERVER-B-IP",command="/usr/share/bin/check_command.sh” ssh-rsa fdasghgdgh+RqUVx5wzgnaMxH2Km5KRx0Wzvsa5Y
2vxjwERVVXs2mUEes5mDpoDMX9pUAwKqPCS5CLyDwI+t0xNmVzPzeZjhypIfvBmgaG7pBNx7Zted7C+fha1X3SUmT4TguLzy7pfWbG7CKr2Xkk
3FUYUOdUniYc99NsIxY1/51+/jjhfgjhfg/Pr5jqH+jhfjfgj/jhfgjh+9kErROS1z root@hostname

 

  • Create the folder where you’re going to store the script that will do the sync and give it appropriate permissions:
1mkdir /var/local/rsync-ca
2chmod 754 /var/local/rsync-ca

 

  • Create the script file and give it proper permissions:
1chmod 740 /var/local/sync-ca/rsync-ca

 

  • Place the following content on the script (change variables as needed)
1#!/bin/bash
2RSYNC=/usr/bin/rsync
3SSH=/usr/bin/ssh
4KEY=/root/.ssh/id_rsa
5RUSER=ebox
6RHOST=SERVER-A-IP
7RPATH=/var/lib/zentyal/CA
8LPATH=/var/lib/zentyal/
9$RSYNC -az -e "$SSH -i $KEY" $RUSER@$RHOST:$RPATH $LPATH

 

  • Test the script and confirm that it works as expected

 

  • Create the cron job for the script we have just created. For instance, to run this daily write under /etc/cron.d/rsync-ca :
1# /etc/cron.d/rsync-ca - Runs the script that syncs CA with SERVERA daily
2 
3SHELL=/bin/sh
4PATH=/usr/bin:/bin
5 
6# Log data for report hourly
7@daily root /var/local/rsync-ca/rsync-ca

Deja un comentario