I have a VM which can be accessed via bastion. I want to write a policy definition to deny the access if the user is NOT a member of a specific user group. I started with the following part, but not sure how to continue with the user and user group part in the definition.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Network/bastionHosts"
},
{
"field": "name",
"in": [
"test-vm-bastion"
]
}
]
},
"then": {
"effect": "deny"
}
},
"parameters": {}
}
I need to correct/complete the definition for the given purpos mentioned up.
Azure Policy does not directly evaluate user or group membership for access control, Instead, you can use Azure RBAC to restrict to connections to VM via
BastionCreate a custom RBAC role with below permissions.
Azure virtual machine.NICof theAzure virtual machine.Azure Bastionresource.Azure AD sign-inmethod.Go to Resource Group Where your VM resides > Access control (IAM) > Add > Create a custom role
You can use the following
JSONcode to create a custom role that allows connection to a VM via Bastion. Simply add the code in theJSONsection when creating acustom role.Once you create a
Custom Role, you can assign it to an Azure AD Group at the VM level by navigating to below steps.Go to your Azure VM > Access control (IAM) > Add > Access control (IAM) > Add role assignment
After assigning the
custom roleto anAzure AD group, only the members of that group will be able to access the VM throughBastion.Reference: Connect to a VM using Bastion
Required roles to connect to the VM