Azure vm 预配和用户分配的标识?

Posted

技术标签:

【中文标题】Azure vm 预配和用户分配的标识?【英文标题】:Azure vm provisioning and user assigned identity? 【发布时间】:2022-01-12 03:41:15 【问题描述】:

我正在寻求解决尝试应用到我正在使用 python sdk 创建身份的 vm 的问题。代码:

print("Creating VM " + resource_name)
compute_client.virtual_machines.begin_create_or_update(
    resource_group_name,
    resource_name,
    
        "location": "eastus",
        "storage_profile": 
            "image_reference": 
                # Image ID can be retrieved from `az sig image-version show -g $RG -r $SIG -i $IMAGE_DEFINITION -e $VERSION --query id -o tsv`
                "id": "/subscriptions/..image id"
            
        ,
        "hardware_profile": 
            "vm_size": "Standard_F8s_v2"
        ,
        "os_profile": 
            "computer_name": resource_name,
            "admin_username": "adminuser",
            "admin_password": "somepassword",
            "linux_configuration": 
                "disable_password_authentication": True,
                "ssh": 
                    "public_keys": [
                        
                            "path": "/home/adminuser/.ssh/authorized_keys",
                            # Add the public key for a key pair that can get access to SSH to the runners
                            "key_data": "ssh-rsa …"
                        
                    ]
                
            
        ,
        "network_profile": 
            "network_interfaces": [
                
                    "id": nic_result.id
                
            ]
        ,
        "identity": 
            "type": "UserAssigned",
            "user_assigned_identities": 
                "identity_id":  myidentity 
            
        
    

最后一部分,身份:我在网络上的某个地方找到了(不确定在哪里),但是当我尝试使用它时它失败了,出现了一些奇怪的设置/获取错误。如果我注释掉身份:块,虚拟机将创建良好,但我需要用户分配的身份。我今天大部分时间都在尝试查找有关 begin_create_or_update 选项的信息和有关身份的信息,但我没有运气。我正在寻求有关如何将用户分配的 python 标识应用于我正在创建的虚拟机的帮助。

【问题讨论】:

如果回答对您有帮助,请Accept it as an Answer,以便遇到相同问题的其他人可以找到此解决方案并解决他们的问题。 【参考方案1】:

Set and Get 错误是因为您以错误的方式声明标识块。

如果您有一个现有的用户分配的身份,那么您可以使用如下的身份块:

    "identity": 
        "type": "UserAssigned",
        "user_assigned_identities": 
            '/subscriptions/948d4068-xxxxxxxxxxxxxxx/resourceGroups/ansumantest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mi-identity' : 
            

如您所见,在user_assigned_identities 内它将是:

'User Assigned Identity ResourceID':

而不是

"identity_id":'User Assigned Identity ResourceID'

输出:

【讨论】:

以上是关于Azure vm 预配和用户分配的标识?的主要内容,如果未能解决你的问题,请参考以下文章