Resolving Azure Maintenance Configuration Authorization Errors - Azure Update Manager

Posted by : on

azure   powershell   troubleshooting   guide

:book: Introduction

While working with Azure, I encountered an authorization error while attempting to create a maintenance configuration. This post discusses the error, its implications, and how to resolve it using a custom role.

:x: Error text

While creating a maintenance configuration, I encountered the following error:

The client ‘[email protected] with object id ‘8b4fd821-05b6-4938-9949-18782893c5ed’ does not have authorization to perform action ‘Microsoft.Resources/deployments/validate/action’ over scope ‘/subscriptions/a1b2c3d4-5e6f-7g8h-9i0j-1k2l3m4n5o6p/resourceGroups/DeleteThisResourceGroup/providers/Microsoft.Resources/deployments/TestConfiguration_1715820611290’ or the scope is invalid. If access was recently granted, please refresh your credentials. (Code: AuthorizationFailed)

This error message indicates a lack of permissions necessary to perform specific actions within the Azure portal.

:gear: Solution

To address this error we will need to create a custom role that specifically includes the necessary permissions for managing maintenance configurations and validating deployments.

:arrow_down: How to get it

GitHub Gist: Create-MaintenanceConfigManagerRole.ps1

I developed a PowerShell script that creates a custom role to grant a user the necessary permissions for managing Maintenance Configurations within a specific Resource Group.

# Create-MaintenanceConfigManagerRole.ps1
# Script to create a custom role for managing Azure Maintenance Configurations
# Author: Blake Drumm ([email protected])
# Website: https://blakedrumm.com/blog/resolve-azure-maintenance-configuration-error/
# Date created: May 15th, 2024

# Define custom variables
$subscriptionId = "a1b2c3d4-5e6f-7g8h-9i0j-1k2l3m4n5o6p"
$resourceGroupName = "ResourceGroupName"
$customRoleName = "Maintenance Configuration Manager - Resource Group: $resourceGroupName"
$userPrincipalName = "[email protected]"

# Define the custom role as a JSON string with the subscription ID and resource group name directly replaced
$customRoleJson = @"
{
    "Name": "$customRoleName",
    "IsCustom": true,
    "Description": "Allows management of maintenance configurations, validate and write deployments, read and write virtual machines, and write configuration assignments.",
    "Actions": [
        "Microsoft.Maintenance/maintenanceConfigurations/read",
        "Microsoft.Maintenance/maintenanceConfigurations/write",
        "Microsoft.Maintenance/maintenanceConfigurations/delete",
        "Microsoft.Resources/deployments/validate/action",
        "Microsoft.Resources/deployments/write",
        "Microsoft.Maintenance/configurationAssignments/write",
        "Microsoft.Compute/virtualMachines/read",
        "Microsoft.Compute/virtualMachines/write"
    ],
    "NotActions": [],
    "AssignableScopes": [
        "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName"
    ]
}
"@

# Convert the JSON string to a PowerShell object
$customRole = $customRoleJson | ConvertFrom-Json

# Create the custom role
New-AzRoleDefinition -Role $customRole

# Define the scope
$scope = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName"

# Assign the custom role to the user
New-AzRoleAssignment -RoleDefinitionName $customRoleName -UserPrincipalName $userPrincipalName -Scope $scope

<#
    Copyright (c) Microsoft Corporation. MIT License
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#>

:bulb: How to use it

To implement this solution:

  1. Modify the script with your specific details, including subscription ID, resource group name, and user principal name.
  2. Execute the script in your PowerShell environment to create the custom role and assign it.
  3. Verify the permissions are correctly applied by attempting to create a Maintenance Configuration again.

:speech_balloon: Conclusion

By understanding and addressing Azure permission errors through custom role creation, administrators can ensure smoother operation, enhance security, and reduce manual workload. Feel free to modify the script to fit your specific needs and share your feedback on how it worked for you! :v:

Page Views


Share on:
About Blake Drumm
Blake Drumm

I like to collaborate and work on projects. My skills with Powershell allow me to quickly develop automated solutions to suit my customers, and my own needs.

Email :

Website :

About Blake Drumm

My name is Blake Drumm, I am working on the Azure Monitoring Enterprise Team with Microsoft. Currently working to update public documentation for System Center products and write troubleshooting guides to assist with fixing issues that may arise while using the products. I like to blog on Operations Manager and Azure Automation products, keep checking back for new posts. My goal is to post atleast once a month if possible.

Follow @blakedrumm
Useful Links