[OpenAFS-devel] aklog on MacOS X was Re: Service Ticket Questions

Alexandra Ellwood lxs@MIT.EDU
Sat, 18 Mar 2006 13:28:56 -0500


On Mar 18, 2006, at 4:34 AM, emoy@apple.com wrote:

> On Mar 17, 2006, at 7:33 PM, Jeffrey Altman wrote:
>
>> I am cc'ing the openafs-devel@openafs.org mailing list because  
>> this is
>> really an OpenAFS discussion.  krbdev@mit.edu is meant to be a  
>> mailing
>> list focused on development of the MIT Kerberos reference
>> implementation.
>>
>> The fundamental issue being discussed here is whether the  
>> Kerberos.App
>> display of the Kerberos Credential Cache contents can be used as an
>> indication by end users that the AFS kernel module contains tokens  
>> for
>> that user.  Hank is claiming that presence of an "afs/cellname@REALM"
>> service ticket in the credential cache is an indicator that there are
>> AFS tokens installed in the AFS kernel module.
>>
>> I believe that end users should be discouraged from checking the
>> Kerberos credential cache to see if they have AFS tokens because  
>> doing
>> so is fundamentally flawed.  There are many reasons why tokens
>> might be
>> removed from the AFS kernel after their initial installation let  
>> alone
>> reasons why tokens might not be able to be stored in the first place.
>> Therefore, using the Kerberos credential cache as a replacement for
>> the
>> "tokens" command or a GUI token display will only make the lives of
>> end
>> users and those that support them more difficult.
>>
>> If there is a concern that the presence of the AFS service ticket  
>> will
>> be misinterpreted as meaning that tokens are present then perhaps the
>> thing to do is modify aklog and anything that derives from its code
>> base
>> to not use the default credential cache and instead use a local  
>> memory
>> cache.  We could make this the default behavior and allow the default
>> credential cache be used when "-d" is specified on the command  
>> line to
>> allow the presence of the service tickets to be used for debugging
>> purposes.
>
> One other place that the credential cache and the AFS token get out
> of sync is when trying to renew the TGT.  Renewal of the TGT and AFS
> token is a whole subject on its own, but suffice it to say that
> running "kinit -R" will renew the TGT, but remove the AFS service
> ticket, while the AFS token remains unchanged.

This is not an issue for the KLL loginLogout aklog plugin.  The KLL  
loginLogout plugins run whenever new tickets are acquired, including  
when renewal occurs.  All of this support works great except when  
Kerberos tickets are acquired during console login.

During console login the KLL is called by the Kerberos authplugin  
which is loaded by authorizationhost.  In Tiger authorizationhost  
runs as root or the securityagent user depending on whether  
",privileged" was specified in /etc/authorization.  The  
authorizationhost is spawned by the SecurityAgent and is not part of  
the chain of processes which will eventually be the user's login  
session.  Unfortunately AFS only associates tokens with a user by two  
mechanisms: magic entries in the user's group list or the user's  
uid.  Since the KLL loginLogout plugins have neither the user's uid  
or access to the user's group list, they cannot store AFS tokens  
properly during login.

Now I believe I asked Conrad Sauerwald to insert some code into the  
Kerberos authplugin which tries to work around this issue.  If  
",privileged" is specified and the authorizationhost is running as  
root, the plugin will try to call KLStoreNewInitialTicketCredentials 
() with its effective uid temporarily set to the user's effective  
uid.  Which means it might be possible to get the uid-based storage  
working so long as ",privileged" is specified.  Folks should  
definitely test this though because I haven't actually tried it since  
before Tiger shipped.

Note that specifying ",privileged" isn't a big deal because the KLL  
needs to run as root to read your /etc/krb5.keytab anyway.


The best way to solve this is to have AFS use the Mac OS X Security  
Session model for storing tokens so that it doesn't need to depend on  
either the user's uid or their group list.  This is what Kerberos  
uses for credentials and what most all of the keychain stuff uses.   
I'm not sure how much progress has been made, or if the functionality  
necessary to make this work for a kernel module is even present.  But  
really that's the right way to do it.


