在不登录的情况下使用 Azure API(使用角色)
Using Azure API without login (using roles)
我正在尝试从另一个 azure 虚拟机中列出 azure 虚拟机。我的意思是,我想做的是从前端列出后端成员。但是我不想在我的前端使用凭据,我想使用角色。
例如,在 AWS 中,您可以将角色 (EC2::DescribeInstance) 分配给实例并使用此命令:
aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress]' --output text --filters Name=instance-state-name,Values=running Name=tag:myapp-member,Values=myapp-backend
我可以 运行 该命令而不会在任何地方暴露我的凭据。
如果我 运行 在 Azure 上有这样的东西
az vm list
它说我需要先登录。
而且我找不到如何为实例分配角色。
非常感谢
干杯
为了您的目的,您可以使用 VM Managed Identity 登录 Azure CLI,这种方式不会在 VM 中存储任何凭据。但首先,您需要将角色分配给您的 VM。要分配角色,您可以使用 Azure CLI 命令 az role assignment create
and the steps in Assign a managed identity access to a resource using Azure CLI. Or just in the Azure Portal, you can follow the steps in Assign a managed identity access to a resource by using the Azure portal。 PowerShell 命令也可用。
创建角色后,可以使用Azure CLI命令az login --identity
免凭证登录。
注意:您需要先在虚拟机中安装Azure CLI。
我正在尝试从另一个 azure 虚拟机中列出 azure 虚拟机。我的意思是,我想做的是从前端列出后端成员。但是我不想在我的前端使用凭据,我想使用角色。
例如,在 AWS 中,您可以将角色 (EC2::DescribeInstance) 分配给实例并使用此命令:
aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress]' --output text --filters Name=instance-state-name,Values=running Name=tag:myapp-member,Values=myapp-backend
我可以 运行 该命令而不会在任何地方暴露我的凭据。
如果我 运行 在 Azure 上有这样的东西
az vm list
它说我需要先登录。
而且我找不到如何为实例分配角色。
非常感谢
干杯
为了您的目的,您可以使用 VM Managed Identity 登录 Azure CLI,这种方式不会在 VM 中存储任何凭据。但首先,您需要将角色分配给您的 VM。要分配角色,您可以使用 Azure CLI 命令 az role assignment create
and the steps in Assign a managed identity access to a resource using Azure CLI. Or just in the Azure Portal, you can follow the steps in Assign a managed identity access to a resource by using the Azure portal。 PowerShell 命令也可用。
创建角色后,可以使用Azure CLI命令az login --identity
免凭证登录。
注意:您需要先在虚拟机中安装Azure CLI。