<?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>SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx</link><description>The ability to sign procedures is my favorite cryptographic feature in SQL Server 2005. If we want to write a procedure that requires permission P, and we want Alice to be able to execute the procedure but we do not want to grant her the permission P,</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#430204</link><pubDate>Fri, 17 Jun 2005 18:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:430204</guid><dc:creator>Chrisr</dc:creator><description>I think I am missing something when it comes to providing data security. The above example is really nice when permission P is not SELECT\UPDATE\INSERT\DELETE for a given table. However, I can prevent a user from directly accessing data on a table by implementing a stored procedure and only granting execute privs to the user on the procedure. This works if the procedure is signed or un-signed. I can also see how it would be beneficial if ownership chaining is involved with the stored procedure to be executed. But I don't see the advantage of signing a procedure when that procedure operates against tables in its own schema and I wish to prevent granting direct privs to a user on the tables.</description></item><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#430238</link><pubDate>Fri, 17 Jun 2005 20:03:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:430238</guid><dc:creator>lcris</dc:creator><description>You're right, if what you want to do can be achieved by ownership chaining, then you don't need to sign your procedure. However, the ability to sign procedures allows scenarios that are not possible with ownership chaining.</description></item><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#471886</link><pubDate>Tue, 20 Sep 2005 21:20:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:471886</guid><dc:creator>brian</dc:creator><description>Hi, I am missing the connection between Alice and  u_certSignCreatePrincipal. Do all users that have EXECUTE have permissions to run the proc or just Alice?</description></item><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#472060</link><pubDate>Wed, 21 Sep 2005 02:14:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:472060</guid><dc:creator>lcris</dc:creator><description>alice is just a low-privileged principal that is used to demo the fact that she can create logins via the proc, without explicitly having been granted the permission to create logins.&lt;br&gt;&lt;br&gt;u_certSignCreatePrincipal is used to grant database permissions to the certificate. l_certSignCreatePrincipal is used to grant server permissions to the certificate. Both these principals are mapped to the certificate via the FROM CERTIFICATE clause.&lt;br&gt;&lt;br&gt;In the example, alice is explicitly granted EXECUTE permission on the procedure.&lt;br&gt;</description></item><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#8848151</link><pubDate>Mon, 11 Aug 2008 17:10:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8848151</guid><dc:creator>toddsriley</dc:creator><description>&lt;P&gt;Great article. &amp;nbsp;I am looking into using certificates and procedure signing as a temporary means of getting around granting direct permissions to the sp_OA procedures to our developers. &amp;nbsp;Eventually, we will, of course, move to using CLR procedures instead of sp_OA but as it stands, I just need a way to give these permissions to our developers through stored procedure signing. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here’s what I have been able to do and where I am running into issues. &amp;nbsp;I started by creating a stored procedure that was similar to the situation we have in our real production environment. &amp;nbsp;The procedure simply uses the sp_send_dbmail stored procedure to send me an email:&lt;/P&gt;
&lt;P&gt;USE [my_database]&lt;/P&gt;
&lt;P&gt;CREATE &amp;nbsp; PROCEDURE dbo.P_Send_Mail_Test&lt;/P&gt;
&lt;P&gt;AS &lt;/P&gt;
&lt;P&gt;BEGIN &lt;/P&gt;
&lt;P&gt;EXECUTE msdb.dbo.sp_send_dbmail&lt;/P&gt;
&lt;P&gt;&amp;nbsp; @profile_name = 'Name',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;@recipients = 'myemail@whatever.com',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;@body = 'Will this certification test work?',&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;@subject = 'Certification Test'&lt;/P&gt;
&lt;P&gt;END&lt;/P&gt;
&lt;P&gt;Then I execute the proc to ensure that it works. &amp;nbsp;It does. &amp;nbsp;Then I grant permissions to a user in our database who is not a member of the sysadmin server role, impersonate him, then try to execute the procedure – “you do not have permissions to execute sp_send_dbmail”. &amp;nbsp;This was expected. &amp;nbsp;So I reverted to my own permissions and went to the msdb database. &amp;nbsp;I created a master key that was encrypted by a password and then a certificate:&lt;/P&gt;
&lt;P&gt;CREATE CERTIFICATE My_Certificate&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WITH SUBJECT = 'User Certificate to Extend Impersonation', &lt;/P&gt;
&lt;P&gt;&amp;nbsp; EXPIRY_DATE = '12/31/2009';&lt;/P&gt;
&lt;P&gt;Then I added a signature to sp_send_dbmail by the certificate I had created and backed the cert up to a file location. (I had also removed the private key before backing up a few of the times I tried this). &amp;nbsp;I created a user from the cert in msdb, granted execute permissions on sp_send_dbmail to the user and also granted authenticate to the user.&lt;/P&gt;
&lt;P&gt;I went back to my_database and created cert with same name from file location:&lt;/P&gt;
&lt;P&gt;CREATE CERTIFICATE My_Certificate FROM FILE = 'C:\cert_sign.cer'&lt;/P&gt;
&lt;P&gt;HERE IS WHERE I AM HAVING MY PROBLEM. &amp;nbsp;When I then try to sign my procedure, P_Send_Mail_Test, I get an error:&lt;/P&gt;
&lt;P&gt;ADD SIGNATURE TO P_Send_Mail_Test BY CERTIFICATE My_Certificate&lt;/P&gt;
&lt;P&gt;Msg 15556, Level 16, State 1, Line 2&lt;/P&gt;
&lt;P&gt;Cannot decrypt or encrypt using the specified certificate, either because it has no private key or because the password provided for the private key is incorrect.&lt;/P&gt;
&lt;P&gt;In other articles, I have seen examples where the author makes use of a private key and not the master key. &amp;nbsp;I would be more than happy to try this but do not know how to create a private key. &amp;nbsp;I even tried, when signing the procedure, using the signature from crypt_properties – didn’t work. &amp;nbsp;And also tried providing the password I used when creating the master key:&lt;/P&gt;
&lt;P&gt;ADD SIGNATURE TO P_Send_Mail_Test BY CERTIFICATE User_Certificate &lt;/P&gt;
&lt;P&gt;WITH &amp;nbsp;PASSWORD = 'WhateverItWas'&lt;/P&gt;
&lt;P&gt;Without being able to sign my procedure, I don’t think this will work as P_Send_Mail_Test calls another procedure (namely sp_send_dbmail) from within it. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any information you might be able to give me would be most helpful.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Todd&lt;/P&gt;</description></item><item><title>re: SQL Server 2005: procedure signing demo</title><link>http://blogs.msdn.com/lcris/archive/2005/06/15/sql-server-2005-procedure-signing-demo.aspx#8848784</link><pubDate>Mon, 11 Aug 2008 21:42:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8848784</guid><dc:creator>lcris</dc:creator><description>&lt;p&gt;A private key is created whenever you create a certificate, but it has to be explicitly backed up (it's backed up separately from the certificate/public key). In my example, I removed the private key after signing the procedure with it, because I didn't need it for any other signature.&lt;/p&gt;
&lt;p&gt;In your example, you would want to grant permissions to the P_Send_Mail_Test code, so you should sign this procedure, not sp_send_dbmail.&lt;/p&gt;
&lt;p&gt;But the issue is a bit more complex, because what you are trying to do is to enable cross database access via signatures. That is a more complex example of signature use than what I showed in this post. For cross-database access, I have an example here: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/lcris/archive/2006/10/24/sql-server-2005-demo-for-enabling-database-impersonation-for-cross-database-access.aspx"&gt;http://blogs.msdn.com/lcris/archive/2006/10/24/sql-server-2005-demo-for-enabling-database-impersonation-for-cross-database-access.aspx&lt;/a&gt;. I used this example in the PASS presentation on execution context that you can find here: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/lcris/archive/2006/12/08/sql-server-2005-security-presentations-at-pass-pre-conference.aspx"&gt;http://blogs.msdn.com/lcris/archive/2006/12/08/sql-server-2005-security-presentations-at-pass-pre-conference.aspx&lt;/a&gt;. Have a look at these resources - there is also a very good BOL article on this topic that I also reference in the presentation: &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms188304.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms188304.aspx&lt;/a&gt;.&lt;/p&gt;
</description></item></channel></rss>