Gallery › Lab Services › Azure built-in policies
Lab Services should require non-admin user for labs
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.0
This policy requires non-admin user accounts to be created for the labs managed through lab-services.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONRequireNonAdminUser.json · 70 lines
{
"properties": {
"displayName": "Lab Services should require non-admin user for labs",
"description": "This policy requires non-admin user accounts to be created for the labs managed through lab-services.",
"mode": "Indexed",
"policyType": "BuiltIn",
"metadata": {
"version": "1.1.0",
"category": "Lab Services"
},
"version": "1.1.0",
"parameters": {
"effect": {
"type": "String",
"defaultValue": "Audit",
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
}
},
"excludeLabPlanId": {
"type": "String",
"metadata": {
"displayName": "Lab Plan Id to exclude",
"description": "Optionally enter the lab Plan Id to exclude for this policy assignment."
},
"defaultValue": ""
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.LabServices/labs"
},
{
"field": "Microsoft.LabServices/labs/labPlanId",
"notEquals": "[parameters('excludeLabPlanId')]"
},
{
"anyOf": [
{
"field": "Microsoft.LabServices/labs/virtualMachineProfile.nonAdminUser.username",
"exists": "false"
},
{
"field": "Microsoft.LabServices/labs/virtualMachineProfile.nonAdminUser.username",
"equals": ""
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/0fd9915e-cab3-4f24-b200-6e20e1aa276a",
"name": "0fd9915e-cab3-4f24-b200-6e20e1aa276a"
}Bylaw0fd9915e-cab3-4f24-b200-6e20e1aa276a.bylaw.ps1 · 41 lines
# Converted from RequireNonAdminUser.json by ConvertTo-Bylaw.
Policy '0fd9915e-cab3-4f24-b200-6e20e1aa276a' {
Properties @{
DisplayName = 'Lab Services should require non-admin user for labs'
Description = 'This policy requires non-admin user accounts to be created for the labs managed through lab-services.'
Version = '1.1.0'
Category = 'Lab Services'
PolicyVersion = '1.1.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter ExcludeLabPlanId @{
Default = ''
DisplayName = 'Lab Plan Id to exclude'
Description = 'Optionally enter the lab Plan Id to exclude for this policy assignment.'
}
Resource 'Microsoft.LabServices/labs' {
When {
Field labPlanId | Must -Not -Be (Param ExcludeLabPlanId)
}
Require 'virtualMachineProfile.nonAdminUser.username exists' {
Field virtualMachineProfile.nonAdminUser.username | Must -Exist
}
Require 'virtualMachineProfile.nonAdminUser.username is not' {
Field virtualMachineProfile.nonAdminUser.username | Must -Not -Be '' -IfPresent
}
}
Effect (Param Effect)
}Source: built-in-policies/policyDefinitions/Lab Services/RequireNonAdminUser.json in Azure/azure-policy, under the MIT licence.
Bylaw