【问题标题】:How can I set up my Azure account in order to make ARM deployments via the REST API?如何设置我的 Azure 帐户以通过 REST API 进行 ARM 部署?
【发布时间】:2018-07-10 17:27:00
【问题描述】:

我有一个 Azure 帐户,我想使用 ASP.NET 库来部署 ARM 模板。我注意到在 Azure 门户生成的 Deployment 类中(在我从门户下载的 DeploymentHelper.cs 文件中)我有以下我需要的字段提供我自己的数据:

string subscriptionId = "your-subscription-id";
string clientId = "your-service-principal-clientId";
string clientSecret = "your-service-principal-client-secret";
string resourceGroupName = "resource-group-name";
string deploymentName = "deployment-name";
string resourceGroupLocation = "resource-group-location";
string pathToTemplateFile = "path-to-template.json-on-disk";
string pathToParameterFile = "path-to-parameters.json-on-disk";
string tenantId = "tenant-id";

我很难处理这些:

string clientId = "your-service-principal-clientId";
string clientSecret = "your-service-principal-client-secret";

我知道 subscriptionId 我可以在 Subscriptions 刀片中获得。我也知道 tenantId 我可以在 Directory ID 字段下的 Azure Active Directory > Properties 刀片中获取。

我已关注 this documentation page 以尝试在 Azure Active Directory 上设置 App Registration,我已经阅读了获得clientIdclientSecret 值。我认为值得一提的是,我对 Active DirectoryAzure Active Directory 没有任何经验。

当我关注文档时,我的第一个问题是这个刀片:

我不知道应该在“登录 URL”字段中输入什么。我尝试用我的个人网站填充它只是因为它是必需的(可能是我的第一个错误)。然后使用已注册的应用程序,我进入“Application ID”并在我的代码中使用该值作为 clientId

然后我在“Settings”刀片中生成密钥并将其用作我的代码中的 clientSecret

但是,当我运行我的代码时,我收到以下错误:

Exception thrown: 'Microsoft.Rest.Azure.CloudException' in System.Private.CoreLib.dll

An exception of type 
'Microsoft.Rest.Azure.CloudException' occurred in System.Private.CoreLib.dll but was not handled in user code

Operation returned an invalid status code 'Forbidden'

我不想为了通过 Azure 进行部署而设置任何花哨的 Azure AD。我正在我的个人帐户上尝试此操作,所以它不像设置 AD 环境。

【问题讨论】:

标签: azure azure-active-directory azure-resource-manager


【解决方案1】:

我不知道应该在“登录 URL”字段中输入什么。我尝试用我的个人网站填充它,只是因为它是必需的(可能是我的第一个错误)。

如果您开发 Web 应用程序,您可以将 Web 应用程序寻址为登录 url。在您的情况下,您可以添加一个有效的 url 地址。您可以添加您的个人网站。

操作返回无效的状态代码“禁止”

这意味着您无权将资源部署到订阅。

您需要为 WebApplication 分配角色。更多信息请参考how to registry an Azure AD application and assigin role

【讨论】:

  • 没错,我以前也这样做过。但是我第一次没有给应用程序适当的权限。我又做了一次,它奏效了。谢谢!
猜你喜欢
  • 2021-11-05
  • 2017-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-02
  • 2016-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多