Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case logic in saltmod.py:function fails to handle ssh permsision denied #54849

Open
brianthelion opened this issue Oct 2, 2019 · 0 comments
Open
Labels
Confirmed Salt engineer has confirmed bug/feature - often including a MCVE
Milestone

Comments

@brianthelion
Copy link

brianthelion commented Oct 2, 2019

Description of Issue

Typical mdata coming back from permission denied on an ssh attempt on a minion looks as follows:

{'stdout': "ubuntu@10.42.1.154's password: \nubuntu@10.42.1.154's password: \nubuntu@10.42.1.154's password: \n", 'stderr': "Warning: Permanently added '10.42.1.154' (ECDSA) to the list of known hosts.\r\nPermission denied, please try again.\r\nPermission denied, please try again.\r\nubuntu@10.42.1.154: Permission denied (publickey,password).\r\n", 'retcode': 255}

Meanwhile, saltmod.py:function implements the following logic:

salt/salt/states/saltmod.py

Lines 600 to 619 in e683178

for minion, mdata in six.iteritems(cmd_ret):
m_ret = False
if mdata.get('retcode'):
func_ret['result'] = False
fail.add(minion)
if mdata.get('failed', False):
m_func = False
else:
if 'return' in mdata and 'ret' not in mdata:
mdata['ret'] = mdata.pop('return')
m_ret = mdata['ret']
m_func = (not fail_function and True) or __salt__[fail_function](m_ret)
if m_ret is False:
m_func = False
if not m_func:
if minion not in fail_minions:
fail.add(minion)
changes[minion] = m_ret

The result is:

[DEBUG   ] An exception occurred in this state: 'ret'
Traceback (most recent call last):
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/loader.py", line 1951, in wrapper
    return f(*args, **kwargs)
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/states/saltmod.py", line 554, in function
    m_ret = mdata['ret']
KeyError: 'ret'
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/loader.py", line 1951, in wrapper
    return f(*args, **kwargs)
  File "/home/f0cal/_venv/lib/python3.6/site-packages/salt/states/saltmod.py", line 554, in function
    m_ret = mdata['ret']
KeyError: 'ret'

The logic is clearly failing to handle the case where there's a nonzero retcode without a corresponding minion return in the blob.

Setup

Steps to Reproduce Issue

Versions Report

Salt Version:
           Salt: 2019.2.1
 
Dependency Versions:
           cffi: 1.12.3
       cherrypy: Not Installed
       dateutil: 2.8.0
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug 20 2019, 17:12:48)
   python-gnupg: Not Installed
         PyYAML: 4.2
          PyZMQ: 18.1.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.2
 
System Versions:
           dist: Ubuntu 18.04 bionic
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-64-generic
         system: Linux
        version: Ubuntu 18.04 bionic
@waynew waynew added Confirmed Salt engineer has confirmed bug/feature - often including a MCVE P4 Priority 4 and removed needs-triage labels Dec 5, 2019
@waynew waynew added this to the Approved milestone Dec 5, 2019
@waynew waynew removed their assignment Feb 28, 2020
@sagetherage sagetherage removed the P4 Priority 4 label Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Confirmed Salt engineer has confirmed bug/feature - often including a MCVE
Projects
None yet
Development

No branches or pull requests

4 participants