Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure 为什么正在使用用户帐户而不是服务主体?_Azure_Jenkins_Azure Cli_Azure Service Principal - Fatal编程技术网

Azure 为什么正在使用用户帐户而不是服务主体?

Azure 为什么正在使用用户帐户而不是服务主体?,azure,jenkins,azure-cli,azure-service-principal,Azure,Jenkins,Azure Cli,Azure Service Principal,我已使用我的帐户“emj”登录,并在Jenkins上执行以下Azure CLI az account show az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>> az account set -s <<Subscription-123>> az account show 以服务主体身份登录 [Pipeli

我已使用我的帐户“emj”登录,并在Jenkins上执行以下Azure CLI

az account show
az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-123>>
az account show
以服务主体身份登录

[Pipeline] sh
+ az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "tenantID",
    "id": "Subscription-456-ID",
    "isDefault": true,
    "managedByTenants": [],
    "name": "Subscription-456",
    "state": "Enabled",
    "tenantId": "tenantID",
    "user": {
      "name": "servicePrincipalID",
      "type": "servicePrincipal"
    }
  },
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "tenantID",
    "id": "Subscription-789-ID",
    "isDefault": false,
    "managedByTenants": [
      {
        "tenantId": "tenantID"
      }
    ],
    "name": "Subscription-789",
    "state": "Enabled",
    "tenantId": "tenantID",
    "user": {
      "name": "servicePrincipalID",
      "type": "servicePrincipal"
    }
  }
]
注意:如果不使用“az帐户集-s”设置订阅,则会显示服务主体帐户


为什么它显示的是用户帐户而不是服务主体?没有考虑“az login--service principal-u-p-t>”的含义是什么?

嗯,不知道为什么会发生这种情况,但要解决这个问题,可以在登录之前使用用户帐户/服务主体,这样不同的上下文就不会混合

例如,您希望通过服务主体凭据运行Azure CLI,它应该是:

az account clear
az login --service-principal -u <<ApplicationId>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-456-ID>>
az account show
az帐户已清除
az登录——服务主体-u-p-t>
az帐户集-s
az帐户显示
然后,如果要通过用户凭据执行操作,只需使用以下命令:

az account clear
az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-123>>
az account show
az帐户已清除
az登录——服务主体-u-p-t>
az帐户集-s
az帐户显示

两个问题:您是否仍登录到您的用户帐户,如果是,您的用户帐户是否有权访问同一订阅,还是只有服务负责人有权访问?是,但是,用户帐户已登录,并且一旦能够使用服务主体执行操作,它就可以访问我们计划撤销的所有订阅。
[Pipeline] sh
+ az account show
{
  "environmentName": "AzureCloud",
  "homeTenantId": "tenantID",
  "id": "Subscription-456-ID",
  "isDefault": true,
  "managedByTenants": [],
  "name": "Subscription-456",
  "state": "Enabled",
  "tenantId": "tenantID",
  "user": {
    "name": "emj@demo.com",
    "type": "user"
  }
}
az account clear
az login --service-principal -u <<ApplicationId>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-456-ID>>
az account show
az account clear
az login --service-principal -u <<UserName>> -p <<Password>> -t <tenantID>>
az account set -s <<Subscription-123>>
az account show