saltstack / saltstack/salt

[BUG] rsync.synchronized treats remote targets as local paths when looking for or creating the target directory.

Open
#61,849 2 comments 0 reactions 1 assignee View on GitHub

@MKLeb is already working on this.

Since May 23, 2023.

bug
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

rsync.synchronized treats remote targets as local paths when looking for or creating the target directory.

The motivating example was an attempt to rsync mine data between a master and its syndics, with sudo on the far end. I suspect the issue exists for any use of rsync.synchronized against a remote target, but I'm not sure. Here is an example state:

rsync-something-somewhere:
  rsync.synchronized:
    - name: user@host:/var/cache/salt/master/minions
    - source: /var/cache/salt/master/minions/
    - update: true
    - additional_opts:
      - --rsync-path=sudo rsync
    # the result differs depending on whether `prepare` is given, but is
    # wrong in both cases.
    - prepare: true

If prepare is false (the default), the above state complains that the target doesn't exist, even if it does: Destination directory user@host:/var/cache/salt/master/minions was not found.

If prepare is true, it creates a directory tree on the local machine at /user@host:/var/cache/salt/master -- i.e. it creates a top-level directory named user@host:. It then proceeds to rsync the right files to the right place.

I conclude that it is treating the state name as a local path in both cases -- but only with respect to the target directory check and creation. The actual transfer still happens if prepare is given, leaving the mis-aimed directories behind.

Note that the reverse case (where name is local and source is remote) appears to work fine.

Workaround

Setting force: true instead of prepare: true seems to skip the target check, but it's not ideal because it also runs rsync with --force, which may not be desired.

Versions Report

Note: while our saltstack is a bit out of date, I diffed the rsync modules for 3002.2 against the most recent tag and didn't see anything that looked relevant.

Salt Version:                                                 
          Salt: 3002.2                                        

Dependency Versions:                                          
          cffi: Not Installed                                 
      cherrypy: Not Installed                                 
      dateutil: 2.6.1                                         
     docker-py: Not Installed                                 
         gitdb: 2.0.3                                         
     gitpython: 2.1.8                                         
        Jinja2: 2.10                                          
       libgit2: Not Installed                                 
      M2Crypto: Not Installed                                 
          Mako: Not Installed                                 
       msgpack: 0.5.6                                         
  msgpack-pure: Not Installed                                 
  mysql-python: Not Installed                                 
     pycparser: Not Installed                                 
      pycrypto: 2.6.1                                         
  pycryptodome: 3.4.7                                         
        pygit2: Not Installed                                 
        Python: 3.6.9 (default, Dec  8 2021, 21:08:43)        
  python-gnupg: 0.4.1                                         
        PyYAML: 3.12                                          
         PyZMQ: 17.1.2                                        
         smmap: 2.0.3                                         
       timelib: Not Installed                                 
       Tornado: 4.5.3                                         
           ZMQ: 4.2.5                                         
                                                              
System Versions:                                              
          dist: ubuntu 18.04 Bionic Beaver                    
        locale: UTF-8                                         
       machine: x86_64                                        
       release: 4.15.0-135-generic                            
        system: Linux                                         
       version: Ubuntu 18.04 Bionic Beaver                    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.