Our sales team will be using Azure VMs to do sales demos. I would like to be able to allow certain people to be able to start/stop their own VMs at will. I've seen being able to add people as an administrator in the management portal, but this seems to give them access to our whole subscription. I'd like to be able to manage this without having everyone create their own subscription.
Example scenario:
Person A is able to start/stop Person A's dedicated VM.
Person B is able to start/stop Person B's dedicated VM. etc.
In order to allow a user to start and stop a virtual machine you need to create a custom role with the right permissions.
In this answer I will list the steps to follow in order to get this result using the azure command line interface
. You can do the same using the Power Shell
or the Azure Rest Api
(find more information about the commands to be used with the Power Shell
at this link and with the Azure Rest Api
at this link).
newRole.json
):
{
"Name": "Virtual Machine Operator",
"IsCustom": true,
"Description": "Can deallocate, start and restart virtual machines.",
"Actions": [
"Microsoft.Compute/*/read",
"Microsoft.Compute/virtualMachines/start/action",
"Microsoft.Compute/virtualMachines/restart/action",
"Microsoft.Compute/virtualMachines/deallocate/action"
],
"NotActions": [
],
"AssignableScopes": [
"/subscriptions/11111111-1111-1111-1111-111111111111"
]
}
A short explanation of each field of the JSON file:
Name
: the name of the new role. This is the name that will be shown in the azure portalIs Custom
: specifies that it is a user defined roleDescription
: a short description of the role, is is shown as well in the azure portalActions
: the list of action that can be performed by a user associated to this role. Respectively each line allows the user to:
No Actions
: the list of action that can't be performed by a user associated to this role. In this case the list is empty, in general it has to be a subset of the previous field.AssignableScopes
: the set of your subscriptions where the role has to be added. Each code is prefixed by the /subscription/
string. You can find the code of your subscription by accessing the subscription menu (identified by this icon)
and copy the value under SUBSCRIPTION ID
column
azure cli
executing the command az login
. More information about how to install the azure cli and perform the login process respectively here and here.az role definition create --role-definition newRole.json
.After you selected the machine select Access control (Iam)
From the new blade select Add
Role
: Select the role you just created, in our case Virtual Machine Operator
Assign access to
: Azure AD user, group, or application
. Select
: the email associated to the account that needs to start/restart/stop the VMAfter this operations when the user will access the portal she will see the selected VM in the list of the virtual machines. If she selects the virtual machine she will be able to start/restart/stop it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With