>> While not part of the same topic, Derrick Brashear spent time this
>> week
>> attempting to prepare a KFM KLL plug-in for aklog that would work on
>> Tiger and discovered that under Tiger we will not be able to provide
>> such functionality.   We will work with Apple to try to make this
>> happen
>> in a future release.  For those who are unaware, the KFM KLL plug-ins
>> have been used in previous releases of MacOS X to allow the Kerberos
>> initial ticket getting functionality to be extended such that
>> whenever a
>> new Kerberos 5 Initial Ticket is obtained a new AFS token would be
>> acquired at the same time.  Without this functionality it is not
>> possible to provide a single sign-on experience for AFS on Tiger.
>
> (Remember, I'm just a developer who happens to work at Apple; I don't
> speak for Apple.)
>
> It turns out I was working this week on something similar, a PAM
> module for aklog.  This is still highly experimental, but I have
> modified aklog to be more reentrant and embeddible, by converting all
> the global variables into fields of a structure.  I have add an
> additional routine that allocates such a structure, which is then
> passed to the aklog() routine.  So now, the main() routine of the
> aklog program calls alloc_aklog_globals() to get a block of memory,
> and passes that to the aklog() routine with the arguments.
>
> The PAM modules does the same thing.  There are some differences that
> are taken care of with a macro definition, like the fact that argv[0]
> is the name of the aklog program, but is the first real argument from
> the PAM modules.  Also, the aklog program exits on error; the PAM
> modules does a longjmp back to the aklog() routine to do an error
> return (because there is no exit, there might be some memory leaks or
> other cleanup that will need to be done).
>
> Creating a loadable PAM module did present some problem.  The LWP
> code uses assembly language (process.s for ppc and process.i386.s for
> x86), but that code references a global variable in way that would
> require a writable text segment.  So I added the usual assembly goop
> to move the relocation info to a data segment.  (I had tried to
> replace LWP with the pthread code, but was running into a bunch of
> undefined symbol problems, so I fell back to LWP.  I did notice four
> places that allocate pthread mutexes but don't initialize with
> PTHREAD_MUTEX_INITIALIZER as per POSIX, and would have made a
> difference on Mac OS X, since when uninitialized, it would reside in
> common segment, which is not allowed for a bundle.  Initializing it
> moves it into a data segment.)
>
> So I finally created the PAM module, which only does session open and
> close.  The open calls aklog to create the token.  The close does the
> equivalent of unlog, but I then commented that out, since I can
> imagine being logging into the GUI, when an ssh session comes in,
> renews the AFS token and then removes it on logout, leaving the GUI
> without a token.  Some mechanism for the last-one-out removing the
> token is needed.
>
> So fine, I have a PAM module, but so what?  Well, I also wrote a
> loginwindow "LoginHook", that is called loginwindow_pam_helper.  It
> gets run when loginwindow finishes authenticating (presuming /etc/
> authorization is set up to do Kerberos authentication).  It then does
> the usual PAM stuff to open a session and I set up the PAM config
> file to call my pam_aklog module.  In loginwindow_pam_helper, I use a
> kqueue to monitor when loginwindow terminates (usually when the user
> logs out, or if loginwindow dies) and then close the session.
>
> Well, this actually all works!  I log in, and my AFS tokens are
> there.  I can even set up a .xlog file and get tokens for multiple
> cells.
>
> Now I'm not saying this is the best approach.  My thinking was that a
> PAM module would be useful for other Unix platforms as well, but
> doesn't really fit in so nicely in Mac OS X.  The KFM might be a
> little cleaner, though Mac OS X specific.  But it might be possible
> to get loginwindow to do PAM directly, so my loginwindow_pam_helper
> wouldn't be needed anymore, and then the PAM module might fit in
> better (of course, I'm not on the loginwindow team, so I can't say
> they will make this change).
>
> Mac OS X also has it's own way of doing things, like the
> Authorization Services framework.  Now I'm a Unix guy, so the
> Authorization Services framework is new to me.  But it might also be
> feasible to put in aklog as a plug-in.  Then loginwindow could get to
> aklog through Authorization Services, and since there is already a
> pam_securityserver.so module that calls into the Authorization
> Services framework, things like ssh might also be able to get to
> aklog.  Again this is Mac OS specific, but could be the cleanest way
> for both Mac OS X applications and command-line programs to get aklog
> access.  And since aklog is embeddable, we could build the aklog
> program, the aklog PAM module, the aklog Authorization plug-in and
> possibly even the KFM KLL plug-in, all using the same base code.
>
> Anyways, Derrick, let me know if I can be of help with the KFM KLL
> plug-in (which is something else I don't know much about).


The problem with using a pam plugin is that it won't run every time  
new tickets are acquired.  The KLL loginLogout plugins even run when  
Kerberos.app is automatically renewing your tickets. It is this  
seamlessness which probably originally inspired Henry Hotz to want to  
use the presence of the afs service ticket to indicate that afs  
tokens had been acquired.  Now you could write a loginLogout plugin  
that calls pam modules, but that will just land you back at the  
problem I described above.

You can actually hinge successful Kerberos ticket acquisition on  
successful AFS token acquisition.  The loginLogout plugin API allows  
the plugin to cancel ticket acquisition if the plugin fails.  However  
this means that if you can't get AFS tokens, you also won't be able  
to get tickets -- probably not terribly useful unless you have an AFS  
home directory -- then no tokens really does mean you can't do anything.


As a side note the loginLogout plugins are called for all ticket  
acquistion.  So if the user has two identities such as user@REALM and  
user/admin@REALM, the plugin needs to be smart about how it gets  
tokens when the plugin is called for both of them.



--lxs

Alexandra Ellwood <lxs@mit.edu>
MIT Kerberos Development Team
<http://mit.edu/lxs/www>