Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies) Expand / Collapse
Author
Message
Posted Monday, August 25, 2014 11:01 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 11:31 PM
Points: 370, Visits: 1,971
Comments posted to this topic are about the item Stairway to SQLCLR Level 4: Security (EXTERNAL and UNSAFE Assemblies)




SQL# - http://www.SQLsharp.com/
Post #1607141
Posted Wednesday, September 10, 2014 12:06 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, September 12, 2014 6:00 AM
Points: 31, Visits: 60
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.
Post #1612338
Posted Wednesday, September 10, 2014 1:08 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 11:31 PM
Points: 370, Visits: 1,971
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/
Post #1612356
Posted Wednesday, September 10, 2014 1:18 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, September 12, 2014 6:00 AM
Points: 31, Visits: 60
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.
Post #1612358
Posted Thursday, September 11, 2014 1:58 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 11:31 PM
Points: 370, Visits: 1,971
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/
Post #1612808
Posted Friday, September 12, 2014 2:44 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 10:14 AM
Points: 2,916, Visits: 1,852
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
Post #1613164
Posted Sunday, September 14, 2014 9:49 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 11:31 PM
Points: 370, Visits: 1,971
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/
Post #1613464
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse