Go SDK for Azure如何在没有服务主体的情况下创建虚拟机?

huangapple go评论85阅读模式
英文:

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
}

Go SDK for Azure如何在没有服务主体的情况下创建虚拟机?

英文:

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
}

Go SDK for Azure如何在没有服务主体的情况下创建虚拟机?

huangapple
  • 本文由 发表于 2023年1月2日 01:24:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/74976179.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定