<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security for Canadian Developers : SQL Server 2005</title><link>http://blogs.msdn.com/s4cd/archive/tags/SQL+Server+2005/default.aspx</link><description>Tags: SQL Server 2005</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Signing Modules in SQL Server 2005 with Certificates</title><link>http://blogs.msdn.com/s4cd/archive/2006/09/06/743182.aspx</link><pubDate>Wed, 06 Sep 2006 23:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:743182</guid><dc:creator>dansellers</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/s4cd/comments/743182.aspx</comments><wfw:commentRss>http://blogs.msdn.com/s4cd/commentrss.aspx?PostID=743182</wfw:commentRss><description>&lt;P&gt;The one topic that I get asked to talk about frequently is Encrypting Data with SQL Server 2005.&amp;nbsp; Personally, I am very impressed with the build-in encryption support provided in SQL Server 2005, but one of my favorite and what appears to be a subtle Security enhancement in SQL Server 2005 is the ability to sign Modules such as Stored Procedures, Functions or&amp;nbsp;Triggers&amp;nbsp;with Certificates.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The first thing you are probably wonder is why would I want to sign a Stored Procedures?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/ms345102.aspx" target=_blank&gt;By signing a Module&lt;/A&gt; with a certificate, the certificate is then granted the relevant permission and goes beyond what can be achieved with the "Execute As" feature, especially from an auditing perspective.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;When you perform tracing, the auditing table will&amp;nbsp;record the&amp;nbsp;"Execute As User" that performed the operation of the Stored Procedure (the user account in which the stored procedure is executing under) but does not show who the&amp;nbsp;actual calling user was.&amp;nbsp; Now, there is a additional column in the auditing table that will record the original login that caused the actions to occur, however, in the trace records it will only show that Execute As User performed all the operations and not the original caller.&lt;/P&gt;
&lt;P&gt;Thus the moral of the story is we use the Sign Module approach in SQL Server 2005 this will allow us to capture the original caller that caused the action to occur in the Stored Procedure.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;So how do I set this up?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Let say we have an End User calling a Stored Procedure called Proc1 that will perform some kind of action on Table1.&amp;nbsp; The End User does not have permission on the Table 1, only the Proc1 does, however, the End User has been granted Execute permission.&lt;/P&gt;
&lt;P&gt;Now we can sign Proc1 with a certificate called Cert1.&amp;nbsp; We then create a User called CertUser which is mapped to the Cert1.&amp;nbsp; Then we grant the necessary permission on Table1 to CertUser.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What is going on under the Hood of SQL Server 2005?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When a SQL Server 2005 User calls a Module the User Token--similar to a token in Windows will be passed to the Module.&amp;nbsp; The Token will contain both the primary id--identifies the calling user--and the secondary's id--the SQL Server 2005 roles the user belongs to.&amp;nbsp; If the Module has been signed, SQL Server 2005 will add the User Account which has been mapped to the Certificate--that was used to sign the Module--to the secondary id of the calling user.&lt;/P&gt;
&lt;P&gt;Therefore, in our example, when EndUser calls SP1, SP1 will verify the signature of Cert1 and add CertUser--the user that was mapped to the Certificate--to the secondary id of the EndUser token.&amp;nbsp; Now EndUser can have access to the Table1 via the signed Module "Proc1" and in tracing we can capture the "Calling User"--End User--and not just the "Executing As User" only.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=743182" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/s4cd/archive/tags/SQL+Server+2005/default.aspx">SQL Server 2005</category></item></channel></rss>