Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies)


Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies)

Author
Message
Solomon Rutzky
Solomon Rutzky
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 2934
Comments posted to this topic are about the item Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies)

SQL# - http://www.SQLsharp.com/
copling
copling
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 78
Mr. Solomon, I really enjoyed your article in regards to External and Unsafe security framework for SQLCLR. I've really been interested in utilizing the power that this piece of technology possess. I do however, one question: Is it possible for a SQLCLR to be built with an external dll? For example, let's say I have a dll that receives data and creates an excel file. Can I reference that dll from within my SQLCLR and pass in the necessary parameters to it's methods and to build that file? I would assume if so, the security for your SQLCLR would have to run under EXTERNAL or UNSAFE. Again, thanks for the great article.
Solomon Rutzky
Solomon Rutzky
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 2934
copling (9/10/2014)
Mr. Solomon, I really enjoyed your article in regards to External and Unsafe security framework for SQLCLR. I've really been interested in utilizing the power that this piece of technology possess. I do however, one question: Is it possible for a SQLCLR to be built with an external dll? For example, let's say I have a dll that receives data and creates an excel file. Can I reference that dll from within my SQLCLR and pass in the necessary parameters to it's methods and to build that file? I would assume if so, the security for your SQLCLR would have to run under EXTERNAL or UNSAFE. Again, thanks for the great article.


Hi there. Thanks and I am glad that you liked the article :-).

Regarding the external DLL, I have not tried that specifically. I believe you will need to load it into SQL Server with a PERMISSION_SET of UNSAFE (but you should try EXTERNAL_ACCESS first, just in case it works). In your project, you would add the reference and "using" statement. That DLL will be able to save the Excel file to the file system.

If you are going to do the preferred method of the Asymmetric Key and Login in order to be able to set the 3rd party Assembly to UNSAFE (or even EXTERNAL_ACCESS), you will need to sign it with the same private key (i.e. pfx file) that are using to sign the Assembly that has the SqlProcedure.

Take care,
Solomon...

SQL# - http://www.SQLsharp.com/
copling
copling
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 78
Thanks a bunch. I greatly appreciate the advice. By the way, you did a great presentation at this past SQL Saturday in Raleigh. Good stuff. Take care.
Solomon Rutzky
Solomon Rutzky
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 2934
copling (9/10/2014)
Thanks a bunch. I greatly appreciate the advice. By the way, you did a great presentation at this past SQL Saturday in Raleigh. Good stuff. Take care.


No problem. If you need further help with that particular issue, post a question to the CLR Integration and Programming Forum here on SQL Server Central.

And thank you for that compliment regarding my presentation and thanks for attending it. Nobody filled out the eval forms (or if they did then I did not get them) so I left that presentation thinking that I had not done all that well since it was the first time I was giving it and some of the slides needed to be finished and some demos needed to be polished up a bit. So I am glad to hear that I did get through to the audience :-).

Take care,
Solomon..

SQL# - http://www.SQLsharp.com/
David.Poole
David.Poole
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3617 Visits: 3110
I had a lot of fun reading the drafts of these articles and they both opened my eyes and dispelled quite a few misconceptions.

I wish I had known everything that was in these articles a long time ago as I would have pushed the use of SQLCLR much harder.

The stuff about Host Protection Attributes, shared memory and the implications of External access reassured me greatly. My worries that SQLCLR is a great big server destabilising security leak has largely been dispelled. Obviously it is possible to write something stupid and highly inefficient but that is just as possible in T-SQL as it is in C#/VB. In fact, using the geographic data types and methods can throw frightening errors but I haven't seen it bring down a server yet.

LinkedIn Profile

Newbie on www.simple-talk.com
Solomon Rutzky
Solomon Rutzky
SSChasing Mays
SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)SSChasing Mays (655 reputation)

Group: General Forum Members
Points: 655 Visits: 2934
David.Poole (9/12/2014)
I had a lot of fun reading the drafts of these articles and they both opened my eyes and dispelled quite a few misconceptions.

I wish I had known everything that was in these articles a long time ago as I would have pushed the use of SQLCLR much harder.

The stuff about Host Protection Attributes, shared memory and the implications of External access reassured me greatly. My worries that SQLCLR is a great big server destabilising security leak has largely been dispelled. Obviously it is possible to write something stupid and highly inefficient but that is just as possible in T-SQL as it is in C#/VB. In fact, using the geographic data types and methods can throw frightening errors but I haven't seen it bring down a server yet.


Hi David. Thank you for the compliment and for sharing what you got out of these two "Security" articles. I feel it is important to make sure that people have accurate information and understanding to base their decisions and designs on. If people don't want to use SQLCLR then that is certainly fine, but it should be due to valid reasons instead of commonly propagated misinformation. But in terms of extending the capabilities of SQL Server, SQLCLR is far better than Extended Stored Procedures and the sp_OA* OLE Automation procedures. SQLCLR is certainly more secure than those other choices, including SQLCMD. The mere ability to do Impersonation allows for a more consistent approach to Windows security for the sys admins; they don't need to create exceptions for the Log On account of the SQL Server service.

But just to be perfectly clear about the wording here: outside of the performance concern (which as you pointed out, is just as easy to do poorly in pure T-SQL), it certainly is possible to do stuff in EXTERNAL_ACCESS and UNSAFE that can destabilize the system or allow for security-related issues. The point is that the DBA has a good degree of control:

  • enabling "CLR Integration" does not automatically open up the system to all types of functionality: a SAFE assembly cannot reach outside of SQL Server. This allows for doing string functions (e.g. Regular Expressions, etc), math functions, and other types of operations without also allowing network and file system access. The OLE Automation procedures (i.e. sp_OA*), on the other hand, do not make such a distinction.

  • the DBA can limit (to a degree) what can be done if reaching outside of SQL Server: EXTERNAL_ACCESS allows file system access, network access, and reading from the Registry without allowing untrusted / unmanaged / non-verified code or writing to the Registry or executing any random DOS / Windows program.




And thank you again for reviewing the articles. Your time and help is greatly appreciated, and the articles have definitely benefited from your suggestions :-).

Take care,
Solomon...

SQL# - http://www.SQLsharp.com/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search