简体   繁体   English

如何创建 Azure 策略?

[英]How to create Azure Policy?

I have written some automation (using az command line) that creates virtual machines for us.我已经编写了一些为我们创建虚拟机的自动化程序(使用 az 命令行)。
However, since users have contributor access to the various subscriptions they login to the portal and create the vm's manually.但是,由于用户对各种订阅具有贡献者访问权限,因此他们登录到门户并手动创建虚拟机。
I would like to prevent the users from creating the vms by logging into the portal.我想阻止用户通过登录门户创建虚拟机。
How do I leverage Azure Policy to enforce this?我如何利用 Azure 策略来执行此操作?

I tried to reproduce this scenario on my end and was able to restrict users with Contributor Role from creating VM via Portal.我试图在我这边重现这个场景,并且能够限制具有贡献者角色的用户通过门户创建 VM。

I created one Policy Definition like below: -我创建了一个如下所示的策略定义:-

"parameters": {},
"policyRule": 
{
"if": {
"anyOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "Microsoft.Authorization/roleAssignments/roleDefinitionId",
"contains": "a8f97275-2685-41ce-a61d-dc550cd090f8"
}
]
},
"then": 
{
"effect": "deny"
}
}

在此处输入图像描述在此处输入图像描述 And assigned this policy at the subscription level: -并在订阅级别分配此策略:-

在此处输入图像描述

I have one user with Contributor role like below:我有一个具有如下贡献者角色的用户:

在此处输入图像描述

Now, when the user with Contributor role tried to create a VM, the VM creation was disallowed by the Policy like below:现在,当具有Contributor角色的用户尝试创建虚拟机时,虚拟机创建被如下策略禁止

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用CLI创建Azure备份策略? - How to create azure backup policy using CLI? 如何在 azure 中创建和应用标记策略 - How to Create and Apply a Tagging Policy in azure 使用 Terraform 创建 Azure 策略 - Create Azure policy with Terraform 如何在 Azure API-manager 策略中创建和使用列表? - How to create and use list in Azure API-manager policy? 如何为同一Azure blob容器创建多个存储的访问策略? - How to create multiple stored access policy for the same Azure blob container? 如何在 azure 服务总线命名空间中创建主题、订阅和 SAS 策略? - How to create topic, subscription and SAS policy in azure service bus namespace? 如何从 Python 中的存储访问策略创建 Azure 容器 SAS - How to create Azure Container SAS from Stored Access Policy in Python 如何创建验证资源组名称的Azure策略 - How can I create an Azure policy that validates Resource Group Names 如何使用共享访问策略连接字符串在 azure 服务总线中创建 SAS 策略 - How to create SAS policy in azure service bus using shared access policy connectionstring 如何在 Azure 门户中为 Azure Blob 容器创建具有存储访问策略的共享访问签名? - How to create a shared access signature with a stored access policy for an Azure Blob container in Azure Portal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM