{"id":299,"date":"2009-10-09T23:27:06","date_gmt":"2009-10-09T23:27:06","guid":{"rendered":"https:\/\/www.bishnet.net\/tim\/blog\/?p=299"},"modified":"2010-11-11T13:01:22","modified_gmt":"2010-11-11T13:01:22","slug":"pam-locking-out-accounts-when-using-external-authentication","status":"publish","type":"post","link":"https:\/\/www.bishnet.net\/tim\/blog\/2009\/10\/09\/pam-locking-out-accounts-when-using-external-authentication\/","title":{"rendered":"PAM &#8211; Locking out accounts when using external authentication"},"content":{"rendered":"<p>One of the projects I&#8217;ve been working on lately has required me to investigate the way PAM handles external authentication. The setup is a bunch of different boxes running Solaris, Linux and FreeBSD, but all authenticating from a single central Kerberos domain. There&#8217;s also LDAP in the mix, but it&#8217;s not actually relevant, so I&#8217;ll ignore it for now.<\/p>\n<p>The problem comes when you want to lock out an account on a machine. By this, I mean the account still exists in the passwd file (for whatever reason, it needs to stay there) and the account still exists within the Kerberos domain because it can log on to other machines.<\/p>\n<p>What are the options? The PAM setup probably looks a little something like this:<\/p>\n<pre>auth    sufficient pam_krb5\r\nauth    required   pam_unix\r\n\r\naccount required   pam_krb5\r\naccount required   pam_unix<\/pre>\n<p>This setup allows the user to authenticate with just their Kerberos credential, but they must pass both modules in the account section (the pam_krb5 one here doesn&#8217;t do much though).<\/p>\n<p>So we can put whatever we want in the shadow password entry on the machine, it won&#8217;t affect the authentication &#8211; it never even gets there. But what about the account section? Can this do anything?<\/p>\n<p>After some investigation and source code checking I came up with the following:<\/p>\n<ul>\n<li>On Solaris one can put *LK* in the shadow password field. This causes the pam_unix module to reject the login in the account stage.<\/li>\n<li>On FreeBSD one can do the same as Solaris but with *LOCKED*.<\/li>\n<li>On Linux you can put what you want in the field but pam_unix won&#8217;t take any notice.<\/li>\n<\/ul>\n<p>If you&#8217;re thinking right now &#8220;hey, you can just put an exclamation mark in the shadow password field to lock the account out&#8221; you&#8217;re wrong. What this does on a standalone system is ensure that no possible password can decrypt to match this string which results in locking the account out. But, when we have external authentication it&#8217;s meaningless.<\/p>\n<p>So what&#8217;s the solution? There&#8217;s another field we can use &#8211; the shadow password expiry field. This is a time stamp in seconds since the epoch at which the password expires. The default setting of 0 means no expiry. Simply setting this to 1 (or any number smaller than now) results in the account being locked out. This seems like it&#8217;ll work across all three operating systems I&#8217;m testing, although I&#8217;m yet to finish my analysis.<\/p>\n<p>I am a little disappointed with the Linux PAM module. It&#8217;s a simple test to do, so I can&#8217;t see any reason why it shouldn&#8217;t be added.<\/p>\n<p><strong>Update 2nd November 2009:<\/strong><\/p>\n<p>I&#8217;ve since discovered that what I said above about the &#8220;default setting of 0 means no expiry&#8221; is incorrect. In fact, it varies on different operating systems. I got misled by the behaviour on Ubuntu 9.04 because of a Debian patch which made 0 mean no expiry, but which has been removed in Ubuntu 9.10 (details <a href=\"http:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi?bug=308229\">here<\/a>).<\/p>\n<p>Consequently my advice now is to set the shadow password expiry field to 1 to lock the account, and to unset it to unlock the account. This appears to work on all the operating systems I&#8217;ve tested it on.<\/p>\n<p>References:<\/p>\n<ul>\n<li><a href=\"http:\/\/pam.sourcearchive.com\/documentation\/1.0.1-5plus-plenny1\/pam__unix__acct_8c-source.html\">Linux PAM source code<\/a><\/li>\n<li><a href=\"http:\/\/src.opensolaris.org\/source\/xref\/onnv\/onnv-gate\/usr\/src\/lib\/pam_modules\/unix_account\/unix_acct.c#446\">OpenSolaris PAM source code<\/a><\/li>\n<li><a href=\"http:\/\/svn.freebsd.org\/viewvc\/base\/head\/lib\/libpam\/modules\/pam_unix\/pam_unix.c?revision=174837&amp;view=markup\">FreeBSD PAM source code<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A look at how PAM modules on different operating systems can be used to lock out accounts when an external authentication provider is used.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[115,7,114],"class_list":["post-299","post","type-post","status-publish","format-standard","hentry","category-computing","tag-authentication","tag-kerberos","tag-pam"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/comments?post=299"}],"version-history":[{"count":8,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/299\/revisions"}],"predecessor-version":[{"id":323,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/posts\/299\/revisions\/323"}],"wp:attachment":[{"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/media?parent=299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/categories?post=299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bishnet.net\/tim\/blog\/wp-json\/wp\/v2\/tags?post=299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}