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

sudo: failure handling could be more robust #143

Closed
rouge8 opened this issue Mar 14, 2018 · 2 comments
Closed

sudo: failure handling could be more robust #143

rouge8 opened this issue Mar 14, 2018 · 2 comments
Labels
bug Code feature that hinders desired execution outcome good first issue Issues that *might* be a good place for a beginner to start sudo Issues impacting mostly sudo.py

Comments

@rouge8
Copy link

rouge8 commented Mar 14, 2018

I'm super excited by the possibilities of mitogen (and working to get my company to back the Kickstarter...), but with the latest mitogen (b0440b7), I'm getting a crash as soon as I use become: true:

Ansible version:

ansible 2.4.3.0
  config file = /Users/andy/gr/myproject/ansible.cfg
  configured module search path = [u'/Users/andy/gr/myproject/ansible/library', u'/Users/andy/gr/myproject/ansible/library/vendor']
  ansible python module location = /Users/andy/gr/myproject/.tox/deploy/lib/python2.7/site-packages/ansible
  executable location = .tox/deploy/bin/ansible
  python version = 2.7.14 (default, Mar  1 2018, 19:23:40) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

Playbook:

---

- hosts: all
  tasks:
  - command: "true"
    become: true

Remote system

uname -a

Linux some-host-bastion 4.4.23-31.54.amzn1.x86_64 #1 SMP Tue Oct 18 22:02:09 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

sudo -V

Sudo version 1.8.6p3
Sudoers policy plugin version 1.8.6p3
Sudoers file grammar version 42
Sudoers I/O plugin version 1.8.6p3

Logs

[pid 71988] 22:39:28 D mitogen: unix.connect(path='/var/folders/bw/ghklm2fs6bx_x9x_f0wg5kph0000gn/T/mitogen_unix_YJwmI_')
[pid 71988] 22:39:28 D mitogen: unix.connect(): local ID is 3, remote is 0
[pid 71977] 22:39:28 D mitogen: Context(2, u'ssh.some-host-web').call_async(<function _proxy_connect at 0x10d1602a8>, *(None, 4, 'sudo', {'sudo_path': u'sudo', 'profiling': False, 'sudo_args': ['-H', '-S', '-n'], 'username': u'root', 'password': None, 'python_path': u'/usr/bin/python', 'debug': False}), **{})
[pid 71977] 22:39:28 D mitogen: ModuleResponder(Router(Broker()))._on_get_module('mitogen.parent')
[pid 71977] 22:39:28 D mitogen: pkgutil._get_module_via_pkgutil('mitogen.parent') -> <pkgutil.ImpLoader instance at 0x10d694488>
[pid 71977] 22:39:28 D mitogen: pkgutil._get_module_via_pkgutil('mitogen.core') -> <pkgutil.ImpLoader instance at 0x10d694440>
[pid 71977] 22:39:28 D mitogen: pkgutil._get_module_via_pkgutil('mitogen') -> <pkgutil.ImpLoader instance at 0x10d2faf80>
[pid 71977] 22:39:28 D mitogen: _send_load_module(mitogen.ssh.Stream(u'ssh.some-host-web'), 'mitogen.parent')
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen: _proxy_connect(): constructing ModuleForwarder
[pid 71977] 22:39:28 D mitogen: ModuleResponder(Router(Broker()))._on_get_module('mitogen.sudo')
[pid 71977] 22:39:28 D mitogen: pkgutil._get_module_via_pkgutil('mitogen.sudo') -> <pkgutil.ImpLoader instance at 0x10d2fafc8>
[pid 71977] 22:39:28 D mitogen: _send_load_module(mitogen.ssh.Stream(u'ssh.some-host-web'), 'mitogen.sudo')
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen: mitogen.sudo.Stream('default').connect()
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen.sudo: sudo command line: [u'sudo', '-u', u'root', '--set-home', u'/usr/bin/python', '-c', 'import codecs,os,sys;_=codecs.decode;exec(_(_("eNpdj81OwzAQhM/kKbitLZzKTlQQkSIVRYh7DuQAqMrPtrVIbctOcOHpcZVKuNz225nd0dSsKbVbGWmQ0MQyH5Hc3QbYaftJaJHchHmYTUY4E5zTP65ZTDaoYuF+1A5JHYONoYnBL4DqS1qt3uCpfnnl8FG677A8YT9PbTfi4gk4kmuBwVFOeo+qwD5LZ4d2c+gP9pS6qd1j6rErRJ7xHGgSPngrJySCwXPF31XYVeWWnLsO2qAKDcF2QFcW24E88oc1ZfAjzXJ78TQMPITml19VrPlrDfI8W9+HnLvqf7o4p/8CvEJ1xw==".encode(),"base64"),"zip"))']
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen: tty_create_child() child 13244 fd 15, parent 13203, cmd: "sudo" "-u" "root" "--set-home" "/usr/bin/python" "-c" "import codecs,os,sys;_=codecs.decode;exec(_(_(\"eNpdj81OwzAQhM/kKbitLZzKTlQQkSIVRYh7DuQAqMrPtrVIbctOcOHpcZVKuNz225nd0dSsKbVbGWmQ0MQyH5Hc3QbYaftJaJHchHmYTUY4E5zTP65ZTDaoYuF+1A5JHYONoYnBL4DqS1qt3uCpfnnl8FG677A8YT9PbTfi4gk4kmuBwVFOeo+qwD5LZ4d2c+gP9pS6qd1j6rErRJ7xHGgSPngrJySCwXPF31XYVeWWnLsO2qAKDcF2QFcW24E88oc1ZfAjzXJ78TQMPITml19VrPlrDfI8W9+HnLvqf7o4p/8CvEJ1xw==\".encode(),\"base64\"),\"zip\"))"
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen: mitogen.sudo.Stream('local.13244').connect(): child process stdin/stdout=15
[pid 71977] 22:39:28 D mitogen.ctx.ssh.some-host-web: mitogen.sudo: mitogen.sudo.Stream('local.13244'): received "sudo: invalid option -- '-'\nusage: sudo [-D level] -h | -K | -k | -V\nusage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user\n            name|#uid]\nusage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user\n            name] [-u user name|#uid] [-g groupname|#gid] [command]\nusage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]\n            [VAR=value] [-i|-s] [<command>]\nusage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] file ...\n"
[pid 71977] 22:39:28 E mitogen: While invoking <ansible_mitogen.services.ContextService object at 0x10d177f10>.dispatch()
Traceback (most recent call last):
  File "/Users/andy/forks/mitogen/mitogen/service.py", line 72, in run_once
    msg.reply(self.dispatch(args, msg))
  File "/Users/andy/forks/mitogen/ansible_mitogen/services.py", line 70, in dispatch
    self._context_by_key[key] = method(**dct)
  File "/Users/andy/forks/mitogen/mitogen/master.py", line 647, in sudo
    return self.connect('sudo', **kwargs)
  File "/Users/andy/forks/mitogen/mitogen/parent.py", line 461, in connect
    return self.proxy_connect(via, method_name, name=name, **kwargs)
  File "/Users/andy/forks/mitogen/mitogen/parent.py", line 470, in proxy_connect
    name, context_id, method_name, kwargs
  File "/Users/andy/forks/mitogen/mitogen/master.py", line 612, in call
    return receiver.get().unpickle(throw_dead=False)
  File "/Users/andy/forks/mitogen/mitogen/core.py", line 314, in unpickle
    raise obj
