
SQL Server Permission Sets
SQL Server allows users to specify the reliability requirements for code deployed into a database. When assemblies are uploaded into the database, the author of the assembly can specify one of three permission sets for that assembly: SAFE, EXTERNAL-ACCESS, or UNSAFE.
Permission set
|
SAFE
|
EXTERNAL-ACCESS
|
UNSAFE
|
|---|
Code access security
|
Execute only
|
Execute + access to external resources
|
Unrestricted
|
Programming model restrictions
|
Yes
|
Yes
|
No restrictions
|
Verifiability requirement
|
Yes
|
Yes
|
No
|
Ability to call native code
|
No
|
No
|
Yes
|
SAFE is the most reliable and secure mode with associated restrictions in terms of the allowed programming model. SAFE code has high reliability and security features. SAFE assemblies are given enough permission to run, perform computations, and have access to the local database. SAFE assemblies need to be verifiably type safe and are not allowed to call unmanaged code.
EXTERNAL-ACCESS provides an intermediate security option, allowing code to access resources external to the database but still having the reliability and safety of SAFE.
UNSAFE is for highly trusted code that can only be created by database administrators. This trusted code has no code access restrictions, and it can call unmanaged (native) code.
SQL Server uses the host-level code access security policy layer to set up a host policy that grants one of the three sets of permissions based on the permission set stored in SQL Server catalogs. Managed code running inside the database always gets one of these code access permission sets.