Microsoft KB Archive/319723

= How to use Kerberos authentication in SQL Server =

Article ID: 319723

Article Last Modified on 12/3/2007

-

APPLIES TO

 Microsoft SQL Server 2000 Standard Edition, when used with:  Microsoft Windows 2000 Advanced Server

 Microsoft Windows 2000 Service Pack 3

 Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)

 Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)</li></ul> </li> Microsoft SQL Server 2005 Standard Edition</li> Microsoft SQL Server 2005 Developer Edition</li> Microsoft SQL Server 2005 Enterprise Edition</li> Microsoft SQL Server 2005 Express Edition</li> Microsoft SQL Server 2005 Workgroup Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q319723

<div class="summary_section">

SUMMARY
You can use Kerberos authentication with Microsoft SQL Server 2000. SQL Server 2000 supports this functionality as part of a typical Microsoft Windows 2000 or Microsoft Windows Server 2003 Active Directory domain installation. With Microsoft Windows 2000 Service Pack 3 (SP3) and Windows Server 2003, you can enable Kerberos authentication on server clusters.

For more information about this added functionality, click the following article number to view the article in the Microsoft Knowledge Base:

235529 Kerberos support on Windows 2000-based server clusters

Note You can only use this functionality if you are running Windows 2000 SP3 or Windows Server 2003.

SQL Server 2000 failover clustering also uses this functionality. When the Network Name resource that SQL Server is dependent on is in a Windows 2000-based cluster, you can use Kerberos authentication on the resource after you upgrade the computer to Windows 2000 SP3 or to Windows Server 2003. To install SQL Server failover clustering, you must have Microsoft SQL Server 2000 Enterprise Edition or Developer Edition installed.

Note The concepts and discussions in this article that apply to SQL Server 2000 also apply to SQL Server 2005. For more information about this subject in SQL Server 2005, see the following topics in SQL Server 2005 Books Online:
 * How to: Enable Kerberos Authentication Including SQL Server Virtual Servers on Server Clusters
 * Registration of Service Principal Name

For more information about how to make sure that you are using Kerberos authentication in SQL Server 2005, click the following article number to view the article in the Microsoft Knowledge Base:

909801 How to make sure that you are using Kerberos authentication when you create a remote connection to an instance of SQL Server 2005

<div class="moreinformation_section">

MORE INFORMATION
SQL Server can use Kerberos authentication for server clusters. You can use Kerberos authentication with stand-alone computers that are running SQL Server, or with instances of SQL Server that are running on a virtual server.

Connect to a server that is running Microsoft Internet Information Services and make a Kerberos connection to SQL Server 2000
This section describes how to connect to a server that is running Microsoft Internet Information Services (IIS) to make a Kerberos connection to a server that is running SQL Server.'''

Note''' Before you perform the setup procedure, download the Kerbtray and the SetSPN utilities.

To download the Kerbtray utility, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?FamilyID=4e3a58be-29f6-49f6-85be-e866af8e7a88&displaylang=en

With Kerbtray.exe, you can easily verify or remove (or both) Kerberos tickets from any of the associated computers that are being used.

To download the SetSPN utility, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?FamilyID=5fd831fd-ab77-46a3-9cfe-ff01d29e5c46&displaylang=en

The following procedure provides an example of a setup sequence where you use Kerberos authentication through an IIS page to access a server that is running SQL Server.

Step 1: Configure the domain controller
On a domain controller, in Active Directory Users and Computers: <ol> Right-click the computer that you want to set up for delegation (IIS Services server), and then click to select Trust this computer for delegation. If the computer that is running SQL Server is what appears to be the last computer contacted but that computer has a linked server, it must also granted delegation permissions. If it is not the last computer in the chain, all the computers that are intermediaries must be trusted for delegation.</li> Grant delegation permission to the SQL Server service account domain user account. You must have a domain user account for clustered SQL Server installations (this step is not required for computers that are running SQL Server that are using a local system account): <ol style="list-style-type: lower-alpha;"> In the Users folder, right-click the user account, and then click Properties.</li> In the user account properties dialog box, click the Account tab.</li> Under Account Options, click to select the Account is Trusted for Delegation check box. Make sure that the Account is sensitive and cannot be delegated check box is cleared for this account.</li></ol>

