{"id":1745,"date":"2013-08-28T14:59:57","date_gmt":"2013-08-28T21:59:57","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/bobb\/?p=1745"},"modified":"2013-08-28T15:01:53","modified_gmt":"2013-08-28T22:01:53","slug":"an-implying-not-implied-permissions-function","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/","title":{"rendered":"An implied (not implying) permissions function"},"content":{"rendered":"<p>I&#8217;d always wondered why they didn&#8217;t make the &#8220;ImplyingPermissions&#8221; function (code is part of the books online) part of the product. I originally thought it was because the function was subtly (or not so subtly) misnamed. What the function does, is &#8220;given a permission in a permission class, return a table of which built-in permissions grant (or deny) you that input permission by permission inheritance\/covering&#8221;. To use their example, if the input permission is &#8220;ALTER&#8221; in the &#8220;SCHEMA&#8221; class, the returned table includes the &#8220;ALTER&#8221; permission in the &#8220;DATABASE&#8221; class, meaning that granting someone &#8220;ALTER DATABASE&#8221; also grants them &#8220;ALTER SCHEMA&#8221; in every schema in that database.<\/p>\n<p>I always wanted the corollary function, &#8220;ImpliedPermissions&#8221;. That is, given the permission &#8220;ALTER&#8221; in the &#8220;DATABASE&#8221; class, what other permissions at lower levels am I granted by hierarchy\/covering? There&#8217;s probably someone that&#8217;s already written that function, but searching for &#8220;SQL Server Implied Permissions&#8221; always brings me back to the &#8220;ImplyingPermissions&#8221; function. Which is where I got the idea about its being misnamed. It&#8217;s non-trivial to write, given that there are two types of permission &#8220;inheritance&#8221; &#8211; inheritance and covering. But I came upon this quick way that uses the ImpliedPermission function and CROSS APPLY:<\/p>\n<p>CREATE FUNCTION dbo.ImpliedPermissions(@class nvarchar(64), @permission_name nvarchar(64))<br \/>\nRETURNS TABLE<br \/>\nAS RETURN<br \/>\nSELECT a.*, b.height, b.RANK<br \/>\nFROM sys.fn_builtin_permissions(&#8221;) AS a<br \/>\nCROSS APPLY dbo.ImplyingPermissions(a.class_desc, a.permission_name) AS b<br \/>\nWHERE b.CLASS = @class AND b.permname = @permission_name<br \/>\nGO<\/p>\n<p>Note that this is not the same as creating a LOGIN or USER, assigning it permissions, then impersonating the principal and using sys.fn_my_permissions. The &#8220;My permissions&#8221; function (which must have been invented when Windows was calling everything &#8220;My&#8230;&#8221;) requires a *specific* securable and class, not a class and permission. So it can tell you which permissions (multiple) you&#8217;ve been granted on schemaX.tableX, and one level and type of inheritance between table and column (SELECT on a table gives you SELECT on all the columns), but not functionality like &#8220;SELECT&#8221; in the &#8220;OBJECT&#8221; class. And the Implying\/ImpliedPermissions functions themselves don&#8217;t deal with individuals, just classes.<\/p>\n<p>So now there is a corollary function too. I did notice that it was a bit slow, especially trying to use it with semi-joins and anti semi-joins. So, if you&#8217;re using this function a lot, you may want to materialize the permission hierarchy table (builtin_permissions CROSS APPLY ImplyingPermissions) somewhere. And now I can tell you, &#8220;if you give someone class X\/permission Y, what else are you giving them? Well, at least to the extent that sys.fn_builtin_permissions() accurately reflects the permission hierarchy\/covering (I think I&#8217;ve found some edge cases). Enjoy&#8230;<\/p>\n<p>@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d always wondered why they didn&#8217;t make the &#8220;ImplyingPermissions&#8221; function (code is part of the books online) part of the product. I originally thought it was because the function was subtly (or not so subtly) misnamed. What the function does, is &#8220;given a permission in a permission class, return a table of which built-in permissions [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1745","post","type-post","status-publish","format-standard","hentry","category-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>An implied (not implying) permissions function - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An implied (not implying) permissions function - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"I&#8217;d always wondered why they didn&#8217;t make the &#8220;ImplyingPermissions&#8221; function (code is part of the books online) part of the product. I originally thought it was because the function was subtly (or not so subtly) misnamed. What the function does, is &#8220;given a permission in a permission class, return a table of which built-in permissions [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-28T21:59:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-28T22:01:53+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/\",\"name\":\"An implied (not implying) permissions function - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2013-08-28T21:59:57+00:00\",\"dateModified\":\"2013-08-28T22:01:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Security\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/security\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"An implied (not implying) permissions function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An implied (not implying) permissions function - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/","og_locale":"en_US","og_type":"article","og_title":"An implied (not implying) permissions function - Bob Beauchemin","og_description":"I&#8217;d always wondered why they didn&#8217;t make the &#8220;ImplyingPermissions&#8221; function (code is part of the books online) part of the product. I originally thought it was because the function was subtly (or not so subtly) misnamed. What the function does, is &#8220;given a permission in a permission class, return a table of which built-in permissions [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/","og_site_name":"Bob Beauchemin","article_published_time":"2013-08-28T21:59:57+00:00","article_modified_time":"2013-08-28T22:01:53+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/","name":"An implied (not implying) permissions function - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2013-08-28T21:59:57+00:00","dateModified":"2013-08-28T22:01:53+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/an-implying-not-implied-permissions-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Security","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/security\/"},{"@type":"ListItem","position":3,"name":"An implied (not implying) permissions function"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=1745"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/1745\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=1745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=1745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=1745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}