Difference between revisions of "Rsync based SysVol replication workaround"

m (Change link to script)
m (/* added note)
 
(23 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
= Introduction=
 
= Introduction=
  
Samba AD currently doesn't provide support for SysVol replication. To achive this important feature in a Multi-DC environment, until it's implemented, workarounds are necessary to keep it in sync. This HowTo provides a basic solution based on a script that uses rsync.
+
Samba AD currently doesn't provide support for SysVol replication. To achive this important feature in a Multi-DC environment, until it's implemented, workarounds are necessary to keep it in sync. This HowTo provides a basic workaround solution based on rsync.
  
'''Like on every change/enhancement, it's highly recommended to test the procedure in a save environment and have a [[Backup_and_Recovery|recoverable backup]]!'''
+
{{Imbox
 +
| type = note
 +
| text = It has been pointed out that using rsync without SSH is insecure and could lead to a 'M-I-M' attack, whilst this is probably unlikely for most users, it is suggested you consider one of the other methods to replicate Sysvol.
 +
}}
  
  
Line 9: Line 12:
  
  
= Requirements =
+
= Information on rsync-based replication =
  
 
[[Image:DC_PDC_emulator.png|thumb|Group Policy Management Console option for PDC]]
 
[[Image:DC_PDC_emulator.png|thumb|Group Policy Management Console option for PDC]]
  
This HowTo describes a way to setup rsync on your DC, that contains the FSMO role „PDC“. The script, that is used below to keep all other servers in sync, retrieves the content from the PDCs SysVol share via rsync.
+
This HowTo describes a solution for SysVol replication based on rsync. This tool is unidirectional, this means files can only be transferred in one direction. That's why for rsync-based SysVol replication, you have to choose one DC on which you do all modifications (GPO edits, logon script changes, etc.). All other DC's retrieve the changes from this host, this is because modifications on them are overwritten when syncing.
  
If you prefer to use rsync through a SSH tunnel, you can adapt the script to your needs. But typically there's no confidential content on the SysVol share. It should be alright for most if the transfer is unencrypted. The rsync module on the PDC is also defined as read only, because it is used only as source. So no content can be pushed to it.
+
A good choice for this "master" host is the one that contains the FSMO role "PDC Emulator", because you can configure the Group Policy Management Console to connect only to this machine (default), instead of just choosing any of your DC's. You can define at „Action“ / „Change Domain Controller“ which machine the GPMC connects to. There you should select „The domain controller with the Operations Master token for the PDC emulator“ (default).
  
Because the SysVol share on your PDC is the source where all other DCs are pulling their content from, it is required, that you only do changes (e. g. GPO, logonscripts, etc.) on this server. Changes made on the other DCs are overwritten on every sync script run.
+
Even if the unidirectional replication of rsync is a limitation, it has also many advantages:
 +
* already available on most distributions and can be installed through it's package manager (if it's not already installed anyway)
 +
* very quickly setup
 +
* very easily configured
 +
* etc.
  
E. g. the Group Policy Management Console can be configured, to use the PDC to connect to. If you choose „Action“ / „Change Domain Controller“, you should select „The domain controller with the Operations Master token for the PDC emulator“ (should be already default), to do changes automatically on your PDC.
+
If you prefer to use rsync through a SSH tunnel, you can adapt the command to your needs, but usually there's no confidential content on the SysVol share. It should be sufficient for most to use an unencrypted transfer. The rsync module on the PDC Emulator is also defined as read only, because it is used only as the source, so no content can be pushed to it.
  
  
Line 27: Line 34:
 
= Setup the SysVol replication =
 
= Setup the SysVol replication =
  
== Setup on the Domain Controller with the PDC role ==
+
== Setup on the Domain Controller with the PDC Emulator FSMO role ==
  
* Install rsync by using your paket manager or compile from source. Make sure, that you use a version that supports extended ACLs!
+
* Install rsync by using your package manager or by compiling from source. Make sure that you use a version that supports extended ACL's!
  
 
* If you start your rsync-server through xinetd, you can use the following configuration file (<tt>/etc/xinetd.d/rsync</tt>):
 
* If you start your rsync-server through xinetd, you can use the following configuration file (<tt>/etc/xinetd.d/rsync</tt>):
Line 45: Line 52:
 
  }
 
  }
  
* Create the file <tt>/etc/rsyncd.conf</tt> (adapt the path variable to your PDCs SysVol path):
+
* Create the file <tt>/etc/rsyncd.conf</tt> (adapt the path variable to your PDC Emulators SysVol path):
  
 
  [SysVol]
 
  [SysVol]
Line 64: Line 71:
  
  
 +
== Setup on all other Domain Controller(s) ==
  
 +
* Make sure, that you have [[Joining_a_Samba_DC_to_an_Existing_Active_Directory#Built-in_User_.26_Group_ID_Mappings|identical IDs of built-in groups on all DCs]].
  
== Setup on all other Domain Controller(s) ==
+
* Install rsync by using your package manager or compile from source. Make sure, that you use a version that supports extended ACLs!
  
'''It's suggested to test the script on a save place, to avoid any problems in production! The script comes without any warranty!'''
+
* Create a password file <tt>/usr/local/samba/etc/rsync-sysvol.secret</tt> and fill it with the password you set on the PDC Emulator for the <tt>sysvol-replication</tt> rsync account (permissions of that file must not be world-readable!):
  
* Install rsync by using your paket manager or compile from source. Make sure, that you use a version that supports extended ACLs!
+
pa$$w0rd
  
* Create a file <tt>/usr/local/samba/etc/rsync-sysvol.secret</tt> and fill it with the password, set on the PDC for the <tt>sysvol-replication</tt> rsync account (permissions of that file must not be world-readable!):
+
* For replicating the SysVol folder, run the following command (<tt>--dry-run</tt> means that no modifications are actually made):
  
  pa$$w0rd
+
  # rsync --dry-run -XAavz --delete-after --password-file=/usr/local/samba/etc/rsync-sysvol.secret rsync://sysvol-replication@{IP-of-your-PDC-Emulator}/SysVol/ /path/to/your/sysvol/folder/
 +
 +
receiving file list ... done                                                                                                                                                                                 
 +
created directory /usr/local/samba/var/locks/sysvol                                                                                                                                                           
 +
./                                                                                                                                                                                                           
 +
samdom.example.com/                                                                                                                                                                                           
 +
samdom.example.com/Policies/                                                                                                                                                                                 
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/                                                                                                                                           
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/GPT.INI                                                                                                                                   
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/MACHINE/                                                                                                                                   
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/MACHINE/Registry.pol                                                                                                                       
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/                                                                                                                                     
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Documents & Settings/                                                                                                                 
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/                                                                                                                             
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/Logoff/
 +
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/Logon/
 +
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/
 +
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/GPT.INI
 +
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/MACHINE/
 +
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/USER/
 +
samdom.example.com/scripts/
 +
samdom.example.com/scripts/logonscript.bat
 +
 +
sent 124 bytes  received 1064 bytes  2376.00 bytes/sec
 +
total size is 1207  speedup is 1.02 (DRY RUN)
 +
 
 +
:'''Warning: Make sure that the destination folder is really your SysVol folder, because the command will replicate to the given directory and removes everything in it that isn't also on the source! You could damage your system! So check the output carefully to see if the replication is doing what you expect!'''
  
* Go to [http://marc-muehlfeld.de/samba/sysvol-replication/ http://marc-muehlfeld.de/samba/sysvol-replication/], download the latest version of the <tt>rsync-sysvol-replication.sh</tt> script and make it executable.
+
* If everything looks sane, run the command without the <tt>--dry-run</tt> option and let rsync do the replication.
  
* If you use a different rsync username than mentioned above and/or a different path to the <tt>rsync-sysvol.secret</tt> file, change it in the configuration area in the head of the script.
+
* To automate synchronisation, you can run the command via cron (e. g. every 5 minutes).
  
* First run the script in dry-run mode:
+
*/5 * * * *          rsync -XAavz --delete-after --password-file=/usr/local/samba/etc/rsync-sysvol.secret rsync://sysvol-replication@{IP-of-your-PDC-Emulator}/SysVol/ /path/to/your/sysvol/folder/
  
# /path/to/rsync-sysvol-replication.sh -d
+
* Repeat these steps on every DC (except your PDC Emulator!).
  
* The script auto-discovers the path to the local SysVol share through <tt>testparm</tt>. As the share is automatically setup in your <tt>smb.conf</tt> when [[Samba4/HOWTO/Join_a_domain_as_a_DC|joining as DC]], this should work without any problems.
+
= FAQ =
  
* The PDC IP is auto-discovered through DNS (<tt>_ldap._tcp.pdc._msdcs.your.domain.</tt>). If you encounter any problems, you can define the PDC host by <tt>-p [IP]</tt>.
+
* How can I get multi-direction replication ?
 +
** There is some testing using unison with rsync to achieve this.
 +
** Have a look here :
 +
** https://wiki.samba.org/index.php/Bidirectional_Rsync/Unison_based_SysVol_replication_workaround
  
* If everything looks fine on the dry-run, you can start the real replication process:
+
* Why can't I simply use a distributed filesystem like GlusterFS, Lustre, etc. for SysVol?
 +
** A cluster file system with Samba requires CTDB to be able to do it safely. And CTDB and AD DC are incompatible.
  
# /path/to/rsync-sysvol-replication.sh
 
2013-07-23 21:05:24 **********************************************************************
 
2013-07-23 21:05:24 Auto-discovered PDC: 10.99.0.1
 
2013-07-23 21:05:24 Replicating from 10.99.0.1:
 
2013-07-23 21:05:25      receiving file list ... done
 
2013-07-23 21:05:25      ./
 
2013-07-23 21:05:25      samdom.example.com/
 
2013-07-23 21:05:25      samdom.example.com/Policies/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/GPT.INI
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/MACHINE/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/MACHINE/Registry.pol
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/USER/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/USER/Documents & Settings/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/USER/Scripts/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/USER/Scripts/Logoff/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{31B2F340-016D-11D2-945F- 00C04FB984F9}/USER/Scripts/Logon/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{6AC1786C-016F-11D2-945F- 00C04FB984F9}/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{6AC1786C-016F-11D2-945F- 00C04FB984F9}/GPT.INI
 
2013-07-23 21:05:25      samdom.example.com/Policies/{6AC1786C-016F-11D2-945F- 00C04FB984F9}/MACHINE/
 
2013-07-23 21:05:25      samdom.example.com/Policies/{6AC1786C-016F-11D2-945F- 00C04FB984F9}/USER/
 
2013-07-23 21:05:25      samdom.example.com/scripts/
 
2013-07-23 21:05:25      samdom.example.com/scripts/logonscript.bat
 
2013-07-23 21:05:25     
 
2013-07-23 21:05:25      sent 191 bytes  received 1908 bytes  1399.33 bytes/sec
 
2013-07-23 21:05:25      total size is 1207  speedup is 0.58
 
  
* Run the script with the <tt>-h</tt> option for further information and parameters.
 
  
* To automatically syncronize the SysVol share every 5 minutes incl. logfile creation, setup a Cron job:
 
  
*/5 * * * *    /path/to/rsync-sysvol-replication.sh -l /var/log/sysvol-replication.log > /dev/null
 
  
* Repeat this steps on every DC (except your PDC!).
+
----
 +
[[Category:Active Directory]]

Latest revision as of 18:18, 18 July 2019

Introduction

Samba AD currently doesn't provide support for SysVol replication. To achive this important feature in a Multi-DC environment, until it's implemented, workarounds are necessary to keep it in sync. This HowTo provides a basic workaround solution based on rsync.



Information on rsync-based replication

Group Policy Management Console option for PDC

This HowTo describes a solution for SysVol replication based on rsync. This tool is unidirectional, this means files can only be transferred in one direction. That's why for rsync-based SysVol replication, you have to choose one DC on which you do all modifications (GPO edits, logon script changes, etc.). All other DC's retrieve the changes from this host, this is because modifications on them are overwritten when syncing.

A good choice for this "master" host is the one that contains the FSMO role "PDC Emulator", because you can configure the Group Policy Management Console to connect only to this machine (default), instead of just choosing any of your DC's. You can define at „Action“ / „Change Domain Controller“ which machine the GPMC connects to. There you should select „The domain controller with the Operations Master token for the PDC emulator“ (default).

Even if the unidirectional replication of rsync is a limitation, it has also many advantages:

  • already available on most distributions and can be installed through it's package manager (if it's not already installed anyway)
  • very quickly setup
  • very easily configured
  • etc.