Note These steps apply only to Windows 2000 Server. If you are using Windows Server 2003, visit the following Microsoft Developer Network (MSDN) Web site:

http://technet2.microsoft.com/windowsserver/en/library/bef202b0-c8e9-4999-9af7-f56b991a4fd41033.mspx

</li> Use the Kerbtray.exe utility to verify that Kerberos tickets were received from the domain controller and host: <ol style="list-style-type: lower-alpha;"> Right-click the Kerbtray icon in the notification area, and then click purge tickets.</li> Wait for the green Kerbtray icon to change from green to yellow. As soon as this occurs, open a command prompt window and run this command:

net session * /d

This will drop the existing sessions, and force a new session to be established and a Kerberos ticket received.</li></ol> </li></ol>

Step 2: Configure the IIS services server
<ol> Replace the default Web site Wwwroot files with the sample .asp files. To create the sample .asp files, use the code that is provided in the &quot;ASP test script for SQL Server data retrieval&quot; section.</li> Add the file to the Wwwroot folder. To do so, use the sample code in the &quot;ASP Test Script for SQL Server Data Retrieval&quot; section. Save the file as Default.asp.</li> Re-configure the Web server to use Integrated Windows Authentication only: <ol style="list-style-type: lower-alpha;"> <li>Right-click the default Web server, and then click the Security folder.</li> <li>In the Security folder, make the correct changes, and then click to clear anonymous access.</li> <li> From a command prompt, run this command:

cscript C:\Inetpub\Adminscripts\adsutil.vbs get w3svc/NTAuthenticationProviders

If Negotiate is enabled, the following is returned: <pre class="fixed_text"> NTAuthenticationProviders : (STRING) Negotiate,NTLM For more information, click the following article number to view the article in the Microsoft Knowledge Base:

215383 How to configure IIS to support both the Kerberos protocol and the NTLM protocol for network authentication

</li></ol>

Notes <ul> <li>You must install Microsoft Data Access (MDAC) 2.6, or later, on the IIS Services server. To do so (and to make the tools available for testing), install the SQL Server 2000 client tools to the Web server. To install only MDAC 2.6, or later (without installing the client tools), visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/data/aa937730.aspx

</li> <li>IIS is a common middle tier system. However, IIS is not the only middle tier system. If IIS is not the middle tier system in your environment, follow the appropriate steps for your middle tier system.</li></ul> </li> <li>Verify that the  value is present in the registry. If the value is not displayed, add it as .</li> <li>Use the Kerbtray.exe utility to verify that Kerberos tickets were received from the domain controller and host: <ol style="list-style-type: lower-alpha;"> <li>Right-click the Kerbtray icon in the notification area, and then click purge tickets.</li> <li>Wait for the green Kerbtray icon to change from green to yellow. As soon as this occurs, open a command prompt window and run this command:

net session * /d

This will drop the existing sessions, and force a new session to be established and a Kerberos ticket received.</li></ol> </li></ol>

Step 3: Configure the SQL Server service to create SPNs dynamically
To do this, you must grant the following access control settings for the SQL Server service account in the Active Directory directory service:
 * Read servicePrincipalName
 * Write servicePrincipalName

Warnings
 * If you use the Active Directory Service Interfaces (ADSI) Edit snap-in, the LDP utility, or the LDAP 3 clients and you incorrectly modify the attributes of Active Directory objects, serious problems occur. To resolve these problems, you may have to reinstall Microsoft Exchange 2000 Server or Microsoft Exchange Server 2003. In some cases, you may have to reinstall Microsoft Windows 2000 Server or Microsoft Windows Server 2003 and then reinstall Exchange 2000 Server or Exchange Server 2003. We cannot guarantee that these problems can be resolved. Modify these attributes at your own risk.
 * You must be logged on as a domain administrator. Alternatively, you must ask your domain administrator to grant the appropriate permissions and the appropriate user rights to the SQL Server startup account.

