{"id":8148,"date":"2026-12-03T15:21:42","date_gmt":"2026-12-03T14:21:42","guid":{"rendered":"https:\/\/blog.redbaronofazure.com\/?p=8148"},"modified":"2026-12-03T15:27:30","modified_gmt":"2026-12-03T14:27:30","slug":"entra-administrative-units-instead-of-group-read-all","status":"publish","type":"post","link":"https:\/\/blog.redbaronofazure.com\/?p=8148","title":{"rendered":"Entra Administrative Units instead of Group.Read.All"},"content":{"rendered":"\n<p>What do you do if you have an app that needs to read a set of groups and lists its members? You can grant the app the Graph API Permission Group.Read.Alll and User.ReadBasic.All, but that would mean the app would be able to see <em>all<\/em> groups in your Entra tenant and that may be a security concern as it gives the app to much permission.<\/p>\n\n\n\n<p>Instead, you can grant the app&#8217;s service principal (SP) the permission to only <em>read<\/em> groups that exists in an <strong><em>Administrative Unit<\/em><\/strong> (AU), meaning it can only see the groups it is intended to see. In order to achieve this the relevant groups needs to be added to an AU and the service principal assigned the permission of a custom role we create that can only read groups, not manage them.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2026\/12\/entra_tenant_au_reader_60kb.jpg\" alt=\"\" class=\"wp-image-8149\" width=\"430\" height=\"229\"\/><\/figure>\n\n\n\n<p>If the other app can use SCIM, that would be a better choice, but in cases where SCIM is not an option, this can be a solution.<\/p>\n\n\n\n<p>This post is a continuation from the the <a href=\"https:\/\/blog.redbaronofazure.com\/?p=8059\" target=\"_blank\" rel=\"noreferrer noopener\">Administrative Units instead of Group.ReadWrite.All post<\/a>.<\/p>\n\n\n\n<h2>Create the Service Principal that should hold the permissions<\/h2>\n\n\n\n<p>The application will need the API permissions User.ReadBasic.All and AdministrativeUnit.Read.All. User.ReadBasic.All is needed to get the user profile for each group member in the cases the users are not a member of the same AU. The  AdministrativeUnit.Read.All is needed to enumerate all groups within the AU (shown further down).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2026\/12\/Screenshot-2026-12-03-143027.png\" alt=\"\" class=\"wp-image-8150\" width=\"749\" height=\"278\"\/><\/figure>\n\n\n\n<h2>Creating Custom Role Group Reader<\/h2>\n\n\n\n<p>We can not use the built-in role Group Administrator as that role gives the holder the right to create and manage groups. In this case we only want the holder to read groups. Therefor we create a custom role with the following permissions.<\/p>\n\n\n\n<ul><li>Name: Group Reader (Custom)<br><\/li><li>Role permissions:<br>microsoft.directory\/groups\/standard\/read<br>microsoft.directory\/groups\/members\/read<br>microsoft.directory\/groups\/owners\/read<br>microsoft.directory\/users\/standard\/read<br>microsoft.directory\/servicePrincipals\/standard\/read<br>microsoft.directory\/devices\/standard\/read<\/li><\/ul>\n\n\n\n<p>The users\/servicePrincipals\/devices permissions are needed to read the different types of group members. Without them you will just get a guid and the odata.type.<\/p>\n\n\n\n<h2>Assign the Group Reader custom role to the AdministrativeUnit<\/h2>\n\n\n\n<p>Once you have the custom role you need to assign it to the AU. Select you AU in Entra Admin Center > Roles &amp; admins > Admin units > Roles and administrators. Then do +Add assignment and pick the AppThatNeedsToReadSomeGroups service principal and set it as an active assignment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1306\" height=\"328\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2026\/12\/Screenshot-2026-12-03-144742.png\" alt=\"\" class=\"wp-image-8151\"\/><\/figure>\n\n\n\n<h2>Listing groups and its members<\/h2>\n\n\n\n<p>First, authenticate the SP using client credentials<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$auth = Invoke-RestMethod -Method Post -Uri \"https:\/\/login.microsoftonline.com\/$tenantId\/oauth2\/v2.0\/token\" `\r\n    -ContentType \"application\/x-www-form-urlencoded\" `\r\n    -Body @{ grant_type=\"client_credentials\"; client_id=$ClientId; client_secret=$ClientSecret; scope=\"https:\/\/graph.microsoft.com\/.default\" }\r\n$authHeader =@{ 'Content-Type'='application\/json'; 'Authorization'='Bearer ' + $auth.access_token }    <\/code><\/pre>\n\n\n\n<p>Second, list groups available in the AU. Here we can not use https:\/\/graph.microsoft.com\/groups as that would require a tenant wide scope which the service principal doesn&#8217;t have. Instead, we need to ask the AU what groups are members. The graph Uri is <em>\/directory\/administrativeUnits\/{id}\/members\/microsoft.graph.groups<\/em> which means &#8220;give me all groups in this AU&#8221;. The crux is to know your AU id.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$groups = (Invoke-RestMethod -Method \"GET\" -Uri \"https:\/\/graph.microsoft.com\/v1.0\/directory\/administrativeUnits\/$($au.id)\/members\/microsoft.graph.group\" -Headers $authHeader).value<\/code><\/pre>\n\n\n\n<p>The above query requires the API permission <em>AdministrativeUnit.Read.All<\/em> which we assigned the SP earlier.<\/p>\n\n\n\n<p>Once you have the group objects, you can use the standard graph group endpoint to get its members.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">(Invoke-RestMethod -Method \"GET\" -Uri \"https:\/\/graph.microsoft.com\/v1.0\/groups\/$($groups[0].id)\/members\" -Headers $authHeader).value | select userPrincipalName, displayName\r\n\r\nuserPrincipalName              displayName\r\n-----------------              -----------\r\nbasil@fawltytowers2.com        Basil Fawlty\r\nsybil@fawltytowers2.com        Sybil Fawlty\r\nrocky.balboa@fawltytowers2.com Rocky Balboa<\/code><\/pre>\n\n\n\n<h2>Prove the SP can&#8217;t list other groups<\/h2>\n\n\n\n<p>If the SP try to execute a query on the groups endpoint that would operate on a tenant wide scope, the SP doesn&#8217;t have that permission and will receive an &#8220;Insufficient privileges&#8221; error.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1435\" height=\"250\" src=\"https:\/\/blog.redbaronofazure.com\/wp-content\/uploads\/2026\/12\/Screenshot-2026-12-03-151251.png\" alt=\"\" class=\"wp-image-8152\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>What do you do if you have an app that needs to read a set of groups and lists its members? You can grant the app the Graph API Permission Group.Read.Alll and User.ReadBasic.All, but that would mean the app would be able to see all groups in your Entra tenant and that may be a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[464,473,453],"tags":[71],"_links":{"self":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/8148"}],"collection":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8148"}],"version-history":[{"count":2,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/8148\/revisions"}],"predecessor-version":[{"id":8155,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=\/wp\/v2\/posts\/8148\/revisions\/8155"}],"wp:attachment":[{"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.redbaronofazure.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}