If you prefer to use rsync through a SSH tunnel, you can adapt the command to your needs, but usually there's no confidential content on the SysVol share. It should be sufficient for most to use an unencrypted transfer. The rsync module on the PDC Emulator is also defined as read only, because it is used only as the source, so no content can be pushed to it.



Setup the SysVol replication

Setup on the Domain Controller with the PDC Emulator FSMO role

  • Install rsync by using your package manager or by compiling from source. Make sure that you use a version that supports extended ACL's!
  • If you start your rsync-server through xinetd, you can use the following configuration file (/etc/xinetd.d/rsync):
service rsync
{
   disable         = no
   only_from       = 10.99.0.0/28     # Restrict to your DC address(es) or ranges, to prevent other hosts retrieving the content, too.
   socket_type     = stream
   wait            = no
   user            = root
   server          = /usr/bin/rsync
   server_args     = --daemon
   log_on_failure += USERID
}
  • Create the file /etc/rsyncd.conf (adapt the path variable to your PDC Emulators SysVol path):
[SysVol]
path = /usr/local/samba/var/locks/sysvol/
comment = Samba Sysvol Share
uid = root
gid = root
read only = yes
auth users = sysvol-replication
secrets file = /usr/local/samba/etc/rsyncd.secret
  • Create a file /usr/local/samba/etc/rsyncd.secret (permissions must not be world-readable!) with the following content (adapt the password!):
