{"id":8125,"date":"2022-09-27T15:12:34","date_gmt":"2022-09-27T20:12:34","guid":{"rendered":"https:\/\/andreas-wolter.com\/?p=8125"},"modified":"2026-10-29T22:02:59","modified_gmt":"2026-10-30T03:02:59","slug":"202209_sql-permission-system-internals-least-privilege-external-policies","status":"publish","type":"post","link":"https:\/\/andreas-wolter.com\/en\/202209_sql-permission-system-internals-least-privilege-external-policies\/","title":{"rendered":"How SQL Server Checks Permissions: Internals of the SQL Server 2022 Permission System"},"content":{"rendered":"<p>If you have not read about it before, we recently made some deep changes within the permissions of SQL Server. The two most relevant announcements are here:<\/p>\n<p><a href=\"https:\/\/andreas-wolter.com\/en\/202208_granular-permissions-sql-server-2022-azure-sql\/\" target=\"_blank\">New granular permissions for SQL Server 2022 and Azure SQL to improve adherence with PoLP<\/a><\/p>\n<p><a href=\"https:\/\/andreas-wolter.com\/en\/202111_purview-access-policies-azure-sql-private-preview\/\" target=\"_blank\">Private Preview: controlling access to Azure SQL at scale with policies in Purview &#8211; Microsoft Tech Community<\/a><\/p>\n<p>In this article I want to share some more details on <strong>why<\/strong> and <strong>how<\/strong> we changed the access check code. The answers are less straight-forward than one may think, and some of you may find it interesting.<\/p>\n<p style=\"padding-left: 30px;\"><em>minor update, Oct 17\/2022<\/em><br \/>In the original article I listed the following Action being part of the Azure Purview for the built-in action-group \u201cSQL Performance Monitor\u201d:<br \/>\/SqlServers\/SystemViewsAndFunctions\/ServerSecurityState\/Rows\/Select<br \/>this is incorrect. That Action is part of the &#8220;SQL Security Auditor&#8221;-role. The correct Action for the\u00a0\u201cSQL Performance Monitor\u201d is\u00a0<br \/>\/Sqlservers\/Databases\/SystemViewsAndFunctions\/DatabasePerformanceState\/Rows\/<\/p>\n<h2 id=\"community-3639399-toc-hId-504728586\">The Why<\/h2>\n<p>1)<\/p>\n<p>The <strong>first<\/strong> part of the answer to the question \u201cWhy?\u201d is quite straightforward: we want to make it easier for customers to adhere to the Principle of Least Privilege (explained here: <a href=\"https:\/\/andreas-wolter.com\/en\/202102_principle-of-least-privilege-polp\/\" target=\"_blank\">Security: The Principle of Least Privilege \/ POLP<\/a>). And for that we need to create permissions that are more specific, in other words, cover more granular operations than before.<br \/>In the announcement-article (<a href=\"https:\/\/andreas-wolter.com\/en\/202208_granular-permissions-sql-server-2022-azure-sql\/\" target=\"_blank\">New granular permissions for SQL Server 2022 and Azure SQL to improve adherence with PoLP<\/a>) I also explain a bit how I approached this when we worked on the permissions that cover viewing system metadata:<br \/>By keeping a <u>balance between increased security and increase of complexity<\/u>. The main take-away is, that rather than coming up with a new permission for every individual object, which surely would have driven everyone crazy, we decided to group all these system objects into 2 groups: those which expose information about the security-state of the system \u2013 and all the rest. This \u201call the rest\u201d is covered under the new permission-name PERFORMANCE STATE respectively PERFORMANCE DEFINITION. That way it is possible to keep personae that work on troubleshooting performance and related issues away from gaining insights into the security state of the system.<\/p>\n<p>2)<\/p>\n<p>But there is a <strong>second<\/strong> reason that plays a vital role in this undertaking, which has additional implications as you will see:<\/p>\n<p>At the same time as I was responsible for the SQL Server permission system in general, I was also working on a second project: <strong>Integrate external policies from Azure Purview to use for access control into SQL Server<\/strong>.<br \/>(This new feature was announced here: <a href=\"https:\/\/andreas-wolter.com\/en\/202111_purview-access-policies-azure-sql-private-preview\/\" target=\"_blank\">controlling access to Azure SQL at scale with policies in Purview<\/a>)<\/p>\n<p>To achieve that, the SQL Server engine permission evaluation algorithm had to be <u>extended<\/u> to allow permission-checks based on external policies. Policies which are received from Azure Purview contain so-called \u201cActions,\u201d which can be either allowed or denied.<\/p>\n<p>As you read above, to change the old SQL permissions to the new more granular permissions on system objects, we had to go through each and every permission check already.<br \/>Realizing this potential to <em>\u201cKill two birds with one stone\u201d<\/em> (no actual birds were harmed in the process, I swear), I convinced the team that doing both changes at the same time would in the long-term safe us a lot of time. Plus, the chances that someone else would want to touch the same code later again would be much lower. While of course doing both at once still added some overhead comparing this to changing the very same code paths later would have been much more extra work.<br \/>Therefore, I am glad that the team followed through on that, despite this being unexciting, repetitive work on these 800+ objects.<\/p>\n<h2 id=\"community-3639399-toc-hId--1302725877\">The undertaking<\/h2>\n<p>The main work went into the splitting of permissions for viewing system metadata, which is exposed via <strong>(A)<\/strong> Dynamic Management View (DMVs (Dynamic Management Views)) and Dynamic Management Functions (DMFs) for information that is often generated at runtime and <strong>(B)<\/strong> Catalog Views for static information.<\/p>\n<p>By splitting, I am referring to the fact that was once covered by (the minimum) permission VIEW DATABASE STATE is now either covered by VIEW DATABASE PERFORMANCE STATE or VIEW DATABASE SECURITY STATE and other 3 splits that we did in this area. The new permissions (see <a href=\"https:\/\/andreas-wolter.com\/en\/202208_granular-permissions-sql-server-2022-azure-sql\/\" target=\"_blank\">New granular permissions for SQL Server 2022 and Azure SQL to improve adherence with PoLP<\/a> for details) are lower permissions than the former minimum permissions and at the same time they are still covered by the respective <strong>former permissions <\/strong>which<strong> are now parent permissions<\/strong>.<\/p>\n<p>These changes of permission requirements naturally required a huge effort by the engineering team that entailed adding new Permission checks for currently about 800 System Objects (DMVs, Catalog Views and DMFs) (!) based on my specification.<\/p>\n<ul>\n<li>Here it helped that until not long ago I have worked extensively in the space of SQL Server system analysis for about 18 years and working with these objects was my daily bread &amp; butter :).<\/li>\n<\/ul>\n<p><strong>Big<\/strong> <strong>Kudos to all the involved engineers, for fighting through it to the end and not giving up at the sight of this enormous task!<\/strong><\/p>\n<h2 id=\"community-3639399-toc-hId-1184786956\">How VIEW SERVER STATE was split up and onboarded to external policies control<\/h2>\n<p>Let\u2019s look at a specific example, which can serve as a blueprint for all the changes that we did: Splitting up the SQL permission VIEW SERVER STATE and onboarding it to allow external policy-based checks.<\/p>\n<p>When VIEW SERVER STATE is granted to a Login, this Login (aka the grantee) can read data from Dynamic Management Views (and -Functions) on the server \u2013 hundreds of them.<br \/>To do that the user will run a command like <em>SELECT * FROM sys.dm_exec_requests<\/em>.<br \/>But there is more: this permission also grants access to some System Stored Procedures such as <em>sys.sp_readerrorlog<\/em>. For that, the command <em>EXECUTE sys.sp_readerrorlog<\/em> is used.<br \/>And then there are DBCC Commands such as <em>DBCC SQLPERF(NETSTATS)<\/em> which again have a different syntax.<\/p>\n<h3 id=\"community-3639399-toc-hId-1875348430\">Explainer: Permissions vs Actions<\/h3>\n<p>Before we get into the next part of the work, I need to make sure everyone understands the difference between SQL permissions and so-called actions.<\/p>\n<p>In policy-based access control systems (such as ABAC (attribute-based access control), Attribute-based access control and Azure IAM (Identity &amp; Access Management) RBAC (role-based access control)), usually the term \u201caction\u201d is used instead of permission (also see: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Attribute-based_access_control\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Attribute-based access control &#8211; Wikipedia<\/a>). Inside the policy definition, an action is just another attribute, next to subjects (Users) or Object attributes<br \/>The difference between action and permission is that <strong><u>actions refer to a specific \u201coperation\u201d<\/u><\/strong> like i.e., \u201cread\u201d or \u201cadd\u201d or \u201ccreate.\u201d<\/p>\n<p>On the other hand, <strong><u>a permission<\/u><\/strong><strong><u> is really just an arbitrary name that implies one or more operations<\/u><\/strong> to be permitted.<\/p>\n<p style=\"padding-left: 30px;\"><em>Example<\/em><br \/>In SQL Server there is a <strong>permission<\/strong> called \u201cCONTROL\u201d which can be granted on a database.<\/p>\n<p style=\"padding-left: 30px;\">But there is no operation in T-SQL (Transact-SQL) that is called \u201cControl\u201d (this is the \u201carbitrary\u201d-part). Instead, this permission allows the granted user (aka grantee) to run a multitude of commands (\u201cone or more\u201d). In fact, in this specific case almost any command that is available inside a database. It could be anything from a SELECT FROM TableX to ALTER DATABASE.<\/p>\n<p style=\"padding-left: 30px;\">This hierarchy of SQL permissions is depicted below:<\/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-3639399-1.jpg\" alt=\"\" width=\"399\" height=\"133\" loading=\"lazy\" style=\"max-width: 100%; height: auto;\" \/><figcaption style=\"font-size: 14px; color: #5a6470; margin-top: 6px;\">Hierarchical SQL permissions<\/figcaption><\/figure>\n<p>The fact that a permission can allow \u201cone or more\u201d different operations is the most important differentiator between actions and permissions &#8211; the latter of which the SQL Server engine used exclusively up until now.<\/p>\n<p>A policy-based permission system that uses <strong>actions<\/strong> usually has a separate action for each different operation and those are independent from each other. So-called \u201ccovering\u201d permissions, as many traditional database-systems use create challenges for PoLP-compliance and are not commonly used in more modern policy-based access control systems.<br \/>This could lead to the following flat list of permissible actions:<\/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-3639399-2.jpg\" alt=\"\" width=\"180\" height=\"334\" loading=\"lazy\" style=\"max-width: 100%; height: auto;\" \/><\/figure>\n<p style=\"padding-left: 30px;\"><em>Note<\/em><br \/>While actions themselves are not hierarchical, the objects that they are applied to can and should very well be <strong>hierarchically organized<\/strong>. The ability to assign a policy at higher levels of resource-hierarchies, such as subscription or a resource group in Azure, allows for efficient access control without micro-managing individual objects. The same is true within SQL Server Databases where a SELECT-permission granted on a whole database would allow selecting all tables in all schemas.<\/p>\n<p>With this background, it is not hard to guess, that a rich RDBMS such as SQL Server which serves as a platform for many internal and external services and functionalities is hard to bring in line with a concept of atomic actions. I.e. if every single DMV (dynamic management views), system stored procedure or DBCC Command would lead to an individual action, we may have done it according to the books, but the result would be a nightmarish pile of individual actions that would lead to extremely large and unreadable policies.<br \/>The solution was to decide on a middle ground that does not compromise on security but keep the ability to express policies manageable.<\/p>\n<p>And this is how it turned out:<\/p>\n<h3 id=\"community-3639399-toc-hId-67893967\">SQL Permission changes<\/h3>\n<p>The VIEW SERVER STATE permission was split into 2 new permissions:<br \/><strong>VIEW SERVER PERFORMANCE STATE<\/strong> and <strong>VIEW SERVER SECURITY STATE<\/strong>.<br \/>Here the new and old permissions both on Server and on Database level are visualized:<\/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-3639399-3.png\" alt=\"Diagram: Split of VIEW SERVER\/DATABASE STATE into VIEW SERVER\/DATABASE PERFORMANCE STATE and VIEW SERVER\/DATABASE SECURITY STATE\" width=\"760\" height=\"396\" loading=\"lazy\" style=\"max-width: 100%; height: auto;\" \/><figcaption style=\"font-size: 14px; color: #5a6470; margin-top: 6px;\">Diagram: Split of VIEW SERVER\/DATABASE STATE into VIEW SERVER\/DATABASE PERFORMANCE STATE and VIEW SERVER\/DATABASE SECURITY STATE<\/figcaption><\/figure>\n<p>In addition to that, we introduce a new permission: <strong>VIEW ANY ERROR LOG<\/strong>.<br \/>It covers the following system stored procedures:<\/p>\n<p><em>sys.xp_enumerrorlogs<br \/>sys.sp_readerrorlog <br \/>sys.xp_readerrorlog<\/em><\/p>\n<p>For the DBCC Commands in the SQL world we keep them under the same <strong>VIEW SERVER PERFORMANCE STATE<\/strong> -permission as used for accessing DMVs. This is a small concession to simplicity since it is unlikely that users who are tasked with performance analysis and hence get access to DMVs etc. would not be allowed running these read-only DBCC-commands. This way we save 1 permission in SQL for the price of a small misalignment with the policy-based action as you will see below.<\/p>\n<p>Result: 3 new permissions<\/p>\n<h3 id=\"community-3639399-toc-hId--1739560496\">New actions for policy-based access control<\/h3>\n<p>To express the same as the SQL permissions above permit, we created the following actions to be used by Azure Purview for the built-in action-group \u201cSQL Performance Monitor\u201d:<\/p>\n<p><strong>\/SqlServers\/SystemViewsAndFunctions\/ServerPerformanceState\/Rows\/Select<\/strong> <br \/><strong>\/Sqlservers\/Databases\/SystemViewsAndFunctions\/DatabasePerformanceState\/Rows\/Select<\/strong><br \/><strong>\/SqlServers\/ErrorLogs\/Select<\/strong><\/p>\n<p><strong>\/Sqlservers\/DBCCs\/ViewServerPerformanceState\/Execute<br \/>\/Sqlservers\/Databases\/DBCCs\/ViewDatabasePerformanceState\/Execute<\/strong><\/p>\n<p>Result: 5 new actions<\/p>\n<p>As you can see here, the use action-names partially align to the SQL permission names that closely match their behavior. In the case of the DBCC commands, we have introduced 2 additional actions as a concession to the action-based model and language.<\/p>\n<h2 id=\"community-3639399-toc-hId--1750063600\">More Details<\/h2>\n<p>Now that we understand the background and the overall idea of working with permissions and actions in parallel, let us see how these checks are implemented inside the SQL engine.<\/p>\n<p>If a given SQL Server is governed by Azure Purview, the server is regularly connecting to the external Microsoft Azure Purview Service and downloads all the relevant policies to a local cache. These policies contain all the required information to match an AAD (Azure Active Directory) Account with the allowed or denied actions.<br \/>If the user is running a query that contains objects that are onboarded for external governance, the permission-check will include both the SQL permissions and the external policy-based actions.<\/p>\n<p>Below is a picture of the high-level architecture of this workflow:<\/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-3639399-4.jpg\" alt=\"Diagram of service-architecture Azure Purview with SQL Server\" width=\"500\" height=\"386\" loading=\"lazy\" style=\"max-width: 100%; height: auto;\" \/><figcaption style=\"font-size: 14px; color: #5a6470; margin-top: 6px;\">Diagram of service-architecture Azure Purview with SQL Server<\/figcaption><\/figure>\n<p>On a high-level, extending existing permission checks to check for new SQL-permissions and at the same time check for new external permissions, the respective locations in code only had to be touched once for both at the same time.<br \/>The new permission checks algorithms are based on <strong>OR-logic<\/strong>. For example, a user executing the query<\/p>\n<p style=\"padding-left: 30px;\">SELECT * FROM sys.dm_os_waiting_tasks<\/p>\n<p>traditionally would undergo a permission check with the following logic:<\/p>\n<p style=\"padding-left: 30px;\"><em>Is there <strong>no DENY<\/strong> for:<\/em><br \/><em>\u00a0\u00a0\u00a0 (SQL permission) <strong>VIEW SERVER PERFORMANCE STATE<\/strong><\/em><br \/><strong><em>AND<\/em><\/strong><br \/><em>is there a <strong>GRANT<\/strong> for:<\/em><br \/><em>\u00a0\u00a0\u00a0 SQL permission <strong>VIEW SERVER PERFORMANCE STATE<\/strong><\/em><\/p>\n<ul>\n<li>There is a check for a DENY on the respective permission, and if that is not the case, the principal still requires an explicit GRANT<\/li>\n<\/ul>\n<p>Now, in SQL Server 2022 and Azure SQL Database, all the commands that we onboarded to allow externally based permissions\/actions, will undergo a permission-check with the following <u>new extended logic:<\/u><\/p>\n<p style=\"padding-left: 30px;\"><em>is there <strong>no DENY<\/strong> for:<\/em><br \/><em>{<\/em><br \/><em>\u00a0\u00a0\u00a0 (SQL permission) <strong>VIEW SERVER PERFORMANCE STATE<\/strong><\/em><br \/><strong><em>OR<\/em><\/strong><br \/><em>\u00a0\u00a0\u00a0 (External Policy Action)\u00a0 <strong>SqlServers\/SystemViewsAndFunctions\/ServerPerformanceState\/Rows\/Select<\/strong><\/em><br \/><em>}<\/em><br \/><strong><em>AND<\/em><\/strong><br \/>is there a <strong>GRANT<\/strong> for:<br \/>{<br \/>\u00a0\u00a0\u00a0 SQL permission <strong>VIEW SERVER PERFORMANCE STATE<\/strong><br \/><strong>OR<\/strong><br \/>\u00a0\u00a0\u00a0 (External Policy Action) <strong>\/SqlServers\/SystemViewsAndFunctions\/ServerPerformanceState\/Rows\/Select<\/strong><br \/>}<\/p>\n<ul>\n<li>Note: the actual source code does not look like this, this is a strong simplification &#x1f642;<\/li>\n<\/ul>\n<p>As you can see, we are simply allowing multiple sources to satisfy the condition using an OR-logic.<br \/>You can also see this in the new error messages that only start appearing after enabling a server for external governance. For example, if a user does not have either permission, the error message reveals the 2 possible alternatives:<\/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-3639399-5.jpg\" alt=\"Error message 371: both SQL permission and external policy action missing\" width=\"999\" height=\"348\" loading=\"lazy\" style=\"max-width: 100%; height: auto;\" \/><figcaption style=\"font-size: 14px; color: #5a6470; margin-top: 6px;\">Error message 371: both SQL permission and external policy action missing<\/figcaption><\/figure>\n<p>I hope this sheds some light on how things are working and why they are working this way in the permission space.<\/p>\n<p>Happy securing<\/p>\n<p>Andreas<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have not read about it before, we recently made some deep changes within the permissions of SQL Server. The two most relevant announcements are here: New granular permissions for SQL Server 2022 and Azure SQL to improve adherence with PoLP Private Preview: controlling access to Azure SQL at scale with policies in Purview [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":8115,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[422,424,478],"class_list":["post-8125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security-en","tag-least-privilege-en","tag-permissions","tag-sql-server-2022-en"],"_links":{"self":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8125","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=8125"}],"version-history":[{"count":2,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8125\/revisions"}],"predecessor-version":[{"id":8186,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/posts\/8125\/revisions\/8186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/media\/8115"}],"wp:attachment":[{"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/media?parent=8125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/categories?post=8125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andreas-wolter.com\/en\/wp-json\/wp\/v2\/tags?post=8125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}