CallError: mitogen.core.StreamError: EOF on stream; last 300 bytes received: 'r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]\n            [VAR=value] [-i|-s] [<command>]\nusage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] file ...\n'
  File "<stdin>", line 1391, in _dispatch_calls
  File "<stdin>", line 1386, in _dispatch_one
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 264, in _proxy_connect
    **kwargs
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 449, in _connect
    stream.connect()
  File "master:/Users/andy/forks/mitogen/mitogen/sudo.py", line 131, in connect
    super(Stream, self).connect()
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 395, in connect
    self._connect_bootstrap()
  File "master:/Users/andy/forks/mitogen/mitogen/sudo.py", line 150, in _connect_bootstrap
    time.time() + 10.0):
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 207, in iter_read
    (''.join(bits)[-300:],)

[pid 71988] 22:39:28 D ansible_mitogen.connection: Call run_module('ansible.modules.commands.command',) took 218 ms
[pid 71988] 22:39:28 D mitogen: mitogen.core.Stream('unix_listener.71977').on_disconnect()
[pid 71977] 22:39:28 D mitogen: mitogen.core.Stream('unix_client.71988').on_disconnect()
[pid 71988] 22:39:28 D mitogen: Waker(Broker()).on_disconnect()
The full traceback is:
Traceback (most recent call last):
  File "/Users/andy/gr/myproject/.tox/ansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 130, in run
    res = self._execute()
  File "/Users/andy/gr/myproject/.tox/ansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 528, in _execute
    result = self._handler.run(task_vars=variables)
  File "/Users/andy/forks/mitogen/ansible_mitogen/mixins.py", line 128, in run
    return super(ActionModuleMixin, self).run(tmp, task_vars)
  File "/Users/andy/gr/myproject/.tox/ansible/lib/python2.7/site-packages/ansible/plugins/action/normal.py", line 45, in run
    results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars, wrap_async=wrap_async))
  File "/Users/andy/forks/mitogen/ansible_mitogen/mixins.py", line 308, in _execute_module
    env=cast(env),
  File "/Users/andy/forks/mitogen/ansible_mitogen/mixins.py", line 137, in call
    return self._connection.call(func, *args, **kwargs)
  File "/Users/andy/forks/mitogen/ansible_mitogen/connection.py", line 238, in call
    return self.call_async(func, *args, **kwargs).get().unpickle()
  File "/Users/andy/forks/mitogen/ansible_mitogen/connection.py", line 224, in call_async
    self._connect()
  File "/Users/andy/forks/mitogen/ansible_mitogen/connection.py", line 204, in _connect
    self.context = self._connect_sudo(via=self.host)
  File "/Users/andy/forks/mitogen/ansible_mitogen/connection.py", line 172, in _connect_sudo
    self._play_context.become_flags or ''
  File "/Users/andy/forks/mitogen/mitogen/service.py", line 91, in call
    return recv.get().unpickle()
  File "/Users/andy/forks/mitogen/mitogen/core.py", line 314, in unpickle
    raise obj