sysvol-replication:pa$$w0rd
  • Restart xinetd.


Setup on all other Domain Controller(s)

  • Install rsync by using your package manager or compile from source. Make sure, that you use a version that supports extended ACLs!
  • Create a password file /usr/local/samba/etc/rsync-sysvol.secret and fill it with the password you set on the PDC Emulator for the sysvol-replication rsync account (permissions of that file must not be world-readable!):
pa$$w0rd
  • For replicating the SysVol folder, run the following command (--dry-run means that no modifications are actually made):
# rsync --dry-run -XAavz --delete-after --password-file=/usr/local/samba/etc/rsync-sysvol.secret rsync://sysvol-replication@{IP-of-your-PDC-Emulator}/SysVol/ /path/to/your/sysvol/folder/

receiving file list ... done                                                                                                                                                                                   
created directory /usr/local/samba/var/locks/sysvol                                                                                                                                                            
./                                                                                                                                                                                                             
samdom.example.com/                                                                                                                                                                                            
samdom.example.com/Policies/                                                                                                                                                                                   
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/                                                                                                                                            
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/GPT.INI                                                                                                                                     
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/MACHINE/                                                                                                                                    
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/MACHINE/Registry.pol                                                                                                                        
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/                                                                                                                                       
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Documents & Settings/                                                                                                                  
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/                                                                                                                               
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/Logoff/
samdom.example.com/Policies/{31B2F340-016D-11D2-945F-00C04FB984F9}/USER/Scripts/Logon/
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/GPT.INI
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/MACHINE/
samdom.example.com/Policies/{6AC1786C-016F-11D2-945F-00C04FB984F9}/USER/
samdom.example.com/scripts/
samdom.example.com/scripts/logonscript.bat

sent 124 bytes  received 1064 bytes  2376.00 bytes/sec
total size is 1207  speedup is 1.02 (DRY RUN)
Warning: Make sure that the destination folder is really your SysVol folder, because the command will replicate to the given directory and removes everything in it that isn't also on the source! You could damage your system! So check the output carefully to see if the replication is doing what you expect!
  • If everything looks sane, run the command without the --dry-run option and let rsync do the replication.
  • To automate synchronisation, you can run the command via cron (e. g. every 5 minutes).
*/5 * * * *          rsync -XAavz --delete-after --password-file=/usr/local/samba/etc/rsync-sysvol.secret rsync://sysvol-replication@{IP-of-your-PDC-Emulator}/SysVol/ /path/to/your/sysvol/folder/
  • Repeat these steps on every DC (except your PDC Emulator!).

FAQ

  • Why can't I simply use a distributed filesystem like GlusterFS, Lustre, etc. for SysVol?
    • A cluster file system with Samba requires CTDB to be able to do it safely. And CTDB and AD DC are incompatible.