{"id":2833,"date":"2016-03-28T21:43:06","date_gmt":"2016-03-29T01:43:06","guid":{"rendered":"http:\/\/microdevsys.com\/wp\/?p=2833"},"modified":"2016-05-29T15:06:04","modified_gmt":"2016-05-29T19:06:04","slug":"passless-keys-ssh-does-not-work-when-home-folder-is-an-nfs-mount","status":"publish","type":"post","link":"https:\/\/microdevsys.com\/wp\/passless-keys-ssh-does-not-work-when-home-folder-is-an-nfs-mount\/","title":{"rendered":"Passless keys ssh does not work when home folder is an NFS mount."},"content":{"rendered":"<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tOn this CentOS 7 (both worker and controller), we cannot ssh using pass less keys from the controller <strong>opennebula01<\/strong> to the worker <strong>mdskvm-p01<\/strong> when the NFS share (&nbsp;<strong>192.168.0.70:\/var\/lib\/one \/var\/lib\/one<\/strong>) is mounted on the worker. But I can as soon as I unmount the <strong>opennebula01 <\/strong>NFS share off of the worker node <strong>mdskvm-p01<\/strong>. When the <strong>NFS<\/strong> is mounted, both worker and controller share a common <strong>\/var\/lib\/one\/.ssh\/authorized_keys<\/strong> file, which seems to be the intent of the setup:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">[oneadmin@mdskvm-p01 .ssh]$ mount|tail -n 1<br \/>\n\t192.168.0.70:\/var\/lib\/one on \/var\/lib\/one type nfs4 (rw,relatime,vers=4.0,rsize=8192,wsize=8192,namlen=255,soft,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.0.60,local_lock=none,addr=192.168.0.70)<br \/>\n\t[oneadmin@mdskvm-p01 .ssh]$ pwd<br \/>\n\t\/var\/lib\/one\/.ssh<br \/>\n\t[oneadmin@mdskvm-p01 .ssh]$<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tNow when I run SSHD in debug mode using port 2222, the passless key works fine with or without NFS mounted on the worker node. Why?\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tIs there a specific sshd config file entry that prevents passless key login if sshd is not running in debug mode or when the OpenNebula NFS share is mounted? Again, in debug, SSHD works fine with or without the NFS mount on the worker mdskvm-p01. &nbsp;To answer these questions we will run through some checks:\n<\/p>\n<p>\n\t<!--more-->\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tFirst ensure that the <strong>known_hosts<\/strong> file and <strong>authorized_keys <\/strong>file is set to 600. Second, we can run ssh in debug mode, both on when we ssh to the target and on the target we can set the ssh daemon into debug mode like this:\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">(server) \/usr\/sbin\/sshd -p 2222 -D -dddd -e&nbsp;<br \/>\n\t(client)&nbsp;ssh mdskvm-p01 -p 2222<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tThis can point to an easily identifyable issue that is easy to fix, and usualy does if it&#39;s something configuration related. &nbsp;For further digging we can also run tail -f \/var\/log\/secure to see additional details. &nbsp;However, in case this doesn&#39;t help, the other area to look at is the SELinux policy. &nbsp;One thing we did NOT do is disable SELinux on the OpenNebula nodes like the OpenNebula Document pages&nbsp;suggest. &nbsp;However we will try to work around this issue by working with SELinux rather then disabling it. &nbsp;This is a safer approach however you may find yourself in a position to tweak SELinux rules for every small action OpenNebula takes. &nbsp;Sure enough, checking the \/var\/log\/audit\/audit.log file yields these messages:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">type=AVC msg=audit(1459215027.430:35013): avc: &nbsp;denied &nbsp;{ read } for &nbsp;pid=4345 comm=&quot;sshd&quot; name=&quot;authorized_keys&quot; dev=&quot;0:41&quot; ino=68066706 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 t<strong><span style=\"color:#008000;\">context=system_u:object_r:nfs_t:s0<\/span><\/strong> tclass=file<br \/>\n\ttype=SYSCALL msg=audit(1459215027.430:35013): arch=c000003e syscall=2 success=no exit=-13 a0=7f9946d498a0 a1=800 a2=1 a3=7f9941c912e0 items=0 ppid=24665 pid=4345 auid=4294967295 uid=0 gid=0 euid=9869 suid=0 fsuid=9869 egid=9869 sgid=0 fsgid=9869 tty=(none) ses=4294967295 comm=&quot;sshd&quot; exe=&quot;\/usr\/sbin\/sshd&quot; subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 key=(null)<br \/>\n\ttype=USER_AUTH msg=audit(1459215027.433:35014): pid=4345 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:sshd_t:s0-s0:c0.c1023 msg=&#39;op=pubkey acct=&quot;oneadmin&quot; exe=&quot;\/usr\/sbin\/sshd&quot; hostname=? addr=192.168.0.70 terminal=ssh res=failed&#39;<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tWhat we need is the item in green above. &nbsp;The reason why this happens is because we have NFS mounted <strong>\/var\/lib\/one<\/strong> folder meaning <strong>NFS SELinux<\/strong> policies need to be adjusted. &nbsp;We can also use <strong>aureport -a<\/strong> and&nbsp;<strong>ausearch -a &lt;NUM&gt;<\/strong>&nbsp;or <strong>audit2why<\/strong> or <strong>audit2allow <\/strong>etc from first command,&nbsp;to get similar details. &nbsp;This doesn&#39;t happen when NFS home folders are&nbsp;not mounted. &nbsp;Now borrowing slightly off of our <a href=\"http:\/\/microdevsys.com\/wp\/chcon-failed-to-change-context-of-operation-not-supported\/\" rel=\"external nofollow\">earlier post on a similar NFS<\/a> issue, we check the permissions on the folder and set the context accordingly:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">[root@mdskvm-p01 ~]# &nbsp;ls -lda &#8211;author -Z \/var\/lib\/one<br \/>\n\tdrwxr-x&#8212;. oneadmin oneadmin system_u:object_r:nfs_t:s0 &nbsp; &nbsp; &nbsp; \/var\/lib\/one<br \/>\n\t[root@mdskvm-p01 ~]#<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tNow to install<strong> audit2why<\/strong> and friends, type this:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">yum install policycoreutils-python<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tAnd this gets you:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\">[root@mdskvm-p01 ~]# rpm -ql policycoreutils-python|grep -i bin<br \/>\n\t\/usr\/bin\/audit2allow<br \/>\n\t\/usr\/bin\/audit2why<br \/>\n\t\/usr\/bin\/chcat<br \/>\n\t\/usr\/bin\/sandbox<br \/>\n\t\/usr\/bin\/semodule_package<br \/>\n\t\/usr\/sbin\/semanage<br \/>\n\t[root@mdskvm-p01 ~]#<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tNow executing the audit2why yeilds the answer we were looking for:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\"><strong>grep ssh \/var\/log\/audit\/audit.log | audit2why -w<\/strong><br \/>\n\t<span style=\"color: rgb(51, 51, 51); line-height: 1.6em;\">type=AVC msg=audit(1459235024.202:33774): avc: &nbsp;denied &nbsp;{ read open } for &nbsp;pid=26163 comm=&quot;sshd&quot; path=&quot;\/var\/lib\/one\/.ssh\/authorized_keys&quot; dev=&quot;0:41&quot; ino=68066706 scontext=system_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:nfs_t:s0 tclass=file<\/span><\/span><\/span>\n<\/p>\n<p style=\"margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">&nbsp; &nbsp; &nbsp; &nbsp; Was caused by:<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; The boolean use_nfs_home_dirs was set incorrectly.<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; Description:<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; Allow use to nfs home dirs<\/span><\/span>\n<\/p>\n<p style=\"margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">&nbsp; &nbsp; &nbsp; &nbsp; Allow access by executing:<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; # setsebool -P use_nfs_home_dirs 1<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tSo in this case, we will try the first option and&nbsp;mount the NFS mount differently, by adding in a context to it:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\"><strong>[root@mdskvm-p01 ~]# grep context \/etc\/fstab<\/strong><br \/>\n\t192.168.0.70:\/var\/lib\/one\/ &nbsp; &nbsp; &nbsp;\/var\/lib\/one\/ &nbsp;nfs &nbsp; context=system_u:object_r:nfs_t:s0,soft,intr,rsize=8192,wsize=8192,noauto<br \/>\n\t[root@mdskvm-p01 ~]#<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\">And sure enough, we get a mount:<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\">[root@mdskvm-p01 ~]# mount \/var\/lib\/one<br \/>\n\t[root@mdskvm-p01 ~]#<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tBut that didn&#39;t work either so we run the recommended command above:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\"><strong>[root@mdskvm-p01 ~]# setsebool -P use_nfs_home_dirs 1<\/strong><br \/>\n\t[root@mdskvm-p01 ~]#<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tAnd try to mount:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-family:courier new,courier,monospace;\"><strong>[oneadmin@opennebula01 .ssh]$ ssh mdskvm-p01<\/strong><br \/>\n\tWarning: Permanently added &#39;mdskvm-p01,192.168.0.60&#39; (ECDSA) to the list of known hosts.<br \/>\n\tLast failed login: Tue Mar 29 03:03:45 EDT 2016 from opennebula01 on ssh:notty<br \/>\n\tThere were 2 failed login attempts since the last successful login.<br \/>\n\tLast login: Tue Mar 29 02:54:54 2016 from opennebula01<br \/>\n\t[oneadmin@mdskvm-p01 ~]$<\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\t<strong>SUCCESS!! <\/strong>&nbsp;Now if you add the wrong context, this can happen:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">[root@mdskvm-p01 ~]# mount \/var\/lib\/one<br \/>\n\tmount.nfs: access denied by server while mounting 192.168.0.70:\/var\/lib\/one\/<br \/>\n\t[root@mdskvm-p01 ~]#<br \/>\n\t[root@mdskvm-p01 ~]#<br \/>\n\t[root@mdskvm-p01 ~]#<br \/>\n\t<strong>[root@mdskvm-p01 ~]# grep 192.168.0.70 \/etc\/fstab<\/strong><br \/>\n\t192.168.0.70:\/var\/lib\/one\/ &nbsp; &nbsp; &nbsp;\/var\/lib\/one\/ &nbsp;nfs &nbsp; context=system_u:system_r:sshd_t:s0,soft,intr,rsize=8192,wsize=8192,noauto<br \/>\n\t[root@mdskvm-p01 ~]#<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tHowever, we get this problem now:\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin-left: 40px;\">\n\t<span style=\"font-size:14px;\"><span style=\"font-family:courier new,courier,monospace;\">type=AVC msg=audit(1459218411.696:37452): avc: &nbsp;denied &nbsp;{ relabelto } for &nbsp;pid=25792 comm=&quot;mount.nfs&quot; scontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tcontext=system_u:system_r:sshd_t:s0 tclass=filesystem<br \/>\n\ttype=SYSCALL msg=audit(1459218411.696:37452): arch=c000003e syscall=165 success=no exit=-13 a0=7f9b20242ff0 a1=7f9b20243e70 a2=7f9b20243e90 a3=0 items=0 ppid=25791 pid=25792 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=95 comm=&quot;mount.nfs&quot; exe=&quot;\/usr\/sbin\/mount.nfs&quot; subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)<\/span><\/span>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tAnd we&#39;ll leave that for another article. &nbsp;It was the first context that we needed. &nbsp;<img loading=\"lazy\" decoding=\"async\" alt=\"wink\" height=\"20\" src=\"http:\/\/microdevsys.com\/wp\/wp-content\/plugins\/ckeditor-for-wordpress\/ckeditor\/plugins\/smiley\/images\/wink_smile.gif\" title=\"wink\" width=\"20\" \/>\n<\/p>\n<p style=\"color: rgb(34, 34, 34); font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px;\">\n\tCheers,<br \/>\n\tTK<\/p>\n\n    <div class=\"xs_social_share_widget xs_share_url after_content \t\tmain_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content\">\n\n\t\t\n        <ul>\n\t\t\t        <\/ul>\n    <\/div> \n","protected":false},"excerpt":{"rendered":"<p>On this CentOS 7 (both worker and controller), we cannot ssh using pass less keys from the controller opennebula01 to the worker mdskvm-p01 when the NFS share (&nbsp;192.168.0.70:\/var\/lib\/one \/var\/lib\/one) is mounted on the worker. But I can as soon as I unmount the opennebula01 NFS share off of the worker node mdskvm-p01. When the NFS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2833","post","type-post","status-publish","format-standard","hentry","category-unix-linux-admin-stuff"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/posts\/2833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/comments?post=2833"}],"version-history":[{"count":5,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/posts\/2833\/revisions"}],"predecessor-version":[{"id":3116,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/posts\/2833\/revisions\/3116"}],"wp:attachment":[{"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/media?parent=2833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/categories?post=2833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microdevsys.com\/wp\/wp-json\/wp\/v2\/tags?post=2833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}