|
| 1 | +# Get formatted RBAC roles Script |
| 2 | + |
| 3 | +Use this script to format a given raw 'Roles' table from Azure to the format required by either bicep or ARM in any RBAC deployment. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +### _Navigation_ |
| 8 | + |
| 9 | +- [Location](#location) |
| 10 | +- [How it works](#what-it-does) |
| 11 | +- [How to use it](#how-to-use-it) |
| 12 | + - [Examples](#examples) |
| 13 | + |
| 14 | +--- |
| 15 | +# Location |
| 16 | + |
| 17 | +You can find the script under `/utilities/tools/Get-FormattedRBACRoles.ps1` |
| 18 | + |
| 19 | +# How it works |
| 20 | + |
| 21 | +1. From the provided raw and plain roles list, create a list of only the contained role names |
| 22 | +1. Fetch all available roles from Azure |
| 23 | +1. Go through all provided role names, match them with those from Azure to get the matching RoleDefinitionId and format a string like `'<roleName>': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','<roleDefinitionId>')` for each match |
| 24 | +1. Print the result to the terminal |
| 25 | + |
| 26 | +# How to use it |
| 27 | + |
| 28 | +The script does not accept any custom parameter per se, but expects you to replace the placeholder in the `rawRoles` variable inside the script |
| 29 | + |
| 30 | +```PowerShell |
| 31 | +$rawRoles = @' |
| 32 | + <paste the table here> |
| 33 | +'@ |
| 34 | +``` |
| 35 | + |
| 36 | +To get the list of roles in the expected format: |
| 37 | +1. Navigate to Azure |
| 38 | +1. Deploy one instance of the service you want to fetch the roles for |
| 39 | +1. Navigate to the `Access Control (IAM)` blade in the resource |
| 40 | +1. Open the `Roles` tab |
| 41 | +1. Set the `Type` in the dropdown to `BuiltInRole` |
| 42 | + |
| 43 | + <img src="media/rbacRoles.png" alt="Complete deployment flow filtered" height="300"> |
| 44 | + |
| 45 | +1. Select and copy the entire table as is to the PowerShell variable. |
| 46 | + |
| 47 | + The result should look similar to |
| 48 | + |
| 49 | + ```PowerShell |
| 50 | + $rawRoles = @' |
| 51 | + Owner |
| 52 | + Grants full access to manage all resources, including the ability to assign roles in Azure RBAC. |
| 53 | + builtInRole |
| 54 | + General |
| 55 | + View |
| 56 | + Contributor |
| 57 | + Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries. |
| 58 | + BuiltInRole |
| 59 | + General |
| 60 | + View |
| 61 | + Reader |
| 62 | + View all resources, but does not allow you to make any changes. |
| 63 | + BuiltInRole |
| 64 | + General |
| 65 | + View |
| 66 | + '@ |
| 67 | + ``` |
| 68 | +1. Execute the script. The output for the above example would be |
| 69 | + |
| 70 | + ```yml |
| 71 | + VERBOSE: Bicep |
| 72 | + VERBOSE: ----- |
| 73 | + 'Owner': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','8e3af657-a8ff-443c-a75c-2fe8c4bcb635') |
| 74 | + 'Contributor': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','b24988ac-6180-42a0-ab88-20f7382dd24c') |
| 75 | + 'Reader': subscriptionResourceId('Microsoft.Authorization/roleDefinitions','acdd72a7-3385-48ef-bd42-f606fba81ae7') |
| 76 | + VERBOSE: |
| 77 | + VERBOSE: ARM |
| 78 | + VERBOSE: --- |
| 79 | + "Owner": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','8e3af657-a8ff-443c-a75c-2fe8c4bcb635')]", |
| 80 | + "Contributor": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','b24988ac-6180-42a0-ab88-20f7382dd24c')]", |
| 81 | + "Reader": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions','acdd72a7-3385-48ef-bd42-f606fba81ae7')]", |
| 82 | + ``` |
| 83 | +1. Copy the output into the RBAC file into the `buildInRoleNames` variable. Again, for the same example using bicep this would be: |
| 84 | + |
| 85 | + ```bicep |
| 86 | + var builtInRoleNames = { |
| 87 | + 'Owner': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635') |
| 88 | + 'Contributor': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c') |
| 89 | + 'Reader': subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') |
| 90 | + } |
| 91 | + ``` |
| 92 | + |
| 93 | +For further details on how to use the function please refer to the script's local documentation. |
| 94 | +> **Note:** The script must be loaded before the function can be invoked |
0 commit comments