Skip to content

Disabling cmd module causes connection error to master #52592

Closed

Description

@eric-price

Description of Issue/Question

I'm trying to disable the cmd module on a few critical hosts and seeing an error in the minion logs with connecting to the master. The timezone library uses cmd.run resulting in this error after blacklisting the cmdmod module.

2019-04-17 20:40:20,064 [salt.minion      :1041][CRITICAL][30565] Unexpected error while connecting to salt-master.domain
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1018, in _connect_minion
    yield minion.connect_master(failed=failed)
  File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1055, in run
    value = future.result()
  File "/usr/lib64/python2.7/site-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1063, in run
    yielded = self.gen.throw(*exc_info)
  File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1216, in connect_master
    yield self._post_master_init(master)
  File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1055, in run
    value = future.result()
  File "/usr/lib64/python2.7/site-packages/tornado/concurrent.py", line 238, in result
    raise_exc_info(self._exc_info)
  File "/usr/lib64/python2.7/site-packages/tornado/gen.py", line 1069, in run
    yielded = self.gen.send(value)
  File "/usr/lib/python2.7/site-packages/salt/minion.py", line 1263, in _post_master_init
    cleanup=[master_event(type='alive')])
  File "/usr/lib/python2.7/site-packages/salt/utils/schedule.py", line 106, in __new__
    utils=utils)
  File "/usr/lib/python2.7/site-packages/salt/utils/schedule.py", line 152, in __singleton_init__
    self.time_offset = self.functions.get('timezone.get_offset', lambda: '0000')()
  File "/usr/lib/python2.7/site-packages/salt/modules/timezone.py", line 234, in get_offset
    return __salt__['cmd.run'](['date', '+%z'], python_shell=False)
  File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1196, in __getitem__
    func = super(LazyLoader, self).__getitem__(item)
  File "/usr/lib/python2.7/site-packages/salt/utils/lazy.py", line 108, in __getitem__
    raise KeyError(key)
KeyError: u'cmd.run

Steps to Reproduce Issue

Add to minion conf file:
disable_modules: cmdmod

Versions Report

           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.8
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.5
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.10 (default, Dec 19 2015, 08:44:39)
   python-gnupg: Not Installed
         PyYAML: 4.1
          PyZMQ: 17.1.2
           RAET: Not Installed
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.1.3.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

Activity

  1. UtahDave commented on Apr 17, 2019

    @UtahDave
    Contributor

    Many parts of salt use the cmd module.

    Have you tried blacklisting it instead of disabling it?

    https://docs.saltstack.com/en/latest/ref/configuration/master.html#std:conf_master-publisher_acl_blacklist

    I believe that should allow other Salt modules to use cmd.run, but not allow users to call it directly.

  2. eric-price commented on Apr 17, 2019

    @eric-price
    Author

    That's an all or nothing method of blocking cmd.run? Would like to block cmd.run on a select few hosts, specifically, the use of cmd.run 'rm -rf'. Does this method look at the arg given to the module or just the module?

  3. s0undt3ch commented on Apr 18, 2019

    @s0undt3ch
    Contributor

    Yeah, it would be hard to now allowing the cmd module to load, many parts of salt rely on it...

  4. added
    v2019.2.0
    on Apr 18, 2019
  5. garethgreenaway commented on Apr 24, 2019

    @garethgreenaway
    Contributor

    @eric-price Blacklisting would be an all-or-nothing, but you could do it on certain hosts. We currently don't support filtering on the command being passed via cmd.run.

  6. eric-price commented on Apr 24, 2019

    @eric-price
    Author

    Thanks for the info and quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v2019.2.0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions