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
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 :-).
SQL# - http://www.SQLsharp.com/