saltstack / saltstack/salt

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

Open
#54,849 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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:
https://github.com/saltstack/salt/blob/e683178e37640b0be3ebbd6029e33172505144ab/salt/states/saltmod.py#L600-L619

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

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.

Research direction

Start in salt/states/saltmod.py:function around the linked lines and inspect how the mdata dictionary is handled when retcode is nonzero but ret is absent. Reproduce with the permission-denied mdata shown in the issue; done means the state reports the SSH failure without raising KeyError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.