CallError: mitogen.core.CallError: mitogen.core.StreamError: EOF on stream; last 300 bytes received: 'r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]\n            [VAR=value] [-i|-s] [<command>]\nusage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g\n            groupname|#gid] [-p prompt] [-u user name|#uid] file ...\n'
  File "<stdin>", line 1391, in _dispatch_calls
  File "<stdin>", line 1386, in _dispatch_one
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 264, in _proxy_connect
    **kwargs
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 449, in _connect
    stream.connect()
  File "master:/Users/andy/forks/mitogen/mitogen/sudo.py", line 131, in connect
    super(Stream, self).connect()
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 395, in connect
    self._connect_bootstrap()
  File "master:/Users/andy/forks/mitogen/mitogen/sudo.py", line 150, in _connect_bootstrap
    time.time() + 10.0):
  File "master:/Users/andy/forks/mitogen/mitogen/parent.py", line 207, in iter_read
    (''.join(bits)[-300:],)

  File "/Users/andy/forks/mitogen/mitogen/service.py", line 72, in run_once
    msg.reply(self.dispatch(args, msg))
  File "/Users/andy/forks/mitogen/ansible_mitogen/services.py", line 70, in dispatch
    self._context_by_key[key] = method(**dct)
  File "/Users/andy/forks/mitogen/mitogen/master.py", line 647, in sudo
    return self.connect('sudo', **kwargs)
  File "/Users/andy/forks/mitogen/mitogen/parent.py", line 461, in connect
    return self.proxy_connect(via, method_name, name=name, **kwargs)
  File "/Users/andy/forks/mitogen/mitogen/parent.py", line 470, in proxy_connect
    name, context_id, method_name, kwargs
  File "/Users/andy/forks/mitogen/mitogen/master.py", line 612, in call
    return receiver.get().unpickle(throw_dead=False)
  File "/Users/andy/forks/mitogen/mitogen/core.py", line 314, in unpickle
    raise obj
@dw dw added ansible Issues relating to Mitogen for Ansible bug Code feature that hinders desired execution outcome labels Mar 14, 2018
@dw
Copy link
Member

dw commented Mar 14, 2018

Thanks for the report, it's a combo bug :)

  • sudo didn't introduce long format option parsing until 2013, therefore older sudos will exit with a usage message
  • sudo.py failed to notice the usage message or report the exit status
  • sudo.py should have reported the full output, which would make it obvious this is a flags error

From sudo hg:

changeset:   8920:d13134819944
user:        Todd C. Miller <Todd.Miller@courtesan.com>
date:        Thu Jul 18 16:51:56 2013 -0600
summary:     Add support for long options and fix inclusion of sudo_usage.h with

The crash should be gone in latest master, but keeping this open to track the remaining 2 issues.

@dw dw added the NeedsTest Label for in-progress and closed bugs that do not yet have a corresponding regression test label Mar 14, 2018
@dw dw changed the title Ansible crashes during sudo sudo: failure handling could be more robust Mar 14, 2018
@dw dw added sudo Issues impacting mostly sudo.py good first issue Issues that *might* be a good place for a beginner to start and removed ansible Issues relating to Mitogen for Ansible labels Mar 14, 2018
@rouge8
Copy link
Author

rouge8 commented Mar 14, 2018

sudo didn't introduce long format option parsing until 2013

Amazon Linux is such a mess of ancient RHEL plus modern backports 😩

Thanks for the quick fix!

@dw dw closed this as completed in 98ee3e1 Apr 9, 2018
@dw dw removed the NeedsTest Label for in-progress and closed bugs that do not yet have a corresponding regression test label Apr 9, 2018
PatrickCoakley23 pushed a commit to cyara/mitogen that referenced this issue Nov 10, 2023
Adding configration files for grc-ath2-m1-azurreo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Code feature that hinders desired execution outcome good first issue Issues that *might* be a good place for a beginner to start sudo Issues impacting mostly sudo.py
Projects
None yet
Development

No branches or pull requests

2 participants