salt icon indicating copy to clipboard operation
salt copied to clipboard

Salt failed to run rsync with password file

Open zhoufwind opened this issue 8 years ago • 1 comments

Salt failed to run rsync command with password

This issue can be reproduce both on Linux and Windows. Rsync need use the values of parameters, which store in environment variables, include:

  • USER=root
  • RSYNC_PASSWORD=applepen

Quote from rsync source code: rsync/rsync.yo

Some modules on the remote daemon may require authentication. If so,
you will receive a password prompt when you connect. You can avoid the
password prompt by setting the environment variable RSYNC_PASSWORD to
the password you want to use or using the bf(--password-file) option. This
may be useful when scripting rsync.

WARNING: On some systems environment variables are visible to all
users. On those systems using bf(--password-file) is recommended.

In this case, rsync failed to read the config file, or failed to read the environment variables, so auth failed. Even specified the auth parameters in system variables, still not working.

Setup

salt server role:

  • salt-master: 10.8.89.126
  • salt-syndic: 10.8.48.124
  • salt-minion: 10.8.172.14

rsync server role:

  • rsync server: 10.8.48.124
  • rsync client: 10.8.172.14

Rsync server config(Changed port and server ip):

# cat /etc/rsyncd.conf
pid file = /var/run/rsyncd.pid
port = 59156
address = 10.8.48.124
uid = root
gid = root
use chroot = no
read only = no
max connections = 20
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
#motd file = /etc/rsyncd/rsyncd.motd
timeout = 300
auth users = root
secrets file = /etc/rsyncd.secrets

[test]
path = /tmp/test/
ready only = no

Rsync server password file:

# chmod 600 /etc/rsyncd.secrets 
# cat /etc/rsyncd.secrets
root:applepen

Rsync server source file:

# tree /tmp/test/
/tmp/test/
└── a.log

0 directories, 1 file

Rsync client password file:

# chmod 600 /etc/rsync.passwd
# cat /etc/rsync.passwd 
applepen

Steps to Reproduce Issue

[Normal] Running on rsync client local machine:

# /usr/bin/rsync -avz --delete rsync://10.8.48.124:59156/test /tmp/test/ --password-file=/etc/rsync.passwd
receiving incremental file list
./
a.log

sent 76 bytes  received 147 bytes  446.00 bytes/sec
total size is 0  speedup is 0.00

[ERROR] running failed by command:

# salt 10.8.172.14 cmd.run '/usr/bin/rsync -avz --delete rsync://10.8.48.124:59156/test /tmp/test/ --password-file=/etc/rsync.passwd'
[DEBUG   ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: 10.8.89.126
[DEBUG   ] Missing configuration file: /root/.saltrc
[DEBUG   ] MasterEvent PUB socket URI: /var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: /var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for (u'/etc/salt/pki/master', u'10.8.89.126_master', u'tcp://127.0.0.1:4506', u'clear')
[DEBUG   ] Connecting the Minion to the Master URI (for the return server): tcp://127.0.0.1:4506
[DEBUG   ] Trying to connect to: tcp://127.0.0.1:4506
[DEBUG   ] Initializing new IPCClient for path: /var/run/salt/master/master_event_pub.ipc
[DEBUG   ] LazyLoaded local_cache.get_load
[DEBUG   ] Reading minion list from /var/cache/salt/master/jobs/43/3652e6cb21a84dfd88da7a3d969ee70af4634a0357181b69fe3f34cffdafa6/.minions.p
[DEBUG   ] get_iter_returns for jid 20180711135452788982 sent to set([]) will timeout at 13:55:07.852227
[DEBUG   ] jid 20180711135452788982 return from 10.8.172.14
[DEBUG   ] return event: {u'10.8.172.14': {u'jid': u'20180711135452788982', u'retcode': 5, u'ret': u'@ERROR: auth failed on module test\nrsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]'}}
[DEBUG   ] LazyLoaded nested.output
10.8.172.14:
    @ERROR: auth failed on module test
    rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]
ERROR: Minions returned with non-zero exit code

