<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Laurentiu Cristofor's blog @microsoft.com : basic SQL Server security concepts</title><link>http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx</link><description>Tags: basic SQL Server security concepts</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Basic SQL Server Security concepts: ownership, CONTROL, TAKE OWNERSHIP</title><link>http://blogs.msdn.com/lcris/archive/2009/08/11/basic-sql-server-security-concepts-ownership-control-take-ownership.aspx</link><pubDate>Wed, 12 Aug 2009 01:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9865191</guid><dc:creator>lcris</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/lcris/comments/9865191.aspx</comments><wfw:commentRss>http://blogs.msdn.com/lcris/commentrss.aspx?PostID=9865191</wfw:commentRss><description>&lt;P&gt;I realized today that while I have discussed earlier object&amp;nbsp;&lt;A href="http://blogs.msdn.com/lcris/archive/2007/09/12/basic-sql-server-security-concepts-permissions-and-special-principals-sa-dbo-guest.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2007/09/12/basic-sql-server-security-concepts-permissions-and-special-principals-sa-dbo-guest.aspx"&gt;permissions&lt;/A&gt;, I have not gone into the details of object ownership.&amp;nbsp;I want to cover the following here: ownership of objects,&amp;nbsp;how it can be changed, and the relatively new permission CONTROL (introduced in SQL Server 2005).&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Ownership:&lt;/STRONG&gt; This should&amp;nbsp;be&amp;nbsp;pretty clear - the owner of an object is usually its creator, but a different owner can be&amp;nbsp;specified at creation time using the AUTHORIZATION clause. The owner of an object has all possible permissions on that object and, most importantly, cannot be denied those permissions while he continues to be an owner.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;CONTROL permission:&lt;/STRONG&gt; The CONTROL permission can be used to easily grant all permissions on an entity to some principal. It's the next best thing after ownership of the entity, but it's not quite as powerful as ownership. The main difference is that a grantee of CONTROL can still be denied some other permissions on the entity. For example, I can be granted CONTROL on a table, while at the same time I can be denied SELECT on that table, preventing me from selecting from it - this can never happen to the owner, because the owner cannot be granted or denied permissions.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Changing ownership:&lt;/STRONG&gt; &amp;nbsp;To change the owner of an entity, we can use the &lt;A href="http://msdn.microsoft.com/en-us/library/ms187359.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms187359.aspx"&gt;ALTER AUTHORIZATION&lt;/A&gt; statement. Changing ownership of an object creates some interesting scenarios in terms of what should be allowed and what should not be. Basically, owners should not be able to "dump" their objects to other users who may not want them and users should not be able to "steal" objects from those that own them. To accomplish this, two&amp;nbsp;checks are needed: one controls to whom&amp;nbsp;ownership can be given&amp;nbsp;to - we verify that the performer of the change has some right on the new owner (we check for IMPERSONATE for users and logins, ALTER or membership for roles, etc);&amp;nbsp;the other&amp;nbsp;check controls from whom&amp;nbsp;ownership can be taken away: we require the performer of the change to have TAKE OWNERSHIP permission on the object.&lt;/P&gt;
&lt;P&gt;Note&amp;nbsp;as a corollary that a grantee of CONTROL permission on an object has the ability to take ownership of the object&amp;nbsp;because CONTROL implies the TAKE OWNERSHIP permission as well - the way to prevent this would be to grant CONTROL and deny TAKE OWNERSHIP.&lt;/P&gt;
&lt;P&gt;TAKE OWNERSHIP is thus used to &lt;EM&gt;selectively&lt;/EM&gt; grant someone the ability to &lt;EM&gt;willingly&lt;/EM&gt; become the owner of an object or to facilitate the change of ownership of that object.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Side effect of ownership change:&lt;/STRONG&gt; A potentially surprising side effect of changing ownership of an object is that all permissions granted on that object will be lost. As always, it's a good idea to script all permissions granted on an entity before changing its ownership, so that the grants can be re-executed by the new owner, if appropriate.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9865191" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server+-+security/default.aspx">SQL Server - security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/lcris/archive/tags/computer+security/default.aspx">computer security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx">basic SQL Server security concepts</category></item><item><title>Basic SQL Server Security concepts: SIDs, orphaned users, and loginless users</title><link>http://blogs.msdn.com/lcris/archive/2007/10/25/basic-sql-server-security-concepts-sids-orphaned-users-and-loginless-users.aspx</link><pubDate>Fri, 26 Oct 2007 03:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5683564</guid><dc:creator>lcris</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/lcris/comments/5683564.aspx</comments><wfw:commentRss>http://blogs.msdn.com/lcris/commentrss.aspx?PostID=5683564</wfw:commentRss><description>&lt;P&gt;I am grouping here two topics (orphaned users and&amp;nbsp;loginless users)&amp;nbsp;that are actually very different, but I have often seen confusion between them, so I am covering them together in an attempt to dispel that confusion.&lt;/P&gt;
&lt;P&gt;In a &lt;A class="" href="http://blogs.msdn.com/lcris/archive/2007/03/23/basic-sql-server-security-concepts-logins-users-and-principals.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2007/03/23/basic-sql-server-security-concepts-logins-users-and-principals.aspx"&gt;previous discussion&lt;/A&gt; of logins and users, I pointed out that the way a login gets mapped to users in databases is via&amp;nbsp;its SID value. This mapping is a one to many mapping - a login maps to several users (each one in a different database), but a user maps back to a single login.&amp;nbsp;When a Windows login is created,&amp;nbsp;its SID value is taken to be the SID of the corresponding Windows principal, but for&amp;nbsp;SQL Server specific logins the SID values are generated at creation time, unless they are explicitly provided via the SID clause of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189751.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189751.aspx"&gt;CREATE LOGIN&lt;/A&gt;. The SID value represents the identity of the login and is invariant for the life of the login - this is why the SID clause is not available for &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx"&gt;ALTER LOGIN&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The SID link between a login and a user&amp;nbsp;can be severed&amp;nbsp;when databases are moved from one server to another - this is because on the new server, there may be no login having the same SID as that user. When such a situation happens, we say that&amp;nbsp;the user was &lt;EM&gt;orphaned&lt;/EM&gt; - it becomes an &lt;EM&gt;orphan user&lt;/EM&gt;. Orphan users can also result from the deletion of a login - in previous versions, SQL Server attempted to warn about the existence of corresponding users, but even that check would fail to detect users in databases that were offline, so SQL Server 2005 no longer performs&amp;nbsp;it&amp;nbsp;(it was also an expensive check, as it required accessing each database). The bottom line is that orphaned users can appear in various ways and we have to either&amp;nbsp;fix them when they occur or we have to&amp;nbsp;prevent&amp;nbsp;them from occurring at all. The&amp;nbsp;classic method for restoring the SID link&amp;nbsp;was to use the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx"&gt;sp_change_users_login&lt;/A&gt; procedure, but starting with SQL Server 2005 SP2, a new LOGIN clause of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms176060.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms176060.aspx"&gt;ALTER USER&lt;/A&gt; has also been made available, which helps fix Windows&amp;nbsp;users in addition to SQL users - a feature that sp_change_users_login was lacking. These methods will fix the SID of a user to match that of a login, effectively remapping the user to&amp;nbsp;match the login.&amp;nbsp;For the preventive approach, the main tool we have available is to create logins with an explicit SID value - this will help when moving a database between two or more&amp;nbsp;servers, by allowing&amp;nbsp;us to create in advance SQL Server logins that not only have&amp;nbsp;the same name, but&amp;nbsp;the same SID value as well. This will also help with recreating a login that was inadvertently dropped.&lt;/P&gt;
&lt;P&gt;Some people seem to think that having the possibility to change a login's SID to match that of a user&amp;nbsp;would be a great&amp;nbsp;feature. That is not true. Changing a login's SID would be wrong because it would attack the problem on the wrong side of the login-user relationship. When fixing the user SID, only that SID needs to be changed and this would be a database scoped operation, but when fixing a login SID, all corresponding user SIDs would have to be changed as well, otherwise we would generate more orphaned users instead of fixing them - and fixing all users mapped to a login isn't a task that can be easily performed,&amp;nbsp;because it would require the availability of all databases in which the login is mapped - something that cannot be guaranteed. There is a good reason why this issue is referred to as orphaned users and not as childless logins.&lt;/P&gt;
&lt;P&gt;So, orphaned users are an issue that normally&amp;nbsp;requires some fixing, when it occurs. Loginless users, on the other hand, are an intentional construct. They are created using the WITHOUT LOGIN clause of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx"&gt;CREATE USER&lt;/A&gt;&amp;nbsp;and they represent standalone users that &lt;STRONG&gt;cannot&lt;/STRONG&gt; map to a login (they have special&amp;nbsp;SID values preventing this), so you cannot connect to a database as a loginless user, although you can impersonate one via EXECUTE AS.&amp;nbsp;A loginless user is valuable in many situations where an application needs to have users that don't necessarily&amp;nbsp;correspond to a human user. For example, an application may be in need to create objects from time to time and to designate an owner for them - it could do this in the caller's context, but that would mean the caller would end up owning objects he may not be aware of - it is better for the application to designate a loginless user as the owner of those objects. One of my favorite uses of loginless users is to break ownership chains (see &lt;A class="" href="http://blogs.msdn.com/lcris/archive/2007/09/13/basic-sql-server-security-concepts-ownership-chaining-good-and-evil-schemas.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2007/09/13/basic-sql-server-security-concepts-ownership-chaining-good-and-evil-schemas.aspx"&gt;previous discussion&lt;/A&gt;) by&amp;nbsp;assigning different loginless users as owners. Raul has a &lt;A class="" href="http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx" mce_href="http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx"&gt;lengthier&amp;nbsp;post&lt;/A&gt; on the topic of loginless users that offers&amp;nbsp;further examples of use, including some TSQL sample code.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5683564" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server+-+security/default.aspx">SQL Server - security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/lcris/archive/tags/computer+security/default.aspx">computer security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx">basic SQL Server security concepts</category></item><item><title>Basic SQL Server Security concepts - ownership chaining: good and evil; schemas</title><link>http://blogs.msdn.com/lcris/archive/2007/09/13/basic-sql-server-security-concepts-ownership-chaining-good-and-evil-schemas.aspx</link><pubDate>Thu, 13 Sep 2007 21:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4903283</guid><dc:creator>lcris</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/lcris/comments/4903283.aspx</comments><wfw:commentRss>http://blogs.msdn.com/lcris/commentrss.aspx?PostID=4903283</wfw:commentRss><description>&lt;P&gt;At some point during SQL Server's history,&amp;nbsp;its designers must have confronted the following problem: how to give someone permission to see&amp;nbsp;parts of a table without giving him any permission on the table? Slices of a table are easily&amp;nbsp;defined using views, so the problem becomes one of giving SELECT permission&amp;nbsp;on a view without&amp;nbsp;granting&amp;nbsp;a SELECT&amp;nbsp;permission on the underlying table as well. Normally, the SELECT permission on the view alone is not sufficient, because the system would check permissions once when you select from the view and a second time when the view makes reference to the underlying table, so the second check would fail if the user has no permission on the table. The solution provided for this problem in SQL Server is &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188676.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188676.aspx"&gt;ownership chaining&lt;/A&gt;. Ownership chaining, or OC for short, will bypass the permission check that would be done when the view is referencing the table,&amp;nbsp;&lt;STRONG&gt;if&lt;/STRONG&gt; the owner of the view is the same as the owner of the table. Intuitively, this makes sense as the intention of the owner in granting SELECT on the view&amp;nbsp;must have been made&amp;nbsp;so that the user would be able to actually select from that view. This mechanism has then been extended beyond this simple example involving a view and a table - the same would hold, for example, if a procedure would use a view that would refer to a table and the caller only had EXECUTE permission on the procedure and no permissions on the view or table. This idea has&amp;nbsp;proliferated so that it&amp;nbsp;resulted in the extension of OC to work across databases - the so-called &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188694.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188694.aspx"&gt;cross-database ownership chaining&lt;/A&gt; (CDOC). CDOC is a topic that goes beyond what I want to cover in this post, so I'll only mention that these days it is disabled by default and it's a good idea to leave it like that.&lt;/P&gt;
&lt;P&gt;So, OC provides a simple way to provide restricted access to objects and simplifies permission management. This sounds like a lot of good stuff. However, to achieve this, OC is bypassing permission checks completely, which means, of course, that it can bypass denies as well. I can deny someone access to a table and I might think that this prevents him from accessing that table, ever&amp;nbsp;- I would be wrong however, as he might still access the table through OC. Ok, you'll say, but then I'm&amp;nbsp;paying the price&amp;nbsp;because I must have granted him access to a view or procedure that I own and which accesses the table. This is true, but is only true in an ideal world where people follow good practices and are aware of all the consequences of their actions -&amp;nbsp;sadly, this is not our world. The bad aspect of OC is the fact that it weakens the semantics of a deny. A deny should have meant that in no way could&amp;nbsp;a user&amp;nbsp;perform the action that he is denied while the deny is in effect. OC represents an exception to this rule and exceptions to security principles are the root of evil.&lt;/P&gt;
&lt;P&gt;All good security principles are often ignored in practice. One principle I often see ignored in the SQL Server world is the principle of executing with minimum privileges. It's often the case that people create objects as&amp;nbsp;sysadmins and when they do that, who will be the owner of the object? dbo, of course. Soon enough, most objects are owned by dbo - see where I'm going with this? Having all objects be owned by dbo means OC chaining is rampant in the database. It's easy now for unintended OC to grant wrong access, especially in view of multiple users mapping to dbo. Because OC cannot be turned off (I wish there would be a&amp;nbsp;database setting&amp;nbsp;to do that), you must always be mindful of OC when you are designing your database and deciding the ownership of entities in it.&lt;/P&gt;
&lt;P&gt;Let's look at schemas now.&amp;nbsp;Similar to how&amp;nbsp;databases can be used to separate applications in a server, schemas provide a further level of separation within a database. In SQL 2000, schemas were equated to users - schemas didn't really exist as distinct entities, but it was assumed that each user had a corresponding schema. This&amp;nbsp;allowed referring&amp;nbsp;to objects using a user name in&amp;nbsp;place of a schema, as&amp;nbsp;when saying:&amp;nbsp;db1.&lt;STRONG&gt;alice&lt;/STRONG&gt;.proc. In SQL Server 2005, schemas became actual objects acting as containers of&amp;nbsp;other basic entities, like procedures, views, tables, etc. To keep backward compatibility with existing use, when creating a user&amp;nbsp;with old procedures such as &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms181422.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms181422.aspx"&gt;sp_adduser&lt;/A&gt;, both a user and a schema named after it are created and the schema&amp;nbsp;will be&amp;nbsp;owned by that user; when using the new DDL, however, &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx"&gt;CREATE USER&lt;/A&gt; would only create the user and if a schema is desired as well, it would have to be explicitly created using &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189462.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189462.aspx"&gt;CREATE SCHEMA&lt;/A&gt;. The owner of a schema&amp;nbsp;will be&amp;nbsp;the default owner of all objects within&amp;nbsp;that schema (in this case, the &lt;EM&gt;principal_id&lt;/EM&gt; column of the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms190324.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms190324.aspx"&gt;sys.objects&lt;/A&gt; row for&amp;nbsp;such objects will be marked as NULL). It is possible, however, to change the ownership of individual objects in a schema to&amp;nbsp;other principals than the schema owner&amp;nbsp;(in this case the &lt;EM&gt;principal_id&lt;/EM&gt; column would indicate the effective owner). You can read more about schemas in &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms190387.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms190387.aspx"&gt;this BOL article&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The reason I grouped these topics together is because both are related to object ownership. OC permits a bypassing of permission checks in references made by one object to another and schemas provide a way to specify an owner for a large collection of objects. For schemas to be effective at separating access to objects,&amp;nbsp;because of OC, they should be owned by different principals. It would be a mistake to allow all schemas in the database to be owned by dbo, for an extreme example.&lt;/P&gt;
&lt;P&gt;Today, the problem for which OC constitued a solution can be resolved in other ways. With the introduction of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms345102.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms345102.aspx"&gt;module signing&lt;/A&gt; in SQL Server 2005, it is now possible to associate permissions with a module, which allows more granular access control than OC could provide. But OC is always on by default and must be kept in mind at all times to prevent undesired side-effects from its existence. To mitigate such undesired side-effect, keep OC in mind when deciding the ownership of entities in your database. In particular, do not setup your database such that all objects are owned by dbo. Keep in mind that SQL Server 2005 allows you now to create users that are database scoped - the loginless users created via &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx"&gt;CREATE USER...WITHOUT LOGIN&lt;/A&gt;&amp;nbsp;- these types of users are perfect for breaking ownership chains in a database.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4903283" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server+-+security/default.aspx">SQL Server - security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/lcris/archive/tags/computer+security/default.aspx">computer security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx">basic SQL Server security concepts</category></item><item><title>Basic SQL Server Security concepts - permissions and special principals: sa, dbo, guest</title><link>http://blogs.msdn.com/lcris/archive/2007/09/12/basic-sql-server-security-concepts-permissions-and-special-principals-sa-dbo-guest.aspx</link><pubDate>Thu, 13 Sep 2007 01:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4886214</guid><dc:creator>lcris</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/lcris/comments/4886214.aspx</comments><wfw:commentRss>http://blogs.msdn.com/lcris/commentrss.aspx?PostID=4886214</wfw:commentRss><description>&lt;P&gt;In&amp;nbsp;a &lt;A class="" href="http://blogs.msdn.com/lcris/archive/2007/03/23/basic-sql-server-security-concepts-logins-users-and-principals.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2007/03/23/basic-sql-server-security-concepts-logins-users-and-principals.aspx"&gt;previous post&lt;/A&gt;, I talked about the various types of &lt;EM&gt;principals&lt;/EM&gt; in SQL Server. Let's have a further look in this post at permissions and at some of the hardcoded principals that ship with any installation of SQL Server.&lt;/P&gt;
&lt;P&gt;Permissions are what allow principals (logins, users, roles, etc)&amp;nbsp;to perform&amp;nbsp;(or not perform)&amp;nbsp;activities in SQL Server. Permissions are managed through three operations: &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188371.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188371.aspx"&gt;grant&lt;/A&gt;, &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173724.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173724.aspx"&gt;deny&lt;/A&gt;, and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms187719.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms187719.aspx"&gt;revoke&lt;/A&gt;&amp;nbsp;(or GDR for short). A &lt;EM&gt;grant&lt;/EM&gt; specifies that a principal (the &lt;EM&gt;grantee&lt;/EM&gt;) is allowed to perform a specific operation; a &lt;EM&gt;deny&lt;/EM&gt; specifies the reverse - that the principal (still referred to as grantee) should not be capable of performing a specific operation; finally, a &lt;EM&gt;revoke&lt;/EM&gt; is simply a mechanism for erasing any previous grants or denies. The person that performs a GDR operation is referred to as the &lt;EM&gt;grantor&lt;/EM&gt;, regardless of the type of operation (i.e. the grantor may perform a deny). All GDR operations have three main parts: they specify a permission name, a grantee name&amp;nbsp;(the subject of the GDR operation), and optionally an entity name on which the permission takes effect (the &lt;EM&gt;securable&lt;/EM&gt; -&amp;nbsp;the object of the GDR operation). The securable is optional because in some cases it is implied by the permission. Sounds complicated? Let's walk through an example. Let's say Alice grants Bob the SELECT permission on table t. She would do this with a statement like:&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;grant&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;SELECT&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;on&lt;/FONT&gt;&lt;FONT size=2&gt; t &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;to&lt;/FONT&gt;&lt;FONT size=2&gt; Bob&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;In this operation, Alice is the grantor (because she executes the statement), Bob is the grantee, SELECT is the permission name, and t is the securable - the object on which the SELECT permission is granted.&lt;/P&gt;
&lt;P&gt;Depending on the scope of the securable, the permission granted is either a server permission or a database permission.&amp;nbsp;When a server permission is GDRed, the securable is implicitly the server and it is not specified in the GDR statement.&amp;nbsp;Grants and denies of server permissions are recorded in the catalog &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms186260.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms186260.aspx"&gt;sys.server_permissions&lt;/A&gt;; grants and denies of database permissions are recorded in &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188367.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188367.aspx"&gt;sys.database_permissions&lt;/A&gt;. Of course, a server permission can only be granted to a server principal and a database permission to a database principal (in the above example, Alice and Bob are users; if they would be only logins, without any corresponding users of the same&amp;nbsp;names, the statement would be invalid).&amp;nbsp;Also note that revokes, because they act as an eraser, are not recorded anywhere - they are just removing entries from these catalogs! The revoke operation is often misunderstood, but the simplest way to think about it is that is an eraser of grants or denies.&lt;/P&gt;
&lt;P&gt;All this information gives you a good basic understanding of the permissions system. There is only one more rule that you should keep in mind at all times: &lt;STRONG&gt;denies prevail over grants&lt;/STRONG&gt;. What this means is that if I am a member of two roles, one of which is granted a permission and one of which is denied that same permission, the end result is that the permission is denied to me, because the deny will take precedence over the grant. A caveat here: there is a&amp;nbsp;special case&amp;nbsp;when permission checks are completely bypassed - &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188676.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188676.aspx"&gt;ownership chaining&lt;/A&gt;, which can allow a principal to access an object despite&amp;nbsp;that principal&amp;nbsp;being denied&amp;nbsp;access to&amp;nbsp;it.&amp;nbsp;I'll comment on ownership chaining in&amp;nbsp;a future post.&lt;/P&gt;
&lt;P&gt;With the basics of permissions understood, let's look at&amp;nbsp;some special SQL Server principals. The most notorious SQL Server login must be &lt;STRONG&gt;sa&lt;/STRONG&gt;. sa is a SQL login administrator account that can be used if mixed authentication is enabled on SQL Server. sa has been infamous due to most people&amp;nbsp;using weak&amp;nbsp;passwords&amp;nbsp;for it (often an empty password)&amp;nbsp;and thus making their systems vulnerable to any attacker that could attempt a connection. The sa login is hardcoded to be a member of the &lt;STRONG&gt;sysadmin&lt;/STRONG&gt; server role. sa and sysadmin membership should be regarded as representing ownership of the server system - they are the pinnacle of power in the SQL Server world! This means that the sa password should be chosen to be a strong password and that membership in the sysadmin role should not be granted around freely. sa is so powerful that you can't even&amp;nbsp;deny him permissions. Because sa is builtin, most attackers are always attempting to break into this account first. SQL Server 2005 has added a number of new features that you can use to defend this account better from attacks:&lt;/P&gt;
&lt;P&gt;1) If you don't use sa but you want to use SQL Authentication (if you don't want to use SQL authentication, you can just restrict authentication to Windows only mode), then you can disable sa using the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx"&gt;ALTER LOGIN ... DISABLE&lt;/A&gt; command. A disabled login cannot be used for gaining access to SQL Server until it is enabled back again.&lt;/P&gt;
&lt;P&gt;2) If you use sa, you should make sure that you keep password policy checks enforced for that account (this is the default behavior and something that you should keep for any login). Note that password policy checks can only be enforced if your OS is Windows 2003 or Windows Vista. Password policy checks will increase the difficulty of someone figuring out your password through brute force.&lt;/P&gt;
&lt;P&gt;3) If you notice frequent failed attempts to connect as sa, you can rename the sa account - this will stop outright those attackers, because they'll now have to first figure out the name of a valid login to attack. You can rename sa using the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189828.aspx"&gt;ALTER LOGIN ... WITH NAME&lt;/A&gt; statement.&lt;/P&gt;
&lt;P&gt;The next famous and often misunderstood principal is the database user &lt;STRONG&gt;dbo&lt;/STRONG&gt;. I discussed about how users are mapped to logins via their SID values. The same holds for dbo, except the mapping of dbo is not done at user creation - dbo always exists since the database was created; instead, the login to which dbo maps is determined by what login&amp;nbsp;is the owner of the database - dbo will always map to the login that is marked as the database owner. Here's a query that can be used to find who&amp;nbsp;is the owner of&amp;nbsp;the current database:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;select&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;suser_sname&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;sid&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;sys.database_principals&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;where&lt;/FONT&gt;&lt;FONT size=2&gt; principal_id &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;user_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'dbo'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;The way to change the mapping of dbo to a login is by changing the database ownership. This can be done via &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms178630.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms178630.aspx"&gt;sp_changedbowner&lt;/A&gt; or using the newer syntax of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms187359.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms187359.aspx"&gt;ALTER AUTHORIZATION&lt;/A&gt;. The owner of a database is also recorded in sys.databases; however, this information can become stale when moving a database from one system to another - to fix a stale entry you can always reissue a database ownership change command. The above query returning NULL, for example, would be an indication that the database was brought from another server where it was owned by a principal that doesn't exist in the current server.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The dbo denomination exists&amp;nbsp;so that, within each database, the most powerful principal is clearly known. Same as sa was built in at server level, dbo is&amp;nbsp;its database counterpart. Like sa, dbo is the most powerful user in a database and no permissions can be denied to him. dbo is a member of the &lt;STRONG&gt;db_owner&lt;/STRONG&gt; database role, and these represent the equivalent of the sa/sysadmin pair&amp;nbsp;at the database level. A&amp;nbsp;final important note is that sa and sysadmin members will always map to dbo, regardless of what login is set as the database owner. Thus, dbo is a fuzzy concept that doesn't clearly identify a single principal mapped to it.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next stop is&amp;nbsp;&lt;STRONG&gt;guest&lt;/STRONG&gt;; guest is a database user that was meant as a way to provide anonymous access to any database. This kind of access is however unrecommended and these days guest is disabled in all databases except some system databases. If guest is enabled, it basically allows any login that is not explicitly mapped in the database to a user, to connect to the database as guest (otherwise, the login would not be able to connect, unless sysadmin, database owner,&amp;nbsp;etc). There is little point in allowing this kind of anonymous access, so by default, in user databases, guest is not granted connect permission, which effectively disables it. Note that it is not possible to effectively remove guest from&amp;nbsp;a database - it cannot be dropped and attempting to drop it will just issue a REVOKE CONNECT command. You can check the permissions assigned to guest using the following query:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;select&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; permission_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; state_desc&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;object_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;major_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; securable&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;user_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;grantor_principal_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; grantor &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;sys.database_permissions&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;where&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; grantee_principal_id &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;user_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'guest'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#000000&gt;Finally, to conclude this post, let's look at the &lt;STRONG&gt;public&lt;/STRONG&gt; roles. There is a new public server role in SQL Server 2005, in addition to the public database role that existed earlier. Any server principal is implicitly&amp;nbsp;a member of the public server role and any database principal is implicitly&amp;nbsp;a member of the public database role. I say implicitly because the memberships are hardcoded in the system and they do not appear in the catalogs, nor can they be modified. These roles&amp;nbsp;allow a simple mechanism to&amp;nbsp;GDR permissions to every&amp;nbsp;principal at&amp;nbsp;server or database scope; you can think of them as meaning "everyone".&amp;nbsp;The&amp;nbsp;permissions associated with the public database role can be checked using the&amp;nbsp;previous query,&amp;nbsp;after&amp;nbsp;replacing 'guest'&amp;nbsp;with 'public'. For querying the public server role permissions,&amp;nbsp;you can use the following&amp;nbsp;query:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#000000&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;
&lt;P&gt;select&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; permission_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; state_desc&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;suser_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt;grantor_principal_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; grantor &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;from&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;sys.server_permissions&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;where&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; grantee_principal_id &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;suser_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#ff0000 size=2&gt;'public'&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#000000&gt;Keep in mind that permissions assigned to these roles by default are necessary for the good functioning of the system. You can revoke some of the default permissions, but that could break functionality. The grants should be inoffensive from a security point of view; if you feel otherwise, you should contact the SQL Server security team on the MSDN forums.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4886214" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server+-+security/default.aspx">SQL Server - security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/lcris/archive/tags/computer+security/default.aspx">computer security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx">basic SQL Server security concepts</category></item><item><title>Basic SQL Server Security concepts - logins, users, and principals</title><link>http://blogs.msdn.com/lcris/archive/2007/03/23/basic-sql-server-security-concepts-logins-users-and-principals.aspx</link><pubDate>Fri, 23 Mar 2007 20:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1938638</guid><dc:creator>lcris</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/lcris/comments/1938638.aspx</comments><wfw:commentRss>http://blogs.msdn.com/lcris/commentrss.aspx?PostID=1938638</wfw:commentRss><description>&lt;P&gt;In this post I'd like to talk about some basic SQL Server security concepts. SQL Server has a less common design that can confuse users&amp;nbsp;familiar with the security features&amp;nbsp;of other software products, such as&amp;nbsp;Microsoft Windows OS; in particular, the difference between logins and users is one that seems to invariably confuse most new SQL Server users.&lt;/P&gt;
&lt;P&gt;The first important thing that needs to be understood about SQL Server security is that there are two security realms involved - the server and the database. The server realm encompasses multiple database realms. All work is done in the context of some database, but to get to do the work, one needs to first have access to the server and then to have access to the database.&lt;/P&gt;
&lt;P&gt;Access to the server is granted via logins. There are two main categories of logins: SQL Server authenticated logins and Windows authenticated logins. I will usually refer to these using the shorter names of SQL logins and Windows logins. Windows authenticated logins can either be logins mapped to Windows users or logins mapped to Windows groups. So, to be able to connect to the server, one must have access via one of these types or logins - logins provide access to the server realm.&lt;/P&gt;
&lt;P&gt;But logins are not enough, because work is usually done in a database and databases are separate realms. Access to databases is granted via users. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Important Note:&lt;/STRONG&gt; &lt;EM&gt;When describing a SQL Server scenario, terms like logins and users should not be used interchangeably - a login is a different concept than a user.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Users are mapped to logins and the mapping is expressed by the SID property of logins and users. A login maps to a user in a database if their SID values are identical. Depending on the type of login, we can therefore have a categorization of users that mimics the above categorization for logins; so, we have SQL users and Windows users and the latter category consists of users mapped to Windows user logins and of users mapped to Windows group logins.&lt;/P&gt;
&lt;P&gt;Let's take a step back for a quick overview: a login provides access to the server and to further get access to a database, a user mapped to the login must exist in the database. It is important to know the difference between these two concepts of &lt;EM&gt;login&lt;/EM&gt; and &lt;EM&gt;user&lt;/EM&gt; and to not use these terms interchangeably.&lt;/P&gt;
&lt;P&gt;The existence of databases as a separate realm has the advantage of allowing a database to be detached from a server instance and to be attached to another one. The operation is not without issues, as users may need to be remapped to logins in the new instance and this is a manual operation - it can be performed using &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms174378.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms174378.aspx"&gt;sp_change_users_login&lt;/A&gt; or, starting with SQL Server 2005 SP2, by using &lt;A class="" href="http://blogs.msdn.com/lcris/archive/2007/02/19/sql-server-2005-some-new-security-features-in-sp2.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2007/02/19/sql-server-2005-some-new-security-features-in-sp2.aspx"&gt;a new clause&lt;/A&gt; of the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms176060.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms176060.aspx"&gt;ALTER USER&lt;/A&gt; statement.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; &lt;EM&gt;Users that are not mapped to a login as a result of a database move are known as &lt;STRONG&gt;orphaned users&lt;/STRONG&gt;.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Another advantage is that databases as separate entities allow a better separation of distinct applications - applications can each be placed in their own database, making it harder to accidentally or maliciously access data under the control of another application.&lt;/P&gt;
&lt;P&gt;This separation has an impact on the authorization model of SQL Server as well, as it may be expected. Permissions can be granted at both scopes: server and database. Permissions granted at server scope&amp;nbsp;take effect regardless of what is the current database, but permissions granted at database scope&amp;nbsp;are&amp;nbsp;used&amp;nbsp;only while working in that database. &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms186260.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms186260.aspx"&gt;Server level permissions&lt;/A&gt; are the permissions that are assignable to logins, and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188367.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188367.aspx"&gt;database level permissions&lt;/A&gt; are the permissions assignable to users. To help with the management of permissions, some other entities than the logins and users we discussed so far can be used as the grantees of a permission. Collectively, in SQL Server, the entities that can be granted a permission are referred to as principals. Principals are separated into &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188786.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188786.aspx"&gt;server principals&lt;/A&gt; and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms187328.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms187328.aspx"&gt;database principals&lt;/A&gt; according to their scope.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Important Note:&lt;/STRONG&gt; &lt;EM&gt;While the logins discussed so far grant access to the server and thus are having a role in the authentication process, the other server principals are only used for permission management and do not help with server authentication.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Examples of server principals besides the logins discussed previously are &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms175892.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms175892.aspx"&gt;server roles&lt;/A&gt; and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189751.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189751.aspx"&gt;logins mapped to certificate or asymmetric keys&lt;/A&gt;. Examples of database principals are database roles (&lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms189612.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms189612.aspx"&gt;fixed&lt;/A&gt; and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms187936.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms187936.aspx"&gt;flexible&lt;/A&gt;), &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms190998.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms190998.aspx"&gt;application roles&lt;/A&gt;, &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx"&gt;users mapped to certificate or asymmetric keys&lt;/A&gt;, and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms173463.aspx"&gt;loginless users&lt;/A&gt;. All of these help with the assignment of the permissions. Loginless users (created using CREATE USER ... WITHOUT LOGIN) are a special case because they can be impersonated (application roles are similar, but terminology differs - approles are set, while loginless users are impersonated).&lt;/P&gt;
&lt;P&gt;The last concept I want to discuss here is that of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms187096.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms187096.aspx"&gt;execution context&lt;/A&gt;. The execution context is how SQL Server keeps track of who you are. As it may be expected already, the execution context is formed of a server execution context and a database execution context - these are referred to as &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms186740.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms186740.aspx"&gt;login token&lt;/A&gt; and &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/ms188421.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms188421.aspx"&gt;user token&lt;/A&gt;. The login-user token pair determines who you are in the eyes of the system. The context is initially determined upon login and changes when you switch to a different database or when an impersonation takes place. For more information on the execution context and on impersonation mechanisms, which are topics that extend well beyond the scope of this post, you can have a look at my presentation from &lt;A href="http://cmcgc.com/Media/WMP/261115/"&gt;&lt;FONT color=#176db5&gt;http://cmcgc.com/Media/WMP/261115/&lt;/FONT&gt;&lt;/A&gt;&amp;nbsp;and&amp;nbsp;its relevant &lt;A class="" href="http://blogs.msdn.com/lcris/archive/2006/10/24/sql-server-2005-demo-for-enabling-database-impersonation-for-cross-database-access.aspx" mce_href="http://blogs.msdn.com/lcris/archive/2006/10/24/sql-server-2005-demo-for-enabling-database-impersonation-for-cross-database-access.aspx"&gt;demo&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1938638" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server+-+security/default.aspx">SQL Server - security</category><category domain="http://blogs.msdn.com/lcris/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/lcris/archive/tags/basic+SQL+Server+security+concepts/default.aspx">basic SQL Server security concepts</category></item></channel></rss>