英文:
How does the Go SDK for Azure create a virtual machine without a service principal?
问题
这是一个来自Go SDK的示例代码,通过部署ARM模板创建一个虚拟机。它要求你包含来自服务主体的clientId和clientSecret。
这是一个使用Go SDK for Azure创建虚拟机的示例代码。它需要一个订阅ID,但不需要服务主体(clientId、clientSecret)。它也不会自动创建服务主体。
我认为创建虚拟机需要一个服务主体,但是GO SDK示例可以在不指定服务主体的情况下创建虚拟机。关于服务主体和虚拟机,我漏掉了什么?
英文:
This sample code from the Go SDK creates a virtual machine by deploying an ARM template. It requires that you include the clientId and clientSecret from a service principal.
This sample code from the Go SDK creates a virtual machine using the Go SDK for Azure. It requires a subscription ID, but no service principal (client id, client secret) is required. It does not create a service principal automatically either.
I would think that a service principal would be required to create a VM, but the GO SDK example is able to create a VM without specifying a service principal. What a I missing about service principals and virtual machines?
答案1
得分: 1
它使用NewDefaultAzureCredential,这个类从环境中获取身份验证信息(例如Azure CLI、环境变量)- 请参阅文档
func connectionAzure() (azcore.TokenCredential, error) {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, err
}
return cred, nil
}
英文:
It uses the NewDefaultAzureCredential, this class retrieves the auth info from the environment (e.g. azure CLI, environment vars) - see docs
func connectionAzure() (azcore.TokenCredential, error) {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, err
}
return cred, nil
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论