[ERROR] running failed by salt rsync module:

# salt 10.8.172.14 rsync.rsync rsync://10.8.48.124:59156/test /tmp/test/ delete=True passwordfile=/etc/rsync.passwd
[DEBUG   ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: 10.8.89.126
[DEBUG   ] Missing configuration file: /root/.saltrc
[DEBUG   ] MasterEvent PUB socket URI: /var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: /var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for (u'/etc/salt/pki/master', u'10.8.89.126_master', u'tcp://127.0.0.1:4506', u'clear')
[DEBUG   ] Connecting the Minion to the Master URI (for the return server): tcp://127.0.0.1:4506
[DEBUG   ] Trying to connect to: tcp://127.0.0.1:4506
[DEBUG   ] Initializing new IPCClient for path: /var/run/salt/master/master_event_pub.ipc
[DEBUG   ] LazyLoaded local_cache.get_load
[DEBUG   ] Reading minion list from /var/cache/salt/master/jobs/4f/4a4c59de579285ab942f8294ebcd6857ab9af7380a00e93a60f18af0148432/.minions.p
[DEBUG   ] get_iter_returns for jid 20180711145548660100 sent to set([]) will timeout at 14:56:03.713198
[DEBUG   ] jid 20180711145548660100 return from 10.8.172.14
[DEBUG   ] return event: {u'10.8.172.14': {u'jid': u'20180711145548660100', u'retcode': 5, u'ret': {u'pid': 15344, u'retcode': 5, u'stderr': u'@ERROR: auth failed on module test\nrsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]', u'stdout': u''}}}
[DEBUG   ] LazyLoaded nested.output
10.8.172.14:
    ----------
    pid:
        15344
    retcode:
        5
    stderr:
        @ERROR: auth failed on module test
        rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]
    stdout:
ERROR: Minions returned with non-zero exit code

Versions Report

salt-master & salt-syndic

# salt --versions-report
Salt Version:
           Salt: 2018.3.2
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Mar 30 2018, 15:31:59)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
 
System Versions:
           dist: centos 6.5 Final
         locale: UTF-8
        machine: x86_64
        release: 2.6.32-431.11.25.el6.ucloud.x86_64
         system: Linux
        version: CentOS 6.5 Final
# rpm -qa|grep salt
salt-master-2018.3.2-1.el6.noarch
salt-repo-latest-2.el6.noarch
salt-2018.3.2-1.el6.noarch
salt-minion-2018.3.2-1.el6.noarch

salt-minion

# rpm -qa|grep salt
salt-repo-latest-2.el7.noarch
salt-minion-2018.3.2-1.el7.noarch
salt-2018.3.2-1.el7.noarch

zhoufwind avatar Jul 11 '18 07:07 zhoufwind

Fixed this issue by sets the environment variables for inside of salt, closing this issue now.

# cat /srv/salt/zhoufeng/files/set_rsync_env.sls 
environment_variables:
  environ.setenv:
    - name: rsync
    - update_minion: True
    - value:
        USER: "root"
        RSYNC_PASSWORD: "applepen"

# salt 10.8.172.14 state.apply zhoufeng/files/set_rsync_env
10.8.172.14:
----------
          ID: environment_variables
    Function: environ.setenv
        Name: rsync
      Result: True
     Comment: Environ values were set
     Started: 19:15:13.012966
    Duration: 7.606 ms
     Changes:   
              ----------
              RSYNC_PASSWORD:
                  applepen
              USER:
                  root

Summary for 10.8.172.14
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   7.606 ms

# salt 10.8.172.14 cmd.run 'echo $USER $RSYNC_PASSWORD'
10.8.172.14:
    root applepen

# salt 10.8.172.14 cmd.run '/usr/bin/rsync -avz --delete rsync://10.8.48.124:59156/test /tmp/test/'
10.8.172.14:
    receiving incremental file list
    
    sent 54 bytes  received 108 bytes  108.00 bytes/sec
    total size is 0  speedup is 0.00

zhoufwind avatar Jul 11 '18 11:07 zhoufwind