{"id":80438,"date":"2018-08-21T22:35:21","date_gmt":"2018-08-21T22:35:21","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=80438"},"modified":"2022-04-24T20:59:40","modified_gmt":"2022-04-24T20:59:40","slug":"questions-about-kerberos-and-sql-server-that-you-were-too-shy-to-ask","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/questions-about-kerberos-and-sql-server-that-you-were-too-shy-to-ask\/","title":{"rendered":"Questions About Kerberos and SQL Server That You Were Too Shy to Ask"},"content":{"rendered":"<h3>The Questions<\/h3>\n<ol>\n<li><a href=\"#first\">What is Kerberos?<\/a><\/li>\n<li><a href=\"#second\">Why is Kerberos needed for SQL Server?<\/a><\/li>\n<li><a href=\"#third\">Can\u2019t I just avoid using Kerberos?<\/a><\/li>\n<li><a href=\"#fourth\">What is a Service Principal Name (SPN)?<\/a><\/li>\n<li><a href=\"#fifth\">Is there a way to see SPNs in AD?<\/a><\/li>\n<li><a href=\"#sixth\">How are SPNs created or changed?<\/a><\/li>\n<li><a href=\"#seventh\">What happens if I change the service account of my SQL Server?<\/a><\/li>\n<li><a href=\"#eighth\">How can I tell if I\u2019m connecting with Kerberos authentication?<\/a><\/li>\n<li><a href=\"#ninth\">I\u2019m connecting from another server, but it\u2019s using NTLM. How did that happen?<\/a><\/li>\n<li><a href=\"#tenth\">Kerberos authentication is working for the instance, but why aren\u2019t the SSRS reports running?<\/a><\/li>\n<li><a href=\"#eleventh\">How do I set up Kerberos for linked servers?<\/a><\/li>\n<li><a href=\"#twelfth\">Any other surprises I need to know about?<\/a><\/li>\n<\/ol>\n<h2 id=\"first\">1. What is Kerberos?<\/h2>\n<p>Kerberos is an authentication protocol used in networks, including Active Directory (AD), that is based on the use of encrypted tickets for access to network resources.<\/p>\n<p>In a situation in an AD network when Kerberos can\u2019t be used, then the older and less secure NTLM authentication protocol is used instead. There are many situations where the end user will not be able to access the resources they need with NTLM. This is especially true when more than one network resource is involved with the request (double-hop), such as is often the case with SSRS (SQL Server Reporting Services) or a linked server.<\/p>\n<p>For Kerberos authentication to connect to a SQL Server instance, Service Principal Names (SPNs) must be properly configured in AD. While these are not difficult to create, most DBAs will not have rights to do so. Even with network administrator privileges, it\u2019s easy to make a mistake when creating SPNs. When DBAs understand Kerberos, they can help the network administrator troubleshoot issues.<\/p>\n<h2 id=\"second\">2. Why is Kerberos needed for SQL Server?<\/h2>\n<p>When NTLM is used, the client, for example a user logged into a laptop, contacts a domain controller when requesting access to a resource in the network. This resource could be an SSRS report, for example. When using NTLM, the user proves their identity to the SSRS server. Unfortunately, the SSRS server cannot forward the credentials of the user along to the database server. The database server will deny the request, and the end user will see an error message. This is common with SSRS but will also be seen whenever resources are needed involving multiple servers.<\/p>\n<p>When Kerberos is properly configured, the SSRS server can pass along confirmation of the identity of the requester to the database server via the ticket. If the login of the original requester has permission to select the data, it\u2019s returned to the SSRS server, and the report is delivered.<\/p>\n<p>Even if you are not using SSRS, you can run into issues when Kerberos is not configured properly. For example, you will often see error messages when trying to connect to SQL Server using SSMS (SQL Server Management Studio) when logged into another server when SPNs are misconfigured.<\/p>\n<h2 id=\"third\">3. Can\u2019t I just avoid using Kerberos?<\/h2>\n<p>If the resources are located within the same physical server or virtual machine, then Kerberos authentication is not required. In this case, the identity of the requester is just needed on one server; nothing needs to be forwarded along. Typically, an SSRS server runs reports that need data from many servers across the network. Even if that\u2019s not the case, SSRS is often installed on its own server for performance reasons. This is that double-hop issue I mentioned earlier.<\/p>\n<p>Another way to avoid using Kerberos in any situation is by using SQL Server logins or users instead of network accounts. For example, if the SSRS report contains credentials for a SQL Server login, Kerberos will not be involved when the request is made to the database. This may or may not be a good idea in your organization depending on security policies or application requirements.<\/p>\n<p>You can also save the credentials for a Windows account in an SSRS data source. This will avoid the double-hop problem since the user name and password will be used by the SSRS server when making the request to the database server. Keep in mind, however, that only one set of credentials can be saved in a data source, so this will probably not be the credentials of the person who wants to run the report. As long as the user has rights to run the report, they do not need permission to the actual data. Again, this might be something you use now, possibly for SSRS subscriptions, but it also might be something you should avoid depending on the policies in your organization.<\/p>\n<p>One other option for SSRS is to save Windows credentials but try to impersonate the user running the report. Theoretically, this can be used to bypass Kerberos, but it uses the <strong>SETUSER c<\/strong>ommand after connecting to the database. This command is deprecated and requires either <em>sysadmin<\/em> or <em>db_owner<\/em> membership by the account whose credentials you are saving. That is not a great idea! It may be a good choice for other sources of data, such as SSAS Tabular, but it\u2019s probably not suited for a traditional SQL Server database.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"661\" height=\"541\" class=\"wp-image-80439\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-61.png\" \/><\/p>\n<h2 id=\"fourth\">4. What is a Service Principal Name (SPN)?<\/h2>\n<p>SPNs are properties of service accounts in AD. It associates the service account to the service. SPNs are in the form <em>Service\/Server Domain\\ServiceAccount<\/em>. Here is an example:<\/p>\n<p>Fully qualified server name: <strong>SQL1.mydomain.local<\/strong><\/p>\n<p>Port: <strong>1433<\/strong><\/p>\n<p>Instance: <strong>Default<\/strong><\/p>\n<p>Service account: <strong>sqlservice1<\/strong><\/p>\n<p>There should be two SPNs registered for the SQL Server instance:<\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local mydomain\\sqlservice1<\/strong><\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local:1433 mydomain\\sqlservice1<\/strong><\/p>\n<p>If the SQL Server instance is using a local account instead of an AD account, the <em>computer name<\/em> will be used instead of a service account name. Here is an example:<\/p>\n<p>Fully qualified server name: <strong>SQL1.mydomain.local<\/strong><\/p>\n<p>Port: <strong>1433<\/strong><\/p>\n<p>Instance: <strong>Default<\/strong><\/p>\n<p>Service account: <strong>Network Service<\/strong><\/p>\n<p>There should be two SPNs registered:<\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local mydomain\\SQL1<\/strong><\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local:1433 mydomain\\SQL1<\/strong><\/p>\n<p>If you have a SQL Server with a named instance, then the SPNs would look like this:<\/p>\n<p>Fully qualified server name: <strong>SQL1.mydomain.local<\/strong><\/p>\n<p>Port: <strong>49827<\/strong><\/p>\n<p>Instance: <strong>Inst1<\/strong><\/p>\n<p>Service account: <strong>Network Service<\/strong><\/p>\n<p>There should be two SPNs registered:<\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local:inst1 mydomain\\SQL1<\/strong><\/p>\n<p><strong>MSSQLSvc\/SQL1.mydomain.local:49827 mydomain\\SQL1<\/strong><\/p>\n<h2 id=\"fifth\">5. Is there a way to see SPNs in AD?<\/h2>\n<p>You can see the <em>SPNs in the Active Directory Users and Computers<\/em> utility. The first step is to enable the <em>Advanced Features<\/em> view.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"611\" height=\"330\" class=\"wp-image-80440\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-62.png\" \/><\/p>\n<p>After finding the object, search in the <em>Attribute Editor<\/em> for <em>servicePrincipleName<\/em> and click <em>Edit<\/em>. This example shows the SPNs that are registered using the computer account because the default account was used during installation of the instance. It\u2019s also a named instance.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-80502\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/spn.png\" alt=\"\" width=\"435\" height=\"510\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>You can also add or remove SPNs from this dialog with the appropriate rights.<\/p>\n<h2 id=\"sixth\">6. How are SPNs created or changed?<\/h2>\n<p>To add or delete an SPN, use the <strong>setspn<\/strong> utility in a command window or PowerShell session. Keep in mind that DBAs will likely not have rights to add or delete SPNs, but it\u2019s useful to know what needs to be changed when working with your network administrators.<\/p>\n<p>Here are the commands:<\/p>\n<p><strong>Setspn -L<\/strong> will list all the SPNs registered for a given service account. In the case of a SQL Server using a local account, you will use the computer name.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">Setspn -L mydomain\\sql1\r\nSetspn -L mydomain\\sqlservice1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"637\" height=\"179\" class=\"wp-image-80443\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-65.png\" \/><\/p>\n<p><strong>Setspn -D<\/strong> is used to delete an SPN.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">Setspn -D MSSQLSvc\/SQL1.mydomain.local mydomain\\SQL1\r\nSetspn -D MSSQLSvc\/SQL1.mydomain.local mydomain\\SQL1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-80444\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-66.png\" width=\"710\" height=\"135\" \/><\/p>\n<p><strong>Setspn -S<\/strong> is used to add an SPN. It avoids creating duplicate SPNs for a given service. If an SPN is already registered for a service with a different service account, it should return an error message including the account with the current SPN.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">Setspn -S MSSQLSvc\/SQL1.mydomain.local:1433 mydomain\\sqlservice1\r\nSetspn -S MSSQLSvc\/SQL1.mydomain.local mydomain\\sqlservice1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-80445\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-67.png\" width=\"705\" height=\"228\" \/><\/p>\n<p><strong>Setspn -Q <\/strong>is used to search for existing SPNs registered for a given service. This is helpful when troubleshooting Kerberos issues and you can\u2019t figure out where the SPN is registered.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">Setspn -Q MSSQLSvc\/sql1.mydomain.local<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"147\" class=\"wp-image-80446\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-68.png\" \/><\/p>\n<h2 id=\"seventh\">7. What happens if I change the service account of my SQL Server?<\/h2>\n<p>When the service account changes, the SPNs must be switched to the new service account. Before a new SPN is added, any incorrect SPNs must be removed. The old SPN will not be removed automatically, and you cannot have multiple entries for the same service. Often, SQL Server instances are installed using the default account, which is local. Only later will the correct service account be set up. When this happens, the old SPN will be left in place, and Kerberos authentication will not work. SSRS reports that were running previously may begin erroring out instead. Often, you\u2019ll see this error when attempting to connect via SSMS from another computer.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"604\" height=\"155\" class=\"wp-image-80447\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-69.png\" \/><\/p>\n<p>Someone with permission to create and remove SPNs will need to run the <strong>setspn -D<\/strong> command to remove the old SPNs and the <strong>setspn -S<\/strong> command to add the new ones. You may need to restart the SQL Server instance and wait for it to be replicated in AD before the change works.<\/p>\n<h2 id=\"eighth\">8. How can I tell if I\u2019m connecting with Kerberos authentication?<\/h2>\n<p>First, Kerberos only comes into play when connecting from a different server. If you are remote controlling the server, you will not be using Kerberos. If you have <strong>VIEW SERVER STATE<\/strong> permission on the instance, you can run this query:<\/p>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">SELECT S.login_name, C.auth_scheme, s.host_name\r\nFROM sys.dm_exec_connections AS C\r\nJOIN sys.dm_exec_sessions AS S ON C.session_id = S.session_id;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"267\" height=\"104\" class=\"wp-image-80448\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-70.png\" \/><\/p>\n<p>You can also use the <strong>klist<\/strong> command to view the tickets. In this example, you can see the ticket for the SQL Server in #2.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-80449\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-71.png\" width=\"657\" height=\"633\" \/><\/p>\n<p>You will see this error message when Kerberos is required, but you are not able to use it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"116\" class=\"wp-image-80450\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-72.png\" \/><\/p>\n<h2 id=\"ninth\">9. I\u2019m connecting from another server, but it\u2019s using NTLM. How did that happen?<\/h2>\n<p>If no SPNs are configured for the instance, then NTLM will be used without error as long as no double-hop is involved. This could happen when the DBA installs the instance and doesn\u2019t have permission to create SPNs, which is typically the case.<\/p>\n<h2 id=\"tenth\">10. Kerberos authentication is working for the instance, but why aren\u2019t the SSRS reports running?<\/h2>\n<p>There are five steps you must complete to get Kerberos configured for native mode SSRS connecting to a SQL Server database:<\/p>\n<ul>\n<li>Create an SPN for the SSRS server. The SPN should look like this for a server named SSRS1 and service account SSRSservice1:<\/li>\n<\/ul>\n<pre class=\"lang:ps theme:powershell-ise\">Setspn -S http\/SSRS1.mydomain.local mydomain\\SSRSservice1<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-80451\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-73.png\" width=\"803\" height=\"94\" \/><\/p>\n<p>It might also be a good idea to set one up for the server name without the domain as well. If the SSRS service is using a local account, then no SPN needs to be created. Instead, it uses the <em>HOST<\/em> SPNs that should already be in place.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"179\" class=\"wp-image-80452\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-74.png\" \/><\/p>\n<ul>\n<li>Set the Delegation property for the SSRS service account in AD to <em>Trust this user for delegation to any service (Kerberos only)<\/em>. The <em>Delegation<\/em> page will not show up in Active Directory Users and Computers until the account has an SPN filled in. Note that this is not the setting used for SharePoint integrated mode or for the new Power BI Report Server. These steps are for native mode pointing to a SQL Server database only.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-80507\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/delegation.png\" alt=\"\" width=\"461\" height=\"627\" \/><\/p>\n<ul>\n<li>Make sure that the <em>Account is sensitive and cannot be delegated property<\/em> is disabled.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"395\" height=\"535\" class=\"wp-image-80454\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-76.png\" \/><\/p>\n<ul>\n<li>Add a value to the SSRS <em>RSReportServer.config<\/em> file on the SSRS server.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"203\" class=\"wp-image-80455\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-77.png\" \/><\/p>\n<ul>\n<li>Once everything is complete, restart the SSRS service<\/li>\n<\/ul>\n<p>Microsoft has made a tool available, <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=39046\">Kerberos Configuration Manager<\/a>, that can help troubleshoot SPNs when setting up Kerberos for SSRS.<\/p>\n<h2 id=\"eleventh\">11. How do I set up Kerberos for linked servers?<\/h2>\n<p>Set up SPNs for both instances. Set delegation to <em>Trust this user for delegation to any service<\/em> on the service account being used on the instance where the linked server is set up. Basically, the server that must pass the ticket along must be set up for delegation.<\/p>\n<h2 id=\"twelfth\">12. Any other surprises I need to know about?<\/h2>\n<p>If there are any time discrepancies on the servers, Kerberos will not work. For example, if you set up a test domain in virtual machines on your laptop, make sure that the domain controller is in the same time zone as the laptop.<\/p>\n<p>Another problem could be that the SSRS server needs the .NET Framework 3.5 feature installed. I\u2019ve seen situations where everything was configured properly, and reports using SQL Server authentication worked, but Kerberos authentication for SSRS just wouldn\u2019t work. Installing .NET Framework 3.5 and restarting the SSRS service fixed the issue.<\/p>\n<p>Instead of using dynamic ports for your instances, be sure to set static ports to make sure that the port doesn\u2019t change and break the SPN.<\/p>\n<p>When testing, you may need to clear out existing tickets with the <strong>klist purge<\/strong> command and log out and back in. Sometime, just waiting a few minutes is required for a change to be replicated in AD is needed. You also may need to reboot the server after adding an SPN.<\/p>\n<p>This article focused on native mode SSRS connecting to a SQL Server database in the same domain. You will have to do some additional research to understand the settings required to enable Kerberos for other applications, services, and situations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kerberos authentication is a topic that many database administrators avoid. It\u2019s really not that difficult to understand, but it\u2019s also easy to get wrong. In this article, Kathi Kellenberger talks about what you need to know about configuring Kerberos for SSRS and SQL Server databases but were too shy to ask.&hellip;<\/p>\n","protected":false},"author":110218,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527],"tags":[5771],"coauthors":[11292],"class_list":["post-80438","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","tag-too-shy"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/110218"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=80438"}],"version-history":[{"count":28,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80438\/revisions"}],"predecessor-version":[{"id":81000,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80438\/revisions\/81000"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=80438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=80438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=80438"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=80438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}