To configure the SQL Server service to create SPNs dynamically when the SQL Server service starts, follow these steps: <ol> <li>Click Start, click Run, type Adsiedit.msc, and then click OK.

Note The ADSIEdit tool is included in the Windows Support Tools. To obtain the Windows Support Tools, visit the following Microsoft Web site:

http://www.microsoft.com/downloads/details.aspx?familyid=6EC50B78-8BE1-4E81-B3BE-4E7AC4F0912D&displaylang=en

</li> <li>In the ADSI Edit snap-in, expand Domain [ ], expand DC= , expand CN=Users, right-click CN=  , and then click Properties.

Notes <ul> <li> is a placeholder for the name of the domain.</li> <li> is a placeholder for the name of the root domain.</li> <li> is a placeholder for the account that you specify to start the SQL Server service.</li> <li>If you specify the Local System account to start the SQL Server service,  is a placeholder for the account that you use to log on to Microsoft Windows.</li> <li>If you specify a domain user account to start the SQL Server service,  is a placeholder for the domain user account.</li></ul> </li> <li>In the CN=  Properties dialog box, click the Security tab.</li> <li>On the Security tab, click Advanced.</li> <li>In the Advanced Security Settings dialog box, make sure that SELF is listed under Permission entries.

If SELF is not listed, click Add, and then add SELF.</li> <li>Under Permission entries, click SELF, and then click Edit.</li> <li>In the Permission Entry dialog box, click the Properties tab.</li> <li>On the Properties tab, click This object only in the Apply onto list, and then click to select the check boxes for the following permissions under Permissions: <ul> <li>Read servicePrincipalName</li> <li>Write servicePrincipalName</li></ul> </li> <li>Click OK two times.

Note For help with this process, contact Active Directory product support, and mention this Microsoft Knowledge Base article.</li> <li>In the CN=  Properties dialog box, click Attribute Editor.</li> <li>Under Attributes, click servicePrincipalName in the Attribute column, and then click Edit.</li> <li>In the Multi-valued String Editor dialog box, remove the service principle names (SPNs) for the instances of SQL Server that use this SQL Server service account.

Warning You should only delete the SPNs for the instances of SQL Server that you are currently working on. The other instances of SQL Server that use this service account will be able to remove the SPNs that are related to these instances the next time that you start these instances.</li> <li>Exit the ADSI Edit snap-in.</li></ol>

After you follow these steps, SPN issues are also eliminated if you change the TCP/IP port or the domain name for new installations of SQL Server 2005 or for existing instances of SQL Server 2005.

Step 4: Configure the client computers
<ol> <li>For each client that will connect, verify that Microsoft Internet Explorer is configured to use Windows authentication: <ol style="list-style-type: lower-alpha;"> <li>In Internet Explorer, on the Tools menu, click Internet Options.</li> <li>Click the Advanced tab.</li> <li>Under Security, click to select Enable Integrated Windows Authentication (requires restart), and then click OK.</li></ol> </li></ol>

Step 5: Test the configuration
For each computer that is involved:
 * 1) Log on to the computer, and then use Kerbtray.exe to verify that the computer can obtain a valid Kerberos ticket from the domain controller.
 * 2) Use Kerbtray.exe to remove all tickets on the computer.
 * 3) Create and connect to the Web page that returns the SQL Server data.

Note Replace  with the name of the computer that is running SQL Server:
 * 1) * If data is returned, this page displays the authentication type Negotiate, and the SQL Server data for the result of the sp_helpdb stored procedure that should return a list of the databases on the server that is being connecting to through the .ASP page.
 * 2) * If you have auditing turned on in SQL Server, in the Application log you will see that the connection is &quot;trusted&quot;.

