<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Blog by Tim Bishop &#187; keytab</title>
	<atom:link href="http://www.bishnet.net/tim/blog/tag/keytab/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bishnet.net/tim/blog</link>
	<description>"For a moment, nothing happened. Then, after a second or so, nothing continued to happen." -- HHGTTG</description>
	<lastBuildDate>Mon, 02 Nov 2009 17:58:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Connecting to an LDAP server using Kerberos authentication in Perl</title>
		<link>http://www.bishnet.net/tim/blog/2008/01/18/connecting-to-ldap-using-kerberos-authentication-in-perl/</link>
		<comments>http://www.bishnet.net/tim/blog/2008/01/18/connecting-to-ldap-using-kerberos-authentication-in-perl/#comments</comments>
		<pubDate>Fri, 18 Jan 2008 10:44:10 +0000</pubDate>
		<dc:creator>Tim Bishop</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Auth::SASL]]></category>
		<category><![CDATA[Authen::Krb5::Easy]]></category>
		<category><![CDATA[GSSAPI]]></category>
		<category><![CDATA[Kerberos]]></category>
		<category><![CDATA[keytab]]></category>
		<category><![CDATA[KRB5CCNAME]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[Net::LDAP]]></category>

		<guid isPermaLink="false">http://www.bishnet.net/tim/blog/2008/01/18/connecting-to-ldap-using-kerberos-authentication-in-perl/</guid>
		<description><![CDATA[It took me a while to figure this code out, and there seemed to be a lack of complete examples on the web to do exactly this, so I thought I&#8217;d document it. I needed to connect to an LDAP server using a Kerberos principal for authentication from within a Perl script. This meant that [...]


Related posts:<ol><li><a href='http://www.bishnet.net/tim/blog/2009/10/09/pam-locking-out-accounts-when-using-external-authentication/' rel='bookmark' title='Permanent Link: PAM &#8211; Locking out accounts when using external authentication'>PAM &#8211; Locking out accounts when using external authentication</a></li>
<li><a href='http://www.bishnet.net/tim/blog/2006/09/01/a-new-server-and-a-new-raid-setup/' rel='bookmark' title='Permanent Link: A new server and a new RAID setup'>A new server and a new RAID setup</a></li>
<li><a href='http://www.bishnet.net/tim/blog/2008/06/19/ill-build-a-new-server-its-got-to-be-easier-than-patching-up-the-old-one/' rel='bookmark' title='Permanent Link: &#8220;I&#8217;ll build a new server; it&#8217;s got to be easier than patching up the old one&#8230;&#8221;'>&#8220;I&#8217;ll build a new server; it&#8217;s got to be easier than patching up the old one&#8230;&#8221;</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>It took me a while to figure this code out, and there seemed to be a lack of complete examples on the web to do exactly this, so I thought I&#8217;d document it.</p>
<p>I needed to connect to an LDAP server using a Kerberos principal for authentication from within a Perl script. This meant that it needed to do it without any external input, so it couldn&#8217;t rely on a password being entered or someone doing a kinit first.</p>
<p>The code is fairly simple. It basically gets the right credentials using a pre-initialised keytab and then sets up the relevant objects and uses them to bind to an LDAP server.</p>
<blockquote>
<pre>#!/usr/local/bin/perl -w    

# How to connect to an LDAP server using GSSAPI Kerberos auth.    

use strict;    

use Net::LDAP;
use Authen::SASL qw(Perl);
# This module makes doing the kinit much easier
use Authen::Krb5::Easy qw(kinit kdestroy kerror);    

# Location of the keytab which contains testuser's key
# exported in kadmin by: ktadd -k /tmp/test.keytab testuser
my $keytab = '/tmp/test.keytab';
# Where to store the credentials
my $ccache = '/tmp/test.ccache';    

$ENV{KRB5CCNAME} = $ccache;    

# Get credentials for testuser
kinit($keytab, 'testuser@CS.UKC.AC.UK') || die kerror();    

# Set up a SASL object
my $sasl = Authen::SASL-&gt;new(mechanism =&gt; 'GSSAPI') || die "$@";    

# Set up an LDAP connection
my $ldap = Net::LDAP-&gt;new('ldap.cs.kent.ac.uk') || die "$@";    

# Finally bind to LDAP using our SASL object
my $mesg = $ldap-&gt;bind(sasl =&gt; $sasl);    

# This should say "0 (Success)" if it worked
print "Message is ". $mesg-&gt;code ." (". $mesg-&gt;error .").\n";    

# Clear up the credentials
kdestroy();</pre>
</blockquote>
<p>Hopefully this will help someone else out. Comments welcome <img src='http://www.bishnet.net/tim/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bishnet.net/tim/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>Related posts:<ol><li><a href='http://www.bishnet.net/tim/blog/2009/10/09/pam-locking-out-accounts-when-using-external-authentication/' rel='bookmark' title='Permanent Link: PAM &#8211; Locking out accounts when using external authentication'>PAM &#8211; Locking out accounts when using external authentication</a></li>
<li><a href='http://www.bishnet.net/tim/blog/2006/09/01/a-new-server-and-a-new-raid-setup/' rel='bookmark' title='Permanent Link: A new server and a new RAID setup'>A new server and a new RAID setup</a></li>
<li><a href='http://www.bishnet.net/tim/blog/2008/06/19/ill-build-a-new-server-its-got-to-be-easier-than-patching-up-the-old-one/' rel='bookmark' title='Permanent Link: &#8220;I&#8217;ll build a new server; it&#8217;s got to be easier than patching up the old one&#8230;&#8221;'>&#8220;I&#8217;ll build a new server; it&#8217;s got to be easier than patching up the old one&#8230;&#8221;</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.bishnet.net/tim/blog/2008/01/18/connecting-to-ldap-using-kerberos-authentication-in-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
