How to use Kerberos authentication in SQL Server (319723)



The information in this article applies to:

  • Microsoft SQL Server 2000 (all editions), when used with:
    • Microsoft Windows 2000 Advanced Server SP3
    • Microsoft Windows 2000 Datacenter Server SP3
    • Microsoft Windows Server 2003, Enterprise Edition
    • Microsoft Windows Server 2003, Datacenter Edition
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup

This article was previously published under Q319723

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

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: 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:

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:
  1. 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.
  2. 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):
    1. In the Users folder, right-click the user account, and then click Properties.
    2. In the user account properties dialog box, click the Account tab.
    3. 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.
    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:
  3. Use the Kerbtray.exe utility to verify that Kerberos tickets were received from the domain controller and host:
    1. Right-click the Kerbtray icon in the notification area, and then click purge tickets.
    2. 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.

Step 2: Configure the IIS services server

  1. 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 "ASP test script for SQL Server data retrieval" section.
  2. Add the file to the Wwwroot folder. To do so, use the sample code in the "ASP Test Script for SQL Server Data Retrieval" section. Save the file as Default.asp.
  3. Re-configure the Web server to use Integrated Windows Authentication only:
    1. Right-click the default Web server, and then click the Security folder.
    2. In the Security folder, make the correct changes, and then click to clear anonymous access.
    3. From a command prompt, run this command:

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

      If Negotiate is enabled, the following is returned:
       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

    Note 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:
  4. Verify that the HKLM\SW\MS\MSSQLSERVER\Client\DSQUERY value is present in the registry. If the value is not displayed, add it as DSQUERY:Reg_SZ:DBNETLIB.
  5. Use the Kerbtray.exe utility to verify that Kerberos tickets were received from the domain controller and host:
    1. Right-click the Kerbtray icon in the notification area, and then click purge tickets.
    2. 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.

Step 3: Create an SPN for SQL Server

Warning SQL Server only uses Kerberos if the client uses the TCP/IP protocol to connect to SQL Server. For example, if a client uses the Named Pipes protocol, Kerberos is not used. If you have multiple instances of SQL Server on a computer, you must configure a Server Principal Name (SPN) for each instance of SQL Server because each instance of SQL Server uses a unique TCP-IP port.

Note If the SQL Server service is running under the LocalSystem account, you do not have to manually configure an SPN for SQL Server. The SPN is created automatically when the SQL Server service starts. If the SQL Server service runs under a domain user account, you must manually configure an SPN. To do this, follow these steps.

To configure an SPN for SQL Server, use the SETSPN utility in the Microsoft Windows Resource Kit. To download the SETSPN utility, visit the following Microsoft Web site:Before you run SETSPN, you must have the following information:
  • The domain user account that the instance of SQL Server is running under. In the following examples, this account is named <SQL_Service_Account>.

    Note If the instance of SQL Server is running under the LocalSystem account, you do not have to run the SETSPN utility.
  • The fully qualified domain name (FQDN) of the computer that is running SQL Server. To determine the FQDN of the computer that is running SQL Server, use the ping utility. To do so, follow these steps:
    1. Ping the computer that is running SQL Server to determine its IP address:
      C:\>ping MySQLServer
      Pinging MySQLServer.MyDomain.com [10.10.10.10] with 32 bytes of data:
      Reply from 10.10.10.10: bytes=32 time=1ms TTL=128
    2. Use ping -a to perform a reverse lookup of the IP address to make sure that the FQDN is correctly returned by the Domain Name System (DNS) protocol:
      C:\>ping -a 10.10.10.10
      Pinging MySQLServer.MyDomain.com [10.10.10.10] with 32 bytes of data:
      Reply from 10.10.10.10: bytes=32 time<1ms TTL=128
    3. Ping the virtual SQL Server name to obtain the IP address, and the run ping -a to make sure that the FQDN is correctly returned by DNS.

      Note If you are using SQL Server failover clustering, you use the FQDN for the virtual SQL Server.
  • The exact TCP-IP port that the instance of SQL Server uses. To determine this information, open Server Network Utility on the computer that is running SQL Server, click the instance of SQL Server, and then view the properties for the TCP/IP protocol (default port).
After you determine the domain user account that the SQL Server service is running under, the FQDN of the computer that is running SQL Server, and the TCP/IP port that the instance of SQL Server is using, follow these steps to create the SPN for SQL Server. Repeat steps 4 and 5 in this section for the flat NetBIOS name, also.