ASP test script for SQL Server data retrieval
Here is an ASP test script for SQL Server data. If you use this code sample, make sure that you replace  with the name of the computer that is running SQL Server. <%@ Language=VBScript %> <HTML> <HEAD> <META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;> </HEAD> <BODY> <%=&quot;'auth_user' is&quot; & request.servervariables(&quot;auth_user&quot;)%> <P> <%=&quot;'auth_type' is&quot; & request.servervariables(&quot;auth_type&quot;)%> <P> Connections string is <B>&quot; Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=SQLSERVERNAME </B> <P> <%   set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;) set cn = Server.CreateObject(&quot;ADODB.Connection&quot;) cn.Open &quot;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=SQLSERVERNAME&quot; rs.open &quot;MASTER..sp_helpdb&quot;,cn Response.Write cstr(rs.Fields.Count) +&quot;<BR>&quot; while not rs.EOF Response.Write cstr(rs(0))+&quot;<BR>&quot; rs.MoveNext wend rs.Close cn.Close set rs = nothing ' Frees memory reserved by the recordset. set cn = nothing ' Frees memory reserved by the connection. %> </BODY> </HTML>

How to gather a list of Active Directory server principle name information
To gather a list of Active Directory server principal name (SPN) information, type the following command on one of your domain controllers, where  is the NetBIOS domain name and   is the name of the output file that you will use to port the results. If you do not use a full path, the file is placed in the current folder where you run the command line. This sample command queries the whole domain: 

ldifde -d &quot;CN=Users,DC= &quot; -l servicePrincipalName -F .txt

This syntax creates a file named NewoutputUsers.txt that contains information that is similar to the output in the &quot;Domain level output of NewouputUsers.txt&quot; section in this article.

This output may be overwhelming when you gather it for a whole domain. Therefore, to limit the gathered information to a specific user name, use the following syntax, where  is the user name and   is the domain that you are querying:

ldifde -d &quot;CN= ,DC= &quot; -l servicePrincipalName -F .txt

Gathering the information for a specific user greatly reduces the data that you must search through. If you gather the information for a whole domain, search for the specific user name of the server in question. In the output sample, you see:
 * Entries for servers that no longer exist, but that were not completely removed from Active Directory.
 * The user &quot; &quot; has valid SPN information about ten different servers.

Additionally, you can use the Active Directory Service Interfaces (ADSI) tool to correct Active Directory entries that are not valid.

Warning If you use the ADSI Edit snap-in, the LDP utility, or any other LDAP version 3 client, and you incorrectly modify the attributes of Active Directory objects, you can cause serious problems. These problems may require you to reinstall Microsoft Windows 2000 Server, Microsoft Windows Server 2003, Microsoft Exchange 2000 Server, Microsoft Exchange Server 2003, or both Windows and Exchange. Microsoft cannot guarantee that problems that occur if you incorrectly modify Active Directory object attributes can be solved. Modify these attributes at your own risk.

Domain level output of NewouputUsers.txt
dn: CN=User Name,CN=Users,DC=betaland changetype: add servicePrincipalName: MSSQLSvc/CLUSTERDEFAULT.betaland:1257 servicePrincipalName: MSSQLSvc/INST3.betaland:3616 servicePrincipalName: MSSQLSvc/INST2.betaland:3490 servicePrincipalName: MSSQLSvc/SQLMAN.betaland:1433 servicePrincipalName: MSSQLSvc/VSS1.betaland:1433 servicePrincipalName: MSSQLSvc/INST1.betaland:2536 servicePrincipalName: MSSQLSvc/INST4.betaland:3967 servicePrincipalName: MSSQLSvc/SQLVIRTUAL1.betaland:1434 servicePrincipalName: MSSQLSvc/SQLVIRTUAL.betaland:1433 servicePrincipalName: MSSQLSvc/SQLBUSTER.betaland:1315

<div class="references_section">