Repository navigation
Closed
Labels
ansibleIssues relating to Mitogen for AnsibleIssues relating to Mitogen for Ansibletransport:sudoIssues impacting mostly mitogen/sudo.pyIssues impacting mostly mitogen/sudo.pyuser-reported
Description
I'm getting the following error when running my playbook to update a remote CentOS7 machine
(the same playbook works perfectly well on all my Ubuntu instances).
____________
< PLAY [all] >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
________________________
< TASK [Gathering Facts] >
------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
fatal: [centos7]: FAILED! => {"msg": "error occurred on host xxx.xxx.xxx.xxx: Failed to create a PTY: [Errno 1] Operation not permitted. It is likely the maximum number of PTYs has been reached. Consider increasing the 'kern.tty.ptmx_max' sysctl on OS X, the 'kernel.pty.max' sysctl on Linux, or modifying your configuration to avoid PTY use."}
to retry, use: --limit @/Users/xxx/ansible/script/update.retry
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
centos7 : ok=0 changed=0 unreachable=0 failed=1
My CentOS7 instance has enough PTYs as you can see:
# sysctl kernel.pty.max
kernel.pty.max = 5120
Moreover, it's an idle machine. No service is running on it except the default ones.
My host config is:
- macOS High Sierra
10.13.6 - Mitogen from GIT
master (ec05604) - Python
$ python
Python 2.7.15 (default, Oct 2 2018, 11:47:18)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
- Ansible from
brew
$ ansible --version
ansible 2.7.5
config file = /Users/xxx/.ansible.cfg
configured module search path = ['/Users/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/2.7.5/libexec/lib/python3.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.1 (default, Nov 28 2018, 11:51:54) [Clang 10.0.0 (clang-1000.11.45.5)]
- My
~/.ansible.cfgis:
[ssh_connection]
retries=3
pipelining = True
[defaults]
timeout = 20
host_key_checking = False
ssh_args = -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=60
strategy_plugins = ~/.ansible/plugins/mitogen/ansible_mitogen/plugins/strategy
strategy = mitogen_linear
[ IMPORTANT ]
if I disablemitogen, the playbook works well forCentOS7!!!
Reacted by Stéphane
Metadata
Metadata
Assignees
Labels
ansibleIssues relating to Mitogen for AnsibleIssues relating to Mitogen for Ansibletransport:sudoIssues impacting mostly mitogen/sudo.pyIssues impacting mostly mitogen/sudo.pyuser-reported
Activity
[-]Failed to create a PTY on CentOS7[/-][+]Failed to create a PTY. Operation not permitted [on CentOS7][/+]sboisson commentedon Jan 4, 2019
I have the exact same problem, with a host running on macOS Mojave 10.14.2 and a specific server running CentOS Linux release 7.5.1804 (Core).
But I do not have the problem with others servers running the same OS or CentOS Linux 6 or Ubuntu.
On both CentOS 7 servers I have: kernel.pty.max = 4096
I've attached logs I get when I run ansible with -vvvv flag. The issue seems to be related to sudo, but I couldn't find the difference in
/etc/sudoerand/etc/ssh/sshd_configbetween the two serversansible.log
dw commentedon Jan 17, 2019
Sorry for the extreme delay replying to this one. Can either of you confirm whether SELinux is enabled or not? Is there anything else about your configuration that might be considered 'non-default', say, are you logging in with an LDAP account or suchlike that might effect group memberships, etc.
dw commentedon Jan 17, 2019
Would it be possible to include the output of these commands executed from the SSH account that is failing to sudo:
Also if you can think of any security features that might be enabled on these servers that aren't enabled elsewhere.. different install script / admin team perhaps? etc.
If
straceis available on these hosts, it would be immensely useful to get the output of an Ansible run including-e ansible_python_interpreter=/path/to/script, with the script below saved to the remote server's disk and marked executable:This produces a set of
/tmp/whybroken.*files, one of which, if you grep for it, will contain a reference to/dev/ptmx. A copy of that file would be absolutely idealThanks again!
yhafri commentedon Jan 18, 2019
Here you are:
As explained above, eveything works as expected if i use
Ansible without mitogen. Thus, it's unlikely that the issue is related to any security features that might be enabled.Strace's test:
dw commentedon Jan 18, 2019
This is amazing, thanks so much -- it's ruled out one problem (ioctl() against
ptmxmay fail if rUID/eUID do not match).Re the strace log, would it be possible to get a copy of that log, or at least, the lines starting at
/dev/ptmxand running to what I assume is a line that ends with "= -1 EPERM (Operation not permitted)"yhafri commentedon Jan 18, 2019
Sure thing. Attached
whybroken.10011whybroken.10011.zip
dw commentedon Jan 18, 2019
The devpts mount is set with no 'gid=' option, therefore when the new PTY is allocated, the kernel gives it the GID of the process (1000). Something in Python or the C library does not like that, and wants to change its group to 5 (probably the 'tty' group, so "wall" and commands like that function), and that's the source of the error.
From looking at a uname() line in the log, and also the presence of multiple devpts mounts in the previous output, am I right in saying this is a container of some sort? What kind of container runtime created it?
Mitogen does not require the group to be changed on its PTYs, so this can definitely be worked around, I assume it is overzealous library code causing the problem. This issue in
rktlooks like a very similar problem, the strace is basically the same: rkt/rkt#2152As for why it does not manifest with regular Ansible, that is because in that case, IIRC the whole SSH connection is started interactively, which means the SSH daemon sets up the PTY. This puts severe constraints on non-interactive use of the channel (e.g. buffer sizes for a PTY are tiny), and so Mitogen only allocates PTYs as needed and (ideally) only in cases where they are definitely required.
Does your Ansible configuration include a become password? If not, then that is a separate bug -- Mitogen should not be allocating a PTY at all in this case.
dw commentedon Jan 18, 2019
The failing library code is grantpt() in the C library, called by openpty() in the C library, called by os.openpty() in Python
yhafri commentedon Jan 18, 2019
Thanks for the detailed explanations.
Yes, that's a customer kernel from a Cloud provider.
Nope. There is no
become passwordin my config.dw commentedon Jan 18, 2019
An entire LWN article dedicated to this very issue :)
yhafri commentedon Jan 18, 2019
Can you think of any solution/workaround?
dw commentedon Jan 18, 2019
When you say it is a customer kernel, does it mean they have replaced the OVH-supplied kernel? CentOS 7 should have shipped with Linux 3.10, and unfortunately for us, the fix mentioned in the LWN article did not arrive until Linux 4.8.
If I understand things correctly, I think you are SSHing into a container whose magic
/dev/ptsfilesystem is not configured correctly. This problem does not manifest on my local CentOS 7 VM, and indeed, only one/dev/ptsmount is visible on that VM, so those extra mounts must be coming from some piece of software -- I assume a container manager program like LXC, LXD, or Docker, but perhaps there is another explanation so far we are missing.Thanks for all your help so far. I will need to setup a reproduction for this in order to test a workaround. TTY handling code is very fragile, and if we are short-circuiting the C library to setup a TTY ourselves, it would be nice to limit it only to this particular case. This may take some more time over the weekend.
I remembered the reason sudo is always called with a TTY -- it is because many sudo configurations ship with an incredibly pointless
requirettyoption enabled. It is pure security theatre. Without it, no password can be typed, and even when no password is required, sudo will still refuse to run. It might be possible to detectrequiretty's existence, but not without creating authentication failures in the system log. So it is better we try to fix PTY allocation instead.Thanks again for your help
yhafri commentedon Jan 18, 2019
Kernel version is
4.9.58, so the issue should be fixed (>4.8).No rush @dw. Tell me what I can do to help if/when needed.
1 remaining item
parent: cope with broken /dev/pts on Linux; closes #462.
dw commentedon Jan 18, 2019
After more Google searches, I'm sufficiently convinced there are enough broken systems around that this merits a code change.
I have created a new branch containing a fix. Would it be possible to run Mitogen from the issue462 branch to ensure both issues have abated? Pretty sure this fixes @yhafri's case, but it would nice to confirm @sboisson's issue is identical.
issue #462: docs: update Changelog.
yhafri commentedon Jan 18, 2019
Awesome. The fix in branch
issue462worked.I only got these 2 errors in the middle of the output:
yhafri commentedon Jan 18, 2019
After Googling a little bit, i found this.
Thus, switching from
ignore_errors: Truetofailed_when: Falsesolved the 2 errors unrelated to mitogen IMHO.dw commentedon Jan 18, 2019
Those errors should have been fixed already :) They will definitely be gone for 0.2.4, there is another ticket open for it. You can safely ignore them
yhafri commentedon Jan 18, 2019
Thanks a mill and have a great weekend.
Long life to
mitogen!!!dw commentedon Jan 18, 2019
Thanks so much for your help :) I will keep the ticket open until @sboisson can confirm the fix.
Merge remote-tracking branch 'origin/issue462'
dw commentedon Jan 19, 2019
I merged this down to master in order to work on other things -- @sboisson please reopen if you're still having the problem.
This is now on the master branch and will make it into the next release. To be updated when a new release is made, subscribe to https://networkgenomics.com/mail/mitogen-announce/
Thanks for reporting this!
sboisson commentedon Jan 31, 2019
Sorry for the delay, I was away for holidays. I confirm the change works for me too! :-) (tested with branch master)
Merge pull request mitogen-hq#462 from spearlineltd/14795-spealine-cy…