{"id":8088,"date":"2023-08-22T15:43:37","date_gmt":"2023-08-22T20:43:37","guid":{"rendered":"https:\/\/andreas-wolter.com\/?p=8088"},"modified":"2026-10-29T22:02:52","modified_gmt":"2026-10-30T03:02:52","slug":"202308_delegating-permission-management-roles-vs-with-grant-option","status":"publish","type":"post","link":"https:\/\/andreas-wolter.com\/en\/202308_delegating-permission-management-roles-vs-with-grant-option\/","title":{"rendered":"Delegating Permission Management in SQL Server: Roles vs WITH GRANT OPTION"},"content":{"rendered":"<h2 id=\"community-3906618-toc-hId-587758737\">Background<\/h2>\n<p>In SQL Server\/Azure SQL, database-level permissions are almost always handled by either the database owner (which has the <em>dbo<\/em>-identity) or members of the <em>db_owner <\/em>or <em>db_securityadmin<\/em>-database roles.<\/p>\n<p style=\"padding-left: 30px;\">Here you can learn more about the differences: <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/authentication-access\/principals-database-engine?view=sql-server-ver16#dbo-user-and-dbo-schema\" target=\"_blank\" rel=\"noopener noreferrer\">Principals (Database Engine)<\/a>, <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/authentication-access\/database-level-roles?view=sql-server-ver16#fixed-database-roles\" target=\"_blank\" rel=\"noopener noreferrer\">Database-Level Roles<\/a>.<\/p>\n<p>Both roles can GRANT\/DENY\/REVOKE <u>any permission<\/u> within a database. Since that makes members of these roles super powerful, their membership should always be tightly controlled and audited. (also see: <a href=\"https:\/\/andreas-wolter.com\/en\/202109_security_concept_audit_trail\/\" target=\"_blank\">Security concept: Audit Trail<\/a>).<br \/>Consequently, most customers just keep this power to the main Administrators-group.<\/p>\n<p>However, there are cases where it is useful to enable a set of <u>non-admin users \u2013 <\/u>let\u2019s call them <em>LowPermission-Managers \u2013 <\/em>to work in a more self-sufficient way and enable them to grant <u>some permissions<\/u> to other users without the need to involve \u201cthe Administrators\u201d.<br \/>The emphasis is on \u201csome permissions\u201d asthis only makes sense for low privileges. Making the <em>LowPermissionManagers<\/em> members of <em>db_owner<\/em> or <em>db_securityadmin<\/em> -roles would defeat the purpose.<\/p>\n<p>For example, it can be useful to allow the <em>LowPermissionManagers<\/em> to grant the SELECT, INSERT, UPDATE and DELETE permissions to other users. But not allow other permissions like ALTER or CONTROL and so on.<\/p>\n<p style=\"padding-left: 30px;\">To put things into perspective,here is an overview of the extensive permissions that the SQL Server engine ships with: <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/permissions-database-engine?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener noreferrer\">Permissions (Database Engine)<br \/><\/a>You will also see me using the term \u201c<em>securable<\/em>\u201d. In a nutshell, a securable is the object on which a user (aka the \u201c<em>grantee\u201d<\/em>) will get certain permissions. (<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/securables?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener noreferrer\">Securables &#8211; SQL Server | Microsoft Learn<\/a>)<\/p>\n<p>In other words, we want to allow someone else to take over some of the work of granting privileges. This concept is also called \u201cdelegation\u201d. (Here you can read more on <a href=\"https:\/\/andreas-wolter.com\/en\/delegation-of-authority\/\" target=\"_blank\">Delegation of Authority<\/a>.)<\/p>\n<p>SQL Server\/Azure SQL has a rich permission system, and I want to show you two methods to accomplish <strong>delegation of permission-management<\/strong>.<\/p>\n<h2 id=\"community-3906618-toc-hId--1219695726\">Using roles for delegating permission-management on a schema<\/h2>\n<p>In general, when granting permissions to users in a database, we should always use roles instead of granting permissions to individual users. This is the same best practice used for Windows Active Directory and Entra ID groups (formerly known as Azure Active Directory: \u201c<a href=\"https:\/\/azure.microsoft.com\/en-us\/updates\/azure-ad-is-becoming-microsoft-entra-id\/\" target=\"_blank\" rel=\"noopener noreferrer\">Azure AD is becoming Microsoft Entra ID <\/a>\u201c).<\/p>\n<p style=\"padding-left: 30px;\"><em>Note<\/em><br \/>In Windows Active Directory the acronyms <a href=\"https:\/\/en.wikipedia.org\/wiki\/AGDLP\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">AGDLP<\/a> (<strong>A<\/strong>ccount -&gt; <strong>G<\/strong>lobal group -&gt; <strong>D<\/strong>omain <strong>L<\/strong>ocal group -&gt; <strong>P<\/strong>ermission) and AGLP are well known amongst administrators.<br \/>In SQL Server the acronym \u00a0URP (<strong>U<\/strong>ser -&gt; <strong>R<\/strong>ole -&gt; <strong>P<\/strong>ermission) or LURP (<strong>L<\/strong>ogin -&gt; <strong>U<\/strong>ser -&gt; <strong>R<\/strong>ole -&gt; <strong>P<\/strong>ermission) is less commonly used but is based on the similar concept: to grant permissions not to individual accounts but to a collection, strored as group or role.<\/p>\n<p>In my example we have a database which contains several user-defined schemas (<a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/relational-databases\/security\/authentication-access\/ownership-and-user-schema-separation?view=sql-server-ver16\" target=\"_blank\" rel=\"noopener noreferrer\">Ownership and user-schema separation in SQL Server &#8211; SQL Server | Microsoft Learn<\/a>). The schema called \u201cSensorData\u201d contains numerous tables.<\/p>\n<p>The database administrator (let\u2019s call that person DBA) does not want to be bothered with managing simple read-access to this specific schema and all the tables and views it contains.<\/p>\n<p>Instead, this will be delegated to a different user, Alejandra.<\/p>\n<p>To set this up, the DBA (1) creates a database role called \u201crole_SensorDataUsers\u201d and (2) gives that role the SELECT-permission for the whole SensorData-schema.<\/p>\n<pre><code>CREATE ROLE role_SensorDataUsers\nGO\n\nGRANT SELECT\n       ON SCHEMA::SensorData\n       TO role_SensorDataUsers\nGO<\/code><\/pre>\n<p>Now instead of adding every other user that needs access to this schema, the DBA (3) delegates the permission to add members for this specific database role \u2013 and no other role! \u2013 to Alejandra, who he trusts with this task.<\/p>\n<p>In SQL Server we have the <em>ALTER ROLE<\/em> permission, which can be granted on a per-role basis. Granting the ALTER ROLE permission allows the grantee, Alejandra, to add and remove (drop) members to and from this role.<\/p>\n<pre><code>GRANT ALTER\n       ON ROLE::role_SensorDataUsers\n       TO Alejandra<\/code><\/pre>\n<p>Now, Alejandra can run the following statement to (4) add Guillermo, a new user, to the role_SensorDataUsers-role:<\/p>\n<pre><code>ALTER ROLE role_SensorDataUsers\n       ADD MEMBER Guillermo<\/code><\/pre>\n<p>Result: Guillermo can now SELECT from any table or view contained in the schema SensorData.<\/p>\n<p>When it comes to Alejandra: all she can do is add or drop other users to and from this role. She cannot change the permissions of the role or drop it.<\/p>\n<p style=\"padding-left: 30px;\"><em>Note<\/em><br \/>The ALTER ROLE-permission also includes the ability to change the name of the role. This is something to be aware of. Renaming may not sound dangerous, but confusion can lead to mistakes. Therefore, make sure the ALTER ROLE-statement is being audited (as it should be anyways).<\/p>\n<p>Finally, when the time comes, Alejandra can remove Guillermo from this role:<\/p>\n<pre><code>ALTER ROLE role_SensorDataUsers\n       DROP MEMBER Guillermo<\/code><\/pre>\n<p>With that, the database administrator does not need to bother with granting specific permissions on specific schemas and can focus on higher privileges and user-creation.<\/p>\n<p>This is a diagram that depicts the setup:<\/p>\n<figure class=\"aw-tc-figure\" style=\"text-align: center; margin: 24px 0;\"><img decoding=\"async\"  src=\"https:\/\/andreas-wolter.com\/wp-content\/uploads\/2026\/10\/tc-3906618-1.png\" alt=\"Diagram of Using roles for delegating permission-management on a schema\" loading=\"lazy\" width=\"999\" height=\"512\" style=\"max-width: 100%; height: auto;\" \/><figcaption style=\"font-size: 14px; color: #5a6470; margin-top: 6px;\">Diagram of Using roles for delegating permission-management on a schema<\/figcaption><\/figure>\n<h2 id=\"community-3906618-toc-hId-1267817107\">Using the WITH GRANT OPTION of the GRANT statement to delegate management of multiple permissions on schema-level<\/h2>\n<p>Imagine we not only want to delegate the management of just the SELECT-permission, but also INSERT, UPDATE and DELETE on a given schema to a different user: Alejandra. And we want Alejandra to decide which of these 4 permissions to grant herself.<\/p>\n<p>We could create 4 roles of course, each with one of the 4 permissions only, and make Alejandra manager of the 4 roles, following the previous example.<\/p>\n<p>But there is another option which I would like to demonstrate:<\/p>\n<p>Instead of having 4 roles, in this case we could make use of the WITH GRANT OPTION of the GRANT statement, documented here: <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/statements\/grant-transact-sql?view=sql-server-ver16&amp;f1url=%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(GRANT_TSQL)%3Bk(sql13.swb.tsqlresults.f1)%3Bk(sql13.swb.tsqlquery.f1)%3Bk(MiscellaneousFilesProject)%3Bk(DevLang-TSQL)%26rd%3Dtrue#with-grant-option\" target=\"_blank\" rel=\"noopener noreferrer\">GRANT (Transact-SQL) &#8211; SQL Server | Microsoft Learn<\/a><\/p>\n<p>When using the GRANT statement together with the WITH GRANT OPTION, we are allowing the grantee to pass the very same permissions on to other users.<\/p>\n<p>This is how it looks using the previous example as a baseline.<\/p>\n<p>We could grant Alejandra the respective permissions directly but, following best practices, the DBA (1) creates a role for this purposein a very different way than in the previous example.<\/p>\n<pre><code>CREATE ROLE role_SensorDataUserManager\nGO\n\n<\/code><\/pre>\n<p>The DBA (2) grants this role the 4 permissions which he wants to delegate the management for:<\/p>\n<pre><code>GRANT SELECT, INSERT, UPDATE, DELETE\n       ON SCHEMA::SensorData\nTO role_SensorDataUserManager WITH GRANT OPTION<\/code><\/pre>\n<p>Now the DBA (3) makes Alejandra a member of this role:<\/p>\n<pre><code>ALTER ROLE role_SensorDataUserManager\n       ADD MEMBER Alejandra<\/code><\/pre>\n<p>At this point I want to point out how SQL Server stores permissions in metadata. To do that we can run the following T-SQL:<\/p>\n<pre><code>SELECT * FROM sys.database_principals\n       WHERE NAME IN ('Alejandra','Guillermo','role_SensorDataUserManager')\n\nSELECT * FROM sys.database_permissions\nwhere grantee_principal_id IN (5, 6, 7)   -- IDs of the 3 principals used in this demo<\/code><\/pre>\n<p>This is the result:<\/p>\n<figure class=\"aw-tc-figure\" style=\"text-align: center; margin: 24px 0;\"><img decoding=\"async\"  src=\"https:\/\/andreas-wolter.com\/wp-content\/uploads\/2026\/10\/tc-3906618-2.png\" alt=\"\" loading=\"lazy\" width=\"999\" height=\"308\" style=\"max-width: 100%; height: auto;\" \/><\/figure>\n<p>Note that (A) Alejandra (principal_id = 5) has no permissions on her own. Instead, the role role_SensorDataUserManager (principal_id = 7, marked red in my image) has the permissions. And (B) The permissions that it has are not simply \u201cGRANT\u201d but really \u201cGRANT WITH GRANT OPTION\u201d (marked red in my image).<\/p>\n<p>This is how this looks like in SQL Server Management Studio UI:<\/p>\n<figure class=\"aw-tc-figure\" style=\"text-align: center; margin: 24px 0;\"><img decoding=\"async\"  src=\"https:\/\/andreas-wolter.com\/wp-content\/uploads\/2026\/10\/tc-3906618-3.png\" alt=\"\" loading=\"lazy\" width=\"874\" height=\"674\" style=\"max-width: 100%; height: auto;\" \/><\/figure>\n<p>As a result, not only can Alejandra do what the role allows: SELECT, INSERT, UPDATE, DELETE on any table or view within the schema <em>SensorData<\/em>, but in addition to that, she can decide to give any of these 4 permissions to someone else \u2013 without making that other user member of the role <em>role_SensorDataUserManager<\/em>:<\/p>\n<pre><code>GRANT INSERT, UPDATE ON SCHEMA::SensorData\n       TO Guillermo\n       AS role_SensorDataUserManager<\/code><\/pre>\n<p>If you look at this statement, you see that it contains the AS-Clause of the GRANT-statement.<br \/>This is important, because without this clause Alejandra cannot grant the permissions to Guillermo. When utilizing the power of the WITH GRANT OPTION which is granted to a role, and not the user-account directly, it is required to explicitly state the principal which is used for the GRANT.<br \/>Because behind the scenes, SQL Server always stores the grantor\u2019s principal_id in metadata. And since the permission could come from different roles it needs to be specified (a good example of explicitness, which is fundamental to security controls, in my eyes).<\/p>\n<p>Let\u2019s look at sys.database_permissions again:<\/p>\n<pre><code>SELECT * FROM sys.database_permissions\nwhere grantee_principal_id = 6    -- Guillermos principal_id on my system<\/code><\/pre>\n<figure class=\"aw-tc-figure\" style=\"text-align: center; margin: 24px 0;\"><img decoding=\"async\"  src=\"https:\/\/andreas-wolter.com\/wp-content\/uploads\/2026\/10\/tc-3906618-4.png\" alt=\"\" loading=\"lazy\" width=\"890\" height=\"78\" style=\"max-width: 100%; height: auto;\" \/><\/figure>\n<p>These are the 2 permissions that have been granted to Guillermo (grantee_principal_id = 6, marked green in my image) in the name of the role <em>role_SensorDataUserManager<\/em> (principal_id = 7, marked red in my image). This time the role is the <em>grantor<\/em>, not the <em>grantee<\/em>.<\/p>\n<p>Result: Guillermo can now run the INSERT and UPDATA-statements against any table or view contained in the schema SensorData.<\/p>\n<p>This is a diagram that shows this approach:<\/p>\n<figure class=\"aw-tc-figure\" style=\"text-align: center; margin: 24px 0;\"><img decoding=\"async\"  src=\"https:\/\/andreas-wolter.com\/wp-content\/uploads\/2026\/10\/tc-3906618-5.png\" alt=\"\" loading=\"lazy\" width=\"998\" height=\"439\" style=\"max-width: 100%; height: auto;\" \/><\/figure>\n<p>Of course, Alejandra can also REVOKE the permissions.<br \/>Here again it is required to call out the principal name from which the permissions originate. Otherwise, the SQL engine cannot find the right permission-entry to remove.<\/p>\n<pre><code>REVOKE INSERT, UPDATE ON SCHEMA::SensorData\n       TO Guillermo\n       AS role_SensorDataUserManager<\/code><\/pre>\n<h3 id=\"community-3906618-toc-hId-1958378581\">Important<\/h3>\n<p>When using the GRANT\u2026 WITH GRANT OPTION statement it is important to have a good understanding on how the permissions are stored. You may know that when database users own objects such as tables within the database, those objects cannot be dropped as long as they are owned by the user which you want to drop In such cases you either drop the objects completely, or change their ownership to a different user account.<br \/>The same applies to permission grantors. In my scenario the permission was saved using the role\u2019s principal-id. Hence the role cannot be dropped before the permissions that were granted under its authority are revoked (not denied either).<\/p>\n<p>The error message in such an attempt would be:<\/p>\n<p>Msg 15284, Level 16, State 1, Line 96<\/p>\n<p>The database principal has granted or denied permissions to objects in the database and cannot be dropped.<\/p>\n<h2 id=\"community-3906618-toc-hId-1947875477\">Summary<\/h2>\n<p>I have shown 2 methods \u00a0for delegation of permission-management.<br \/>Generally, I always strongly recommend exclusively working with roles that have permissions and absolutely avoid granting permissions on a user-level. This makes reporting and auditing much easier and avoids problems down the road.<br \/>However, at times, it can be useful to explicitly save who granted which permissions in metadata, or the use of roles may not always be practical. The GRANT WITH GRANT OPTION is a niche player for sure, but it&#8217;s good to have alternatives when needed.<\/p>\n<p>Happy securing<\/p>\n<p>Andreas<\/p>\n<p>Thank you to the following people for help with this article:<br \/>Practical use cases: Ralf Dietrich, Managing director <a href=\"https:\/\/www.sarpedonqualitylab.com\/\" target=\"_self\" rel=\"nofollow noopener noreferrer\"><em>Sarpedon Quality Lab<\/em><\/a> <br \/>Technical correctness: Steven Gott (Principal Software Engineer, Microsoft)<br \/>Language: Tameika Lawrence (Program Manager SQL Security)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background In SQL Server\/Azure SQL, database-level permissions are almost always handled by either the database owner (which has the dbo-identity) or members of the db_owner or db_securityadmin-database roles. Here you can learn more about the differences: Principals (Database Engine), Database-Level Roles. Both roles can GRANT\/DENY\/REVOKE any permission within a database. Since that makes members of [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":8078,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[422,424,434],"class_list":["post-8088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security-en","tag-least-privilege-en","tag-permissions","tag-security-principles"],"_links":{"self":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/comments?post=8088"}],"version-history":[{"count":2,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8088\/revisions"}],"predecessor-version":[{"id":8183,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8088\/revisions\/8183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/media\/8078"}],"wp:attachment":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/media?parent=8088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/categories?post=8088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/tags?post=8088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}