{"id":1224,"date":"2014-06-10T08:08:15","date_gmt":"2014-06-10T07:08:15","guid":{"rendered":"http:\/\/blog.repsaj.nl\/?p=1224"},"modified":"2014-09-15T14:56:16","modified_gmt":"2014-09-15T13:56:16","slug":"sp201x-implementing-kerberos-delegation-in-sharepoint","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2014\/06\/sp201x-implementing-kerberos-delegation-in-sharepoint\/","title":{"rendered":"[SP201x] Implementing Kerberos delegation in SharePoint"},"content":{"rendered":"<p>Kerberos is often perceived as painful to setup and hard to debug. And to be honest: in my opinion it\u2019s not one of the most user friendly techniques out there. But once you get the hang of it, the bigger picture start becoming clear and things get easier. In this article I will explain how to use Kerberos in combination with Business Connectivity Services (BCS) to delegate a users\u2019 credentials to SQL Server. So let\u2019s get to it!<!--more--><\/p>\n<h2>An example case<\/h2>\n<p>Let\u2019s start with a short case description for some context. Suppose you\u2019re contacted by a business user, John, who wants to surface data from a SQL server database in SharePoint. The data in the database is of sensitive nature. Based on the logged on user, John wants the solution to filter the records so only the appropriate ones are shown. So there is a need for an additional layer of security, to make sure the correct data is visible for each user.<\/p>\n<p>There are some routes you may consider:<\/p>\n<ol>\n<li>Create a web service which queries the database and adds a layer of security to make sure the user only sees the appropriate data. Connect your BCS entities to this web service, instead of directly to SQL.<\/li>\n<li>Create views within SQL which use the current logged on user to pre-filter the table and return only relevant data. This is sometimes referred to as <em>view-time <\/em>security.<\/li>\n<li>Use reporting services to create a report which filters data based on the current user.<\/li>\n<\/ol>\n<p>The real creative thinkers amongst you might think of more ways to do the same, but that\u2019s not the point here. The point is that SharePoint is not going to magically filter the data, so you need to make arrangements to make sure that your security requirements are met. And for that, you will need to be able to know which user is requesting the data, no matter which solution you choose.<\/p>\n<p>&nbsp;<\/p>\n<h2>Kerberos authentication, the basics<\/h2>\n<p>As the name implies, Kerberos will help us with authenticating the user. It\u2019s important to understand that authentication is not the same as authorization. Authentication will help you to identify the user, making sure their identity is validated. Authorizing is the process of granting a user access to resources, based on that same identity. I will not go into the details of authentication; it suffices to know that Kerberos implements a way of checking your credentials to validate your identity. In Microsoft Active Directory environments, Kerberos or NTLM is used as authentication method, where Kerberos is the more secure one.<\/p>\n<p>In the mentioned case, our user\u2019s identity will be used in several places:<\/p>\n<ul>\n<li>First, SharePoint will authenticate the user.<\/li>\n<li>It will then use the user\u2019s identity to check if he \/ she is authorized (there\u2019s the difference!) to view the page, the BCS entity, etc.<\/li>\n<li>Now, assuming our user is authorized, BCS is going to query the SQL database to get the actual data. SQL is going to ask for credentials as well. That is where <strong>delegation <\/strong>comes in.<\/li>\n<li>SharePoint delegate your credentials to SQL, who will authenticate<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Why Kerberos?<\/h2>\n<p>When you search for the combination of SharePoint and Kerberos online, you will find a lot of people having problems with it (myself included by the way). Based on that, you might ask: why should I use Kerberos at all? Well for starters, your domain admins might have specified it\u2019s required. Secondly, NTLM doesn\u2019t support <strong>double hop authentication<\/strong>. Double hop means your credentials are passed on to a second service \/ server, like we\u2019re doing in this case. Lastly and arguably the most important reason: it\u2019s the most secure over NTLM. So, Kerberos it is\u2026<\/p>\n<p>&nbsp;<\/p>\n<h2>Step 1: SPNs<\/h2>\n<p>To be able to use Kerberos, the service using it should be registered in Active Directory. This is done using a <strong>service principal name<\/strong> (SPN). To register an SPN, we need some detail on the service which will be using Kerberos as an authentication provider.<\/p>\n<ul>\n<li>Which service you\u2019ll be using. When you initially enabled Kerberos for SharePoint, you used HTTP as the service type. Since we\u2019re enabling SQL Server to use Kerberos, we use: <strong>MSSQLSvc<\/strong>\n<ul>\n<li>The fully qualified domain name (FQDN) of the SQL server: <strong>sqlserver.contoso.com<\/strong><\/li>\n<li>The port your server is using, or in case of a named instance: the named instance itself. <b><strong>1433 <\/strong><\/b>(default)<\/li>\n<li><strong>SP <\/strong>(named instance)<\/li>\n<li>The service account which is used to run the SQL service: <strong>CONTOSO\\sqlserver_svc<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>We use these parameters as input for the setspn command, as follows:<\/p>\n<p><code>setspn \u2013A MSSQLSvc\/sqlserver.contoso.com:1433 CONTOSO\\sqlserver_svc<br \/>\nsetspn \u2013A MSSQLSvc\/sqlserver.contoso.com:SP CONTOSO\\sqlserver_svc<\/code><\/p>\n<p>The setspn command should be executed by a domain admin. When the details are correct, this will register the SPN in AD.<br \/>\n<strong>TIP! <\/strong>Ask your DBA for these details. And should he \/ she not know (or there is no DBA&#8230;): Microsoft has a tool which finds out for you. It\u2019s called \u201cMicrosoft Kerberos Configuration Manager for SQL Server\u201d. With this tool, you can easily check if your configuration is OK and it can also generate the script to generate the correct SPNs when needed. This way you have to worry less about the correct ports and named instances.<\/p>\n<p><a href=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-1225\" src=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01-1024x152.png\" alt=\"Siegmund_BCS Kerberos Delegation_01\" width=\"625\" height=\"92\" srcset=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01-1024x152.png 1024w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01-300x44.png 300w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01-624x93.png 624w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_01.png 1107w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p><em>Figure 1: The Kerberos Configuration Manager shows missing SPNs and allows to generate a script for SPN creation.<\/em><\/p>\n<p><strong>Note:<\/strong> when you\u2019re running SQL 2012 AlwaysOn, you will need to register SPNs for all of the servers in your availability group. You do not have to register SPNs for your listener or aliases. Use the Kerberos Configuration Manager to find out exactly what you need to register.<\/p>\n<p>&nbsp;<\/p>\n<h2>Step 2: delegation<\/h2>\n<p>Setting the SPNs will not yet have enabled the double-hop scenario. We now need to tell Active Directory that our SharePoint application pool accounts are allowed to delegate credentials to the previously added SPNs.<\/p>\n<p>To do so, open up the Active Directory Users and Computers tool and find the account used for the SharePoint application pool. Note that this is the application pool which serves the site in which you want to use the external content type (ECT). When you\u2019re going to use it in multiple web applications, you might have to do these steps for multiple accounts as well.<\/p>\n<p><a href=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_02.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1226\" src=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_02.png\" alt=\"Siegmund_BCS Kerberos Delegation_02\" width=\"470\" height=\"420\" srcset=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_02.png 470w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_02-300x268.png 300w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/a><\/p>\n<p><em>Figure 2: the Delegation tab shows to which SPNs this account is allowed to delegate credentials. <\/em><\/p>\n<p>On the Delegation tab (Figure 2), you will find all of the SPNs to which this account is allowed to delegate. Of course you could also select \u201cTrust this user for delegation to any service (Kerberos only)\u201d, which would be the easier, but less safe option. To add an SPN, click \u201cAdd\u201d and search for your SQL Server service account (NOT the server itself). You will now find all SPNs (servers) registered for that particular service account; select the ones you need to enable delegation for. At this time, Kerberos will now allow delegation of user credentials by the SharePoint application pool, to the SQL server hosting the database.<\/p>\n<p>&nbsp;<\/p>\n<h2>Step 3: Configuring ECT for delegation<\/h2>\n<p>When you create an External Content Type (ECT), the connection properties (figure 1) have an \u201cAuthentication Mode\u201d property. Here, we can choose between the following values:<\/p>\n<ul>\n<li>User\u2019s Identity<\/li>\n<li>BCS Identity<\/li>\n<li>Impersonate Windows Identity<\/li>\n<li>Impersonate Custom Identity<\/li>\n<\/ul>\n<p>The two <strong>impersonate<\/strong> options use a credential which is stored in the secure store and identified with a secure store application ID. This will usually be a service account stored in Active Directory, or a SQL account. The \u201cBCS Identity\u201d option uses the application pool account. This option is disabled by default and in most cases you should leave it that way. Reusing such an account for multiple purposes adds security risks and complicates your security scheme.<br \/>\nThe first option is the one we\u2019re interested in: using the <strong>User\u2019sIdentity<\/strong>. This means BCS will connect to the SQL server by delegating (acting on behalf of) the currently logged on user. This way, we can use this information to filter data.<\/p>\n<p><a href=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_03.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1227\" src=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_03.png\" alt=\"Siegmund_BCS Kerberos Delegation_03\" width=\"419\" height=\"419\" srcset=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_03.png 419w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_03-150x150.png 150w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2014\/06\/Siegmund_BCS-Kerberos-Delegation_03-300x300.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/a><\/p>\n<p><em>Figure 3: BCS connection properties<\/em><\/p>\n<p>That\u2019s it! You should now be able to create a new External List based on your previously created content type. When everything is configured, SharePoint now passes along the identity of the currently logged on user to SQL. You can check if your connections are using Kerberos by using the following SQL statement:<\/p>\n<p><code>SELECT auth_scheme FROM sys.dm_exec_connections<\/code><\/p>\n<p>And when you want to include the current user in your view, use the CURRENT_USER variable as such:<\/p>\n<p><code>SELECT CURRENT_USER<br \/>\n<\/code><\/p>\n<p>Of course, these same steps apply to any service for which you want to enable Kerberos. Make sure you register the correct service type, server name and accounts; and you\u2019re good to go!<\/p>\n<p>&nbsp;<\/p>\n<h2>Used sources \/ links<\/h2>\n<p>Identity delegation for Business Connectivity Services<br \/>\n<a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/gg502600(v=office.14).aspx\">http:\/\/technet.microsoft.com\/en-us\/library\/gg502600(v=office.14).aspx<\/a><\/p>\n<p>SharePoint 2010 and Kerberos<br \/>\n<a href=\"http:\/\/www.harbar.net\/archive\/2010\/03\/31\/sharepoint-2010-and-kerberos.aspx\">http:\/\/www.harbar.net\/archive\/2010\/03\/31\/sharepoint-2010-and-kerberos.aspx<\/a><\/p>\n<p>Authenticating to Your External System<br \/>\n<a href=\"http:\/\/blogs.msdn.com\/b\/bcs\/archive\/2010\/03\/12\/authenticating-to-your-external-system.aspx\">http:\/\/blogs.msdn.com\/b\/bcs\/archive\/2010\/03\/12\/authenticating-to-your-external-system.aspx<\/a><\/p>\n<p>Setspn overview<br \/>\n<a href=\"http:\/\/technet.microsoft.com\/nl-nl\/library\/cc773257(v=WS.10).aspx\">http:\/\/technet.microsoft.com\/nl-nl\/library\/cc773257(v=WS.10).aspx<\/a><\/p>\n<p>Microsoft\u00ae Kerberos Configuration Manager for SQL Server\u00ae<br \/>\n<a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=39046\">http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=39046<\/a><\/p>\n<p><strong>Update; <\/strong>this is also a very good read on the subject: <a href=\"http:\/\/www.itunity.com\/article\/sharepoint-2010-2013-kerberos-unconstrained-constrained-delegation-533\" target=\"_blank\">http:\/\/www.itunity.com\/article\/sharepoint-2010-2013-kerberos-unconstrained-constrained-delegation-533<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kerberos is often perceived as painful to setup and hard to debug. And to be honest: in my opinion it\u2019s not one of the most user friendly techniques out there. But once you get the hang of it, the bigger picture start becoming clear and things get easier. In this article I will explain how<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[11,7,39,109],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-jK","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1224"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=1224"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/1224\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=1224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=1224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=1224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}