Note You must be a member of the Domain Administrators group to run the SETSPN command.
  1. If you are using SQL Server failover clustering, run the following SETSPN command:
    setspn -A MSSQLSvc/<FQDN> <SQL_Service_Account>
    For example, if MySQLServer.MyDomain.com is running under the domain user account SQLSVC (where MySQLServer.MyDomain.com is the name of the instance of SQL Server 2000 and is clustered), run the following command:
    setspn -A MSSQLSvc/MySQLServer.MyDomain.com SQLSVC
  2. For both clustered and non-clustered computers that are running SQL Server, run the following SETSPN command to register an SPN for the port that the computer that is running SQL Server is using:
    setspn -A MSSQLSvc/<FQDN>:<Port> <SQL_Service_Account>
    For example, if MySQLServer.MyDomain.com is running under the domain user account SQLSVC on port 1433, run the following SETSPN command:
    setspn -A MSSQLSvc/MySQLServer.MyDomain.com:1433 SQLSVC 
  3. After the SPN is registered, verify that it is correctly registered by using the LIST feature. To use the LIST feature, use the -L switch of the SETSPN utility. Run SETSPN -L <SQL_Service_Account> to list all the SPNs that are registered to the domain user account that the instance of SQL Server is running under:
    setspn -L <SQL_Service_Account>
    For example, if MySQLServer.MyDomain.com is running under the domain user account SQLSVC, run the following command:
    setspn -L SQLSVC 
    The SPN that you created in step 1, if SQL Server is clustered, and in step 2, if SQL Server is not clustered, is shown in the following output:
    C:\>setspn -l SQLSVC 
    Registered ServicePrincipalNames for CN=SQLSVC,CN=Users,DC=MyDomain,DC=com: 
    MSSQLSvc/MySQLServer 
    MSSQLSvc/MySQLServer:1433 
    MSSQLSvc/MySQLServer.MyDomain.com 
    MSSQLSvc/MySQLServer.MyDomain.com:1433
    Note If you are using SQL Server failover clustering, you must register a SPN without the port number and another SPN with the port number. With a typical, non-clustered computer that is running SQL Server, you only have to register the SPN with the port number. However, if you have an additional SPN without the port number, it will not cause any problems with non-clustered computers.

    Note You can also use the Ldifde.exe utility on the domain controller to verify both SPN registrations. This is described in the "How to gather a list of Active Directory server principle name information" section.

Step 4: Configure the client computers

  1. For each client that will connect, verify that Microsoft Internet Explorer is configured to use Windows authentication:
    1. In Internet Explorer, on the Tools menu, click Internet Options.
    2. Click the Advanced tab.
    3. Under Security, click to select Enable Integrated Windows Authentication (requires restart), and then click OK.

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 SQLSERVERNAME with the name of the computer that is running SQL Server:
    • 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.
    • If you have auditing turned on in SQL Server, in the Application log you will see that the connection is "trusted".

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 SQLSERVERNAME with the name of the computer that is running SQL Server.
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%="'auth_user' is" & request.servervariables("auth_user")%>
<P>
<%="'auth_type' is" & request.servervariables("auth_type")%>
<P>
Connections string is <B>" Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=SQLSERVERNAME </B>
<P>
<%
	set rs = Server.CreateObject("ADODB.Recordset")
	set cn = Server.CreateObject("ADODB.Connection")
	cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs;Data Source=SQLSERVERNAME"
	rs.open "MASTER..sp_helpdb",cn
	Response.Write cstr(rs.Fields.Count) +"<BR>"
	while not rs.EOF
		Response.Write cstr(rs(0))+"<BR>"
		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 betaland is the NetBIOS domain name and NewoutputUsers.txt 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 "CN=Users,DC=betaland" -l servicePrincipalName -F NewoutputUsers.txt

This syntax creates a file named NewoutputUsers.txt that contains information that is similar to the output in the "Domain level output of NewouputUsers.txt" 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 User Name is the user name and betaland is the domain that you are querying:

ldifde -d "CN=User Name,DC=betaland" -l servicePrincipalName -F NewoutputUsers.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 "User Name" 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

REFERENCES

For more information about security account delegation, see the "Security Account Delegation" topic in SQL Server Books Online.

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

262177 How to enable Kerberos event logging

321708 How to use the Network Diagnostics Tool (Netdiag.exe) in Windows 2000

326985 How to troubleshoot Kerberos-related issues in IIS

244474 How to force Kerberos to use TCP instead of UDP in Windows Server 2003, in Windows XP, and in Windows 2000


Modification Type:MajorLast Reviewed:6/29/2006
Keywords:kbinfo KB319723 kbAudDeveloper