Azure policy to auto add user group in resource group contributors

%3CLINGO-SUB%20id%3D%22lingo-sub-1555720%22%20slang%3D%22en-US%22%3EAzure%20policy%20to%20auto%20add%20user%20group%20in%20resource%20group%20contributors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1555720%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EThis%20is%20my%20first%20project%20in%20Azure.%20Please%20avoid%20if%20any%20mistake.%20I%20have%20a%20user%20group%20%22Azure%20Cross%20Team%20Contributors%22.%20I%20want%20to%20add%20it%20in%20resource%20group%20contributors%20by%20default%20whenever%20I%20create%20any%20resource%20group.%20I%20got%20to%20know%20there%20is%20policy%2C%20But%20not%20able%20to%20write%20policy%20rule.%20What%20would%20be%20policy%20rule%20for%20this%20scenario.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1558194%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20policy%20to%20auto%20add%20user%20group%20in%20resource%20group%20contributors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1558194%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F744717%22%20target%3D%22_blank%22%3E%40ashishnm%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMaybe%20i%20got%20it%20wrong%2C%20but%20you%20want%20this%20Group%20to%20be%20added%20as%20the%20%22Standard%22%20Admin%20Group%20for%20the%20Resources%2C%20right%3F%20Maybe%20you%20should%20take%20a%20look%20on%20Azure%20Management%20Groups%2C%20that%20might%20be%20a%20better%20and%20easier%20Solution%20and%20will%20offer%20you%20even%20more%20functionality.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20learn%20more%20about%20Management%20Groups%2C%20please%20take%20a%20look%20here%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fgovernance%2Fmanagement-groups%2Foverview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fgovernance%2Fmanagement-groups%2Foverview%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20Regards%2C%20Peter%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1558276%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20policy%20to%20auto%20add%20user%20group%20in%20resource%20group%20contributors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1558276%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F744717%22%20target%3D%22_blank%22%3E%40ashishnm%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20would%20help%20to%20get%20more%20details%20about%20your%20scenario%2C%20but%20based%20on%20what%20you%20wrote%2C%20I%20don't%20think%20there%20is%20a%20way%20how%20to%20write%20a%20custom%20policy%20that%20would%20assign%20a%20certain%20AAD%20group%20some%20role%20on%20a%20RG%20scope.%20Azure%20Policy%20is%20dealing%20with%20resources%20and%20its%20properties.%20Role%20assignment%20is%20not%20in%20its%20scope.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDepending%20what%20you%20are%20trying%20to%20achieve%2C%20you%20can%20either%20operate%20within%20a%20single%20subscription%20or%20across%20subscriptions.%20For%20the%20latter%20case%2C%20leveraging%20Management%20Groups%20(and%20assign%20e.g.%20a%20Contributor%20role%20for%20your%20AAD%20group)%20could%20make%20sense%20(as%20it%20was%20suggested%20by%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F294699%22%20target%3D%22_blank%22%3E%40Peter_Beckendorf%3C%2FA%3E%26nbsp%3B).%20Please%20keep%20in%20mind%20the%20inheritance%20principle%2C%20meaning%20that%20members%20of%20that%20group%20will%20have%20Contributor%20permissions%20in%20all%20subscriptions%20that%20are%20member%20of%20such%20Management%20Group.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20work%20in%20a%20context%20of%20a%20single%20subscription%2C%20I%20am%20wondering%20why%20you%20don't%20use%20role%20assignment%20on%20that%20subscription%20level%3F%20Is%20it%20because%20you%20want%20to%20control%20when%20and%20what%20Resource%20Groups%20are%20being%20created%3F%3C%2FP%3E%3CUL%3E%3CLI%3Eif%20no%2C%20assigning%20a%20role%20for%20that%20group%20in%20your%20subscription%20is%20the%20easiest%20option%2C%20since%20this%20assignment%20will%20propagate%20to%20all%20existing%20any%20any%20new%20RGs%3C%2FLI%3E%3CLI%3EIf%20yes%2C%20then%20doing%20role%20assignment%20for%20that%20group%20on%20a%20subscription%20level%20(or%20even%20MG-level)%20won't%20work%20for%20you%2C%20since%20the%20users%20(members%20of%20that%20group)%20will%20inherit%20permission%20to%20create%20RGs.%20In%20this%20case%20I%20would%20advise%20you%20to%20implement%20an%20event-driven%20automation%20solution%20that%20would%3A%3CUL%3E%3CLI%3Esubscribe%20to%20Event%20Log%20'Create%20Resource%20Group'%20event%2C%20either%20by%20using%20Azure%20Monitor%20alerts%20(and%20action%20groups)%20or%20Event%20Grid%20subscription%3C%2FLI%3E%3CLI%3Eprocess%20that%20event%20in%20either%20Azure%20Automation%20(runbook)%20or%20Azure%20Function%20(PowerShell)%20and%20do%20the%20role%20assignment%20for%20that%20newly%20created%20RG%20for%20your%20target%20AAD%20group%3C%2FLI%3E%3CLI%3Ein%20this%20way%2C%20you%20keep%20control%20what%20RGs%20are%20being%20created%20while%20that%20team%20gets%20necessary%20permissions%20to%20work%20in%20new%20RGs.%3C%2FLI%3E%3C%2FUL%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

This is my first project in Azure. Please avoid if any mistake. I have a user group "Azure Cross Team Contributors". I want to add it in resource group contributors by default whenever I create any resource group. I got to know there is policy, But not able to write policy rule. What would be policy rule for this scenario.

2 Replies

Hi @ashishnm,

 

Maybe i got it wrong, but you want this Group to be added as the "Standard" Admin Group for the Resources, right? Maybe you should take a look on Azure Management Groups, that might be a better and easier Solution and will offer you even more functionality.

 

To learn more about Management Groups, please take a look here:

 

https://docs.microsoft.com/en-us/azure/governance/management-groups/overview

 

Kind Regards, Peter 

Hi @ashishnm ,

 

It would help to get more details about your scenario, but based on what you wrote, I don't think there is a way how to write a custom policy that would assign a certain AAD group some role on a RG scope. Azure Policy is dealing with resources and its properties. Role assignment is not in its scope.

 

Depending what you are trying to achieve, you can either operate within a single subscription or across subscriptions. For the latter case, leveraging Management Groups (and assign e.g. a Contributor role for your AAD group) could make sense (as it was suggested by @Peter_Beckendorf ). Please keep in mind the inheritance principle, meaning that members of that group will have Contributor permissions in all subscriptions that are member of such Management Group.

 

If you work in a context of a single subscription, I am wondering why you don't use role assignment on that subscription level? Is it because you want to control when and what Resource Groups are being created?

  • if no, assigning a role for that group in your subscription is the easiest option, since this assignment will propagate to all existing any any new RGs
  • If yes, then doing role assignment for that group on a subscription level (or even MG-level) won't work for you, since the users (members of that group) will inherit permission to create RGs. In this case I would advise you to implement an event-driven automation solution that would:
    • subscribe to Event Log 'Create Resource Group' event, either by using Azure Monitor alerts (and action groups) or Event Grid subscription
    • process that event in either Azure Automation (runbook) or Azure Function (PowerShell) and do the role assignment for that newly created RG for your target AAD group
    • in this way, you keep control what RGs are being created while that team gets necessary permissions to work in new RGs.