DATABASE

SQL Server 2012 : Exploring SQL CLR - Security

11/25/2013 8:33:39 PM

Depending on the deployment method, you have numerous ways to specify what security level to grant a CLR assembly. All of them demand that you specify one of three permission sets:

  • Safe Assembly can perform local data access and computational tasks only.

  • External_Access Assembly can perform local data access and computational tasks and also access the network, the file system, the registry, and environment variables. Although External_Access is less restrictive than Safe, it still safeguards server stability.

  • Unsafe Assembly has unrestricted permissions and can even call unmanaged code. This setting can significantly compromise SQL Server security; only members of the sysadmin role can create (load) unsafe assemblies. Also note the TRUSTWORTHY property must be set to ON for the database into which the unsafe assembly will be loaded, and the dbo must have UNSAFE ASSEMBLY permission (or the assembly must be specially signed). There is commented code at the top of the CreateObjects.sql script that sets the TRUSTWORTHY property to ON for the AdventureWorks2012 database.

When you deploy an assembly from Visual Studio, its security level is set to Safe by default. To change it, double-click the Properties node in the Solution Explorer, click the SQLCLR tab in the resulting property sheet designer and then select SAFE, EXTERNAL_ACCESS, or UNSAFE from the Permission Level combo box, as shown in Figure 1.

Selecting an assembly permission level in the SQLCLR property sheet tab.

Figure 1. Selecting an assembly permission level in the SQLCLR property sheet tab.

To specify an assembly’s permission set using T-SQL, simply specify SAFE, EXTERNAL_ACCESS, or UNSAFE within the “WITH PERMISSION_SET” clause of the CREATE ASSEMBLY statement. Recall that our example used the default SAFEsetting in this clause.

Finally, in the SSMS New Assembly dialog box and the Assembly Properties dialog box, you can select Safe, External Access, or Unrestricted from the Permission Set combo box. The last of these three options is equivalent to selecting the UNSAFE permission set in Visual Studio or T-SQL.

Other  
  •  SQL Server 2012 : Exploring SQL CLR - SQL CLR Types
  •  SQL Server 2012 : Exploring SQL CLR - CLR Aggregates
  •  SQL Server 2012 : Exploring SQL CLR - CLR Triggers
  •  My SQL : Replication for High Availability - Procedures (part 8) - Circular Replication
  •  My SQL : Replication for High Availability - Procedures (part 7) - Slave Promotion - Slave promotion in Python
  •  My SQL : Replication for High Availability - Procedures (part 6) - Slave Promotion - A revised method for promoting a slave
  •  My SQL : Replication for High Availability - Procedures (part 5) - Semisynchronous Replication - Configuring semisynchronous replication
  •  My SQL : Replication for High Availability - Procedures (part 4) - Dual Masters - Replicated disks using DRBD , Bidirectional replication
  •  My SQL : Replication for High Availability - Procedures (part 3) - Dual Masters - Shared disks
  •  My SQL : Replication for High Availability - Procedures (part 2) - Hot Standby
  •  
    Top 10
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    3 Tips for Maintaining Your Cell Phone Battery (part 1) - Charge Smart
    OPEL MERIVA : Making a grand entrance
    FORD MONDEO 2.0 ECOBOOST : Modern Mondeo
    BMW 650i COUPE : Sexy retooling of BMW's 6-series
    BMW 120d; M135i - Finely tuned
    PHP Tutorials : Storing Images in MySQL with PHP (part 2) - Creating the HTML, Inserting the Image into MySQL
    PHP Tutorials : Storing Images in MySQL with PHP (part 1) - Why store binary files in MySQL using PHP?
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS