LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-25-2006, 12:10 PM   #1
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
OpenSSH, authentication, PAM


I have a question on how OpenSSH interacts with PAM.

I setup sshd_config to allow PubkeyAuthentication but not PasswordAuthentication. My key was accepted for authentication. Then I renamed my ~/.ssh directory as a test. No key available now, but it prompted me for a password (???)

I figured this was PAM, not SSHD, so I removed "UsePAM yes" from sshd_config, retested, and this proved that it was indeed PAM triggering the password prompt.

But I noticed something unexpected during this testing. It appears that when SSHD accepted my key for authentication, it still called PAM if UsePAM was in effect. I was still seeing the MOTD, lastlogin, email check, etc. from PAM. But the authentication part from PAM - which should ask for a password per my /etc/pam.d/ssh configuration - was NOT used. So does OpenSSH somehow pass a message on to PAM saying that I had already been authenticated? I would have expected to have to authenticate TWICE - once with a key for SSHD, and once with a password for PAM.

I think I would prefer to turn off all authentication in OpenSSH (allow nothing) and defer to PAM to authenticate. But I can't find any pam_pubkey (or similar) module in PAM. Does that strike anyone else as an odd thing to be omitted?

I'm just learning PAM, so please excuse my newbie-ness here. It appears from my testing that there would be no way to require BOTH pubkey AND password authentication with OpenSSH/PAM. I'm not saying that this level of paranoia is required. The suggestion is more a mental exercise in configuration to learn how these two packages interact.
 
Old 03-27-2006, 11:10 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
(..) It appears that when SSHD accepted my key for authentication, it still called PAM if UsePAM was in effect. I was still seeing the MOTD, lastlogin, email check, etc. from PAM.
That's because of how a PAM stack works. On a regular PAM stack there's four module sections (authentication, account, password, session) that need to be worked through. AFAIK when UsePAM=no OpenSSH is expected to handle anything after authentication like session etc, etc checking itself else PAM will take care of it. BTW, note that PasswordAuthentication and UsePAM usage changes over releases: see "OpenSSH versions and PAM behaviour.": http://www.openssh.com/faq.html#3.15. (and one example where you would need UsePAM=yes is external auth like LDAP). BTW, have you tried UsePAM=no and renamed /etc/pam.d/sshd? Then it has no PAM stack config at all to interfere with tests (don't do that on a box you only have remote acess to).


But the authentication part from PAM - which should ask for a password per my /etc/pam.d/ssh configuration - was NOT used.
That's the wrong conclusion I think, because if I understand PAM, if a previous item in the same module section of the stack gets the auth done, the next item, when using args like use_authtok or use_first_pass or similar, will be just take the "OK" from the previous module and move on.


I would have expected to have to authenticate TWICE - once with a key for SSHD, and once with a password for PAM.
Try removing any args like use_authtok or use_first_pass or similar and try again, but again, don't do that on a box you only have remote acess to.


I think I would prefer to turn off all authentication in OpenSSH (allow nothing) and defer to PAM to authenticate.
I don't think that'll work and I don't see anything there that enhances the security posture of the service. If you have idea's otherwise I'd sure like to hear it.


I'm not saying that this level of paranoia is required.
I wouldn't either. There's enough established ways around to secure the service w/o having to resort to all kinds of hacks.
 
Old 03-27-2006, 11:48 AM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Original Poster
Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Thanks for the reply.
Quote:
But the authentication part from PAM - which should ask for a password per my /etc/pam.d/ssh configuration - was NOT used.
That's the wrong conclusion I think, because if I understand PAM, if a previous item in the same module section of the stack gets the auth done, the next item, when using args like use_authtok or use_first_pass or similar, will be just take the "OK" from the previous module and move on.
And this is exactly what is confusing me. There is no "previous module" that would have done the authentication in PAM. Nor any use_authtok or use_first_pass args in my setup. The authentication was pubkey, which PAM does not support as far as I can tell. So the authentication would have had to been done by sshd, not by a PAM module. So how would PAM have known that sshd already did the authentication? I know the PAM stack is being called, because I see the behavior triggered by the "session" directives (MOTD, email check, etc.) But I don't see the expected behavior from the "auth" directives. It's as if the "auth" part of the PAM stack was bypassed because sshd had already done the authentication. What I don't get is how this fact is communicated from sshd to PAM so PAM knows to skip the auth part.

Here are the auth directives from my ssh PAM stack:
Code:
auth       required     pam_nologin.so
auth       required     pam_env.so # [1]
@include common-auth
And common-auth looks like this:
Code:
auth    required        pam_unix.so nullok_secure
I don't know what that nullok_secure arg is. It doesn't seem to be documented anywhere I can find. This is PAM as default installed by Debian SID, so maybe it's some Debian-specific thing added by the developers. Maybe nullok_secure is my missing link between sshd and PAM???

Quote:
I think I would prefer to turn off all authentication in OpenSSH (allow nothing) and defer to PAM to authenticate.
I don't think that'll work and I don't see anything there that enhances the security posture of the service. If you have idea's otherwise I'd sure like to hear it.
No, I don't expect this would enhance security. If anything, it might provide some minor maintenance benefit. Namely, all authentication system-wide being done in one place - by PAM - and not by seperate applications like sshd. Of course, with no pubkey PAM module I'd be kind of stuck...

Thanks again for your reply!
 
Old 03-27-2006, 01:40 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
It's as if the "auth" part of the PAM stack was bypassed because sshd had already done the authentication.
That looks like a valid conclusion. I mean, why do password auth if ssh passphrase auth went OK?


What I don't get is how this fact is communicated from sshd to PAM so PAM knows to skip the auth part.
For that you'll have to read the PAM devel HOWTO and read the OpenSSH code (which is clean to read and not like a gazillion of lines).


I don't know what that nullok_secure arg is. It doesn't seem to be documented anywhere I can find.
Quote:
The nullok_secure option was added to support passwordless pam_unix logins only from ttys listed in /etc/securetty. It was added because nullok was not considered an appropriate option to configure for all services, but there was a need to support passwordless root logins on tty2 on newly installed Debian systems when base-config has not yet been run to configure a root password.

If anything, it might provide some minor maintenance benefit. Namely, all authentication system-wide being done in one place - by PAM - and not by seperate applications like sshd.
If it's only about centralising auth then I think you lose more than you gain, because I can't see how this would keep/make the system equally/more secure.

Last edited by unSpawn; 03-27-2006 at 02:43 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passwordless OpenSSH with MIT-Kerberos and PAM dbalsige Linux - Software 1 11-12-2009 12:12 PM
PAM Pop3 Authentication vijaykcm Linux - Security 3 12-27-2004 11:38 AM
Publickey authentication problem with OpenSSH Tularis Linux - Networking 2 03-17-2004 11:50 AM
openssh/PAM auth problem crippler909 Linux From Scratch 1 06-08-2003 11:51 AM
OpenSSH and PAM Authentication RyanP Linux - General 4 02-17-2001 12:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration