mitogen icon indicating copy to clipboard operation
mitogen copied to clipboard

Mitogen is not compatible with 'become_exe = "sudo su -" ' in ansible.cfg

Open tdluckyboy opened this issue 5 years ago • 9 comments

Ansible 2.9.2 with ansible.cfg:

[defaults] inventory = /home/xxx/ansible/staging remote_user = xxx host_key_checking = False callback_whitelist = profile_tasks strategy_plugins = /home/xxx/ansible/mitogen-0.2.9/ansible_mitogen/plugins/strategy strategy = mitogen_linear

[privilege_escalation] become = True become_method = su become_user = root become_exe = "/usr/bin/sudo su -"

Mitogen 0.2.9

Python (host 2.7.5 and target is 2.6.6)

OS(Host is CentOS 7.7 and target is RHEL 6.10)

Error:

ansible-playbook site.yml -vvv
The command above failed when going into 'gather fact' step. But will be successful if deleting the 'become_exe' in ansible.cfg.

[mux 18510] 19:00:25.388312 D mitogen.importer.[ssh.xxxxxx]: received mitogen.su [mux 18510] 19:00:25.390934 D mitogen.parent.[ssh.xxxxxx]: creating connection to context 4 using mitogen.su [mux 18510] 19:00:25.399658 D mitogen.importer.[ssh.xxxxxx]: encodings.ascii is submodule of a locally loaded package [mux 18510] 19:00:25.400047 D mitogen.importer.[ssh.xxxxxx]: encodings.base64_codec is submodule of a locally loaded package [mux 18510] 19:00:25.400244 D mitogen.importer.[ssh.xxxxxx]: encodings.base64 is submodule of a locally loaded package [mux 18510] 19:00:25.401381 D mitogen.parent.[ssh.xxxxxx]: command line for Connection(None): "/usr/bin/sudo su -" root -c "/usr/bin/python -c "import codecs,os,sys;=codecs.decode;exec(((\"eNqFkc1OwzAQhO95itxsq1bqFMpPJEugHhAHhBQhcoAKObEDhsS2nKShPD3bFNGkHLjt5xnvrHZTmnHbRE47hUngaT8iXYYApfUfmCTBrpadW2BGY8bIgVM6Jg9qvOeiso3C6Rj8GLIx9AAQ2GwhvhItpNYh5yGSwvfaoFAYOYjqUxVdK/JKDfK8a/w812butu2bNQjmPLbN+PCyUb7R1jwlJ+shVpmN9sDoOr15ZGjNp9/2HsAKTwU6xRnCtW7tqzLJe6W7K93Um7o6W0ZQFMIIKaLC1snpJVsSRAJo2nvdKhxTdHf7cM8YezYIhimshJ2TYMVf8G7r0jplYNfI54hEXgmJ43O2vCAUfWkHnUrHD76Moj5Hu0OU7idgNdT75R65+//cf6eMp1P+nm1BvgFIrbci\".encode(),\"base64\"),\"zip\"))"" [mux 18510] 19:00:25.406699 D mitogen.importer.[ssh.xxxxxx]: encodings.string_escape is submodule of a locally loaded package [mux 18510] 19:00:25.406837 D mitogen.parent.[ssh.xxxxxx]: failed to start child Traceback (most recent call last): File "master:/home/xxx/ansible/mitogen-0.2.9/mitogen/parent.py", line 1681, in async_connect self.proc = self.start_child() File "master:/home/xxx/ansible/mitogen-0.2.9/mitogen/parent.py", line 1527, in start_child raise mitogen.core.StreamError(msg) StreamError: Child start failed: [Errno 2] No such file or directory. Command was: "/usr/bin/sudo su -" root -c "/usr/bin/python -c "import codecs,os,sys;=codecs.decode;exec((_(\"eNqFkc1OwzAQhO95itxsq1bqFMpPJEugHhAHhBQhcoAKObEDhsS2nKShPD3bFNGkHLjt5xnvrHZTmnHbRE47hUngaT8iXYYApfUfmCTBrpadW2BGY8bIgVM6Jg9qvOeiso3C6Rj8GLIx9AAQ2GwhvhItpNYh5yGSwvfaoFAYOYjqUxVdK/JKDfK8a/w812butu2bNQjmPLbN+PCyUb7R1jwlJ+shVpmN9sDoOr15ZGjNp9/2HsAKTwU6xRnCtW7tqzLJe6W7K93Um7o6W0ZQFMIIKaLC1snpJVsSRAJo2nvdKhxTdHf7cM8YezYIhimshJ2TYMVf8G7r0jplYNfI54hEXgmJ43O2vCAUfWkHnUrHD76Moj5Hu0OU7idgNdT75R65+//cf6eMp1P+nm1BvgFIrbci\".encode(),\"base64\"),\"zip\"))""

tdluckyboy avatar Apr 21 '20 01:04 tdluckyboy

Can you try current master of mitogen?

s1113950 avatar May 08 '20 15:05 s1113950

Can you try current master of mitogen?

Thanks for the reply. I just tried, but still the same problem. Based on the error, it seems missing some file or directory, but I can't figure out what it was looking for.

tdluckyboy avatar May 08 '20 16:05 tdluckyboy

I think it's because of how mitogen creates the su and sudo command to use 🤔 Here's an alternative to what could work in the meantime though:

become = True
become_method = su
become_user = root
become_exe = sudo

s1113950 avatar May 08 '20 16:05 s1113950

I think it's because of how mitogen creates the su and sudo command to use 🤔 Here's an alternative to what could work in the meantime though:

become = True
become_method = su
become_user = root
become_exe = sudo

Yep, that may work, but unfortunately, I need to use 'sudo su -' to switch to the user root. The setting above didn't generate 'sudo su -' and gave me the sudo warnings "We trust you have received the usual lecture from the local System".

tdluckyboy avatar May 08 '20 17:05 tdluckyboy

ahh ok. In that case I'm not sure of a fix you can use in the meantime :/ Once I finish collections support I'll try and repro/fix this if it hasn't been fixed by then :)

s1113950 avatar May 08 '20 18:05 s1113950

ahh ok. In that case I'm not sure of a fix you can use in the meantime :/ Once I finish collections support I'll try and repro/fix this if it hasn't been fixed by then :)

Much appreciated.

tdluckyboy avatar May 08 '20 18:05 tdluckyboy

I'm running a similar setup with RHEL7 where the target system has a custom sudo exe which requires the - at the end of the become_exe option. Until this issue isn't solved I'm not able to get onto mitogen ;(

mongrelion avatar May 20 '20 13:05 mongrelion

@tdluckyboy @mongrelion to aid in debugging, could someone create a minimal Dockerfile with a reproducible environment I can use to test with? Collections support will probably take awhile to complete (much discussion around it here: #715 ); I can try and get to this ticket at the same time, but I don't have a ton of extra dev time to spare at the moment. A Dockerfile would make that a faster process 😅

s1113950 avatar May 20 '20 16:05 s1113950

@s1113950, this issue still happens and is pretty annoying. I kind of assume that the cause of it seems to be that somewhere in Mitogen's code there's a check that if become_exe exists/is file/is executable. Since using sudo su - is kind of a hacky way doing things by defining become_method: su and become_exe: sudo su - then Mitogen fails to account that become_exe also might contain executable arguments and thinks that sudo su - should be the executable's filename and checks if it exists/is file/is executable, which obviously fails because there is no such thing as sudo su -, thats why the No such file or directory error.

Edit:

It seems that the offending part could be https://github.com/mitogen-hq/mitogen/blob/master/mitogen/parent.py#L336

gynter avatar Apr 19 '21 13:04 gynter