Hide Forgot
Description of problem: ssh with hostbased auth fails after changing group ID ( with newgrp, etc. ) although hostbased auth normally is accepted. and ssh reports "setresgid XXXX: Operation not permitted". Version-Release number of selected component (if applicable): openssh-clients-7.4p1-11.el7.x86_64 How reproducible: run ssh with both HostBasedAuthentication and EnableSSHKeysign enabled, after changing the group ID to one of the supplementary groups. Steps to Reproduce: 1. run "newgrp" with one of the supplementary groups as its argument 2. under the newgrp'ed session, run ssh with hostbased auth enabled Actual results: Expected results: Additional info: comparing output; -- normal -- user1$ getent passwd user1 user1:x:1001:1001::/home/user1:/bin/bash user1$ id uid=1001(user1) gid=1001(group1) groups=1001(group1),1002(group2) user1$ ssh -v -o HostbasedAuthentication=yes -o PubkeyAuthentication=no host1 hostname ... debug1: userauth_hostbased: trying hostkey ... debug1: permanently_drop_suid: 1001 debug1: Authentication succeeded (hostbased). ... host1 Transferred: ... Bytes per second: ... debug1: Exit status 0 -- chgrp'ed -- user1$ getent passwd user1 user1:x:1001:1001::/home/user1:/bin/bash user1$ newgrp group2 user1$ id uid=1001(user1) gid=1002(group2) groups=1002(group2),1001(group1) user1$ ssh -v -o HostbasedAuthentication=yes -o PubkeyAuthentication=no host1 hostname ... debug1: userauth_hostbased: trying hostkey ... debug1: permanently_drop_suid: 1001 setresgid 1001: Operation not permitted ssh_keysign: no reply sign using hostkey ... failed Permission denied (publickey,hostbased).
Did you make sure that the change was effective in your use case by re-logging in the user or using the - switch to newgrp? With what are you comparing the "working" part? Was it working before? In which version?
(In reply to Jakub Jelen from comment #2) > Did you make sure that the change was effective in your use case by > re-logging in the user or using the - switch to newgrp? "newgrp - group2" made no difference. > With what are you comparing the "working" part? Was it working before? In > which version? I remember ssh in RHEL6 did not have problems like this, in other words, I used to run ssh in newgrp'ed sessions and hostbased-auth did not fail. But I can't verify that because I have no RHEL6 environment now. Instead, I tried CentOS6/openssh-5.3p1-94.el6.x86_64 ( hostname: mic, ssh client and server were on a same node ) and I found, as I expect, ssh did neither fail hostbased-auth nor report "setresgid XXXX: Operation not permitted" in a newgrp'ed session. --- not newgrp'ed user61$ getent passwd user61 user61:x:1101:1101::/home/user61:/bin/bash user61$ id uid=1101(user61) gid=1101(group61) groups=1101(group61),1102(group62) user61$ ssh -v -o PubkeyAuthentication=no -o HostbasedAuthentication=yes localhost hostname ... debug1: Next authentication method: hostbased debug1: permanently_drop_suid: 1101 debug1: Remote: Accepted for localhost [::1] by /etc/ssh/shosts.equiv. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password,hostbased debug1: permanently_drop_suid: 1101 debug1: Remote: Accepted for localhost [::1] by /etc/ssh/shosts.equiv. debug1: Authentication succeeded (hostbased). ... mic ... debug1: Exit status 0 -- newgrp'ed user61$ newgrp group62 user61$ id uid=1101(user61) gid=1102(group62) groups=1101(group61),1102(group62) user61$ ssh -v -o PubkeyAuthentication=no -o HostbasedAuthentication=yes localhost hostname ... debug1: Next authentication method: hostbased debug1: permanently_drop_suid: 1101 debug1: Remote: Accepted for localhost [::1] by /etc/ssh/shosts.equiv. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password,hostbased debug1: permanently_drop_suid: 1101 debug1: Remote: Accepted for localhost [::1] by /etc/ssh/shosts.equiv. debug1: Authentication succeeded (hostbased). ... mic ... debug1: Exit status 0
ok, forget about the previous comment. It is going through different code paths. Here is a debug3 log as I reproduced it with the latest openssh: debug3: authmethod_is_enabled hostbased debug1: Next authentication method: hostbased debug3: userauth_hostbased: trying key type ecdsa-sha2-nistp256-cert-v01 debug3: userauth_hostbased: trying key type ecdsa-sha2-nistp384-cert-v01 debug3: userauth_hostbased: trying key type ecdsa-sha2-nistp521-cert-v01 debug3: userauth_hostbased: trying key type ssh-ed25519-cert-v01 debug3: userauth_hostbased: trying key type ssh-rsa-cert-v01 debug3: userauth_hostbased: trying key type ecdsa-sha2-nistp256 debug1: userauth_hostbased: trying hostkey ecdsa-sha2-nistp256 SHA256:OyN0FVZ1BiQ5cgEY8L7+jrEMuWRXarBBGs7Faw1mDgA debug2: userauth_hostbased: chost f26. debug3: ssh_msg_send: type 2 debug3: ssh_msg_recv entering debug1: permanently_drop_suid: 1001 debug3: ssh_keysign: [child] pid=14766, exec /usr/libexec/openssh/ssh-keysign setresgid 1002: Operation not permitted ssh_keysign: no reply sign using hostkey ecdsa-sha2-nistp256 SHA256:OyN0FVZ1BiQ5cgEY8L7+jrEMuWRXarBBGs7Faw1mDgA failed debug2: we did not send a packet, disable method The error is not coming from the ssh process, but from the exec-ed ssh-keysign, which does one of the first things permanently_set_uid(pw). This call was there quite much ever since (2004) so I don't think it could be something that changed in OpenSSH. The problem is that ssh-keysign is a setgid binary, so it is already running as "ssh_keys" group, but RHEL6 and upstream is the root account and the binary is setuid. This was changed in RHEL7 to harden SSHD daemon. I can not find Fedora/RHEL bugs, but there is an upstream bug which was closed as wontfix even though it is in Fedora: https://bugzilla.mindrot.org/show_bug.cgi?id=1893 What I remember, this was the first and only issue with this change over the years. Workaround is probably to revert from setgit to setuid and some related downstream changes, but I am not sure if we want to go down this road at this moment. If this issue is critical or in any way time sensitive, please raise a ticket through the regular Red Hat support channels to ensure it receives the proper attention and prioritization to assure a timely resolution. For information on how to contact the Red Hat production support team, please visit: https://www.redhat.com/support/process/production/#howto
Thank you for your suggestion. But now I understand what caused this problem and how to get around it, so it's no longer emergency for me. I've decided to add setuid permission to the ssh-keysign binary, and that actually is preventing the problem. I don't know this method - to add setuid permission - should be best or not though, I'd like RHEL/Fedora or upstream to apply this or some other correction, or at least, to add some explanation to man or some document. because it's a bit confusing behavior that newgrp'ed ssh fails hostbased-auth while ssh which is not newgrp'ed succeeds.
Thank you for the confirmation that setuid bit helped. The setuid bit was there until RHEL6, so it should be quite safe to restore it in your case. I am not sure if we will be able to change this in RHEL7 timeframe (unless it shows as a bigger issue -- this is probably the first problem we found with this approach since 2011 [1]). This change was no significant security improvement and was never accepted in upstream openssh so I believe we could switch back in the next major release to avoid differences from upstream OpenSSH. Until that time, the easiest and probably best solution where to document this issue would be a Knowledge base on customer portal, which is written by the support guys and used by them and customers. They are usually created based on the customer issues so filling a ticket on customer portal would be the fastest way there. [1] https://src.fedoraproject.org/rpms/openssh/c/1ddd0ee5