簡體   English   中英

在 Azure DevOps Powershell 管道任務中獲取自己的服務主體名稱

[英]Get own Service Principal Name in an Azure DevOps Powershell pipeline task

在 Azure DevOps 發布管道中使用 system.debug=true 運行 Azure Powershell 任務時,您將獲得類似於以下內容的輸出:

# anonymized
...
2019-09-05T12:19:41.8983585Z ##[debug]INPUT_CONNECTEDSERVICENAMEARM: '7dd40b2a-1c37-4c0a-803e-9b0044a8b54e'
2019-09-05T12:19:41.9156487Z ##[debug]ENDPOINT_URL_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: 'https://management.azure.com/'
2019-09-05T12:19:41.9188051Z ##[debug]ENDPOINT_AUTH_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: '********'
2019-09-05T12:19:41.9221892Z ##[debug]ENDPOINT_DATA_7dd40b2a-1c37-4c0a-803e-9b0044a8b54e: '{"subscriptionId":"b855f753-d5b3-48f4-b7cd-5beb58fb5508","subscriptionName":"Entenhausen","environment":"AzureCloud","creationMode":"Automatic","azureSpnRoleAssignmentId":"5ddcc3fe-f93c-4771-8041-50b49f76b828","azureSpnPermissions":"[{\"roleAssignmentId\":\"5ddcc3fe-f93c-4771-8041-50b49f76b828\",\"resourceProvider\":\"Microsoft.RoleAssignment\",\"provisioned\":true}]","spnObjectId":"76055cb6-3b75-4191-9309-306b32dad443","appObjectId":"e4b90b9d-7a73-42a3-ae6e-4daec910def4","environmentUrl":"https://management.azure.com/","galleryUrl":"https://gallery.azure.com/","serviceManagementUrl":"https://management.core.windows.net/","resourceManagerUrl":"https://management.azure.com/","activeDirectoryAuthority":"https://login.microsoftonline.com/","environmentAuthorityUrl":"https://login.windows.net/","graphUrl":"https://graph.windows.net/","managementPortalUrl":"https://manage.windowsazure.com/","armManagementPortalUrl":"https://portal.azure.com/","activeDirectoryServiceEndpointResourceId":"https://management.core.windows.net/","sqlDatabaseDnsSuffix":".database.windows.net","AzureKeyVaultDnsSuffix":"vault.azure.net","AzureKeyVaultServiceEndpointResourceId":"https://vault.azure.net","StorageEndpointSuffix":"core.windows.net","EnableAdfsAuthentication":"false"}'
2019-09-05T12:19:41.9284444Z ##[debug]AuthScheme ServicePrincipal
...

我需要將 Azure DevOps 連接的 SPN 添加到資源。 更改訂閱或管道時,SPN 也會更改,我不想對值進行硬編碼。 由於該值打印在 system.debug=true 輸出中,我想知道如何在管道任務中訪問我自己的 SPN。 是否可以使用 Powershell 以某種方式讀出spnObjectId":"76055cb6-3b75-4191-9309-306b32dad443"

可以使用 Get-AzureRmContext 訪問有關服務主體的信息,但信息有限,並且有些信息在日志中被混淆,因此您需要再次調用 Get-AzureRmServicePrincipal 以訪問 ObjectId

$Context = Get-AzureRmContext
$AzureDevOpsServicePrincipal = Get-AzureRmADServicePrincipal -ApplicationId $Context.Account.Id
$ObjectId = $AzureDevOpsServicePrincipal.Id

$Context.Account.Id公開的 Id 是服務主體 ApplicationId

管道任務中的 SPN 只不過是您傳遞給任務的 Azure 訂閱。 您可以單擊管理連接並復制連接下的 SPN 詳細信息,並根據需要使用它們。 但是,我不確定您為什么要直接使用 SPN,因為您始終可以使用 Azure Powershell 任務,只需選擇訂閱即可。 存儲 Connection 后,您始終可以在不同的管道中重用它。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM