2017-02-23 10 views
0

現在、私は2つのサブスクリプションを持っています:S01とS02。私は、S01のリソースにアクセスする必要があるS02で走っているランがあります。1つはランブックとは別のサブスクリプションにアクセスする方法

私はGet-AzureRmSubscription -SubscriptionName S01というコマンドを実行すると、サブスクリプションを見つけることさえできません。以下のコードと出力の例を示します。

$connectionName = "AzureRunAsConnection" 
try 
{ 
    # Get the connection "AzureRunAsConnection " 
    $servicePrincipalConnection = Get-AutomationConnection -Name $connectionName   

    Write-Output "Logging in to Azure..." 
    $Account = Add-AzureRmAccount ` 
     -ServicePrincipal ` 
     -TenantId $servicePrincipalConnection.TenantId ` 
     -ApplicationId $servicePrincipalConnection.ApplicationId ` 
     -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint ` 
     -Verbose ` 
     -ErrorAction Stop 

    Write-Output "***** LOGGED IN ($((Get-AzureRmContext).Subscription.SubscriptionName)). *******" 
} 
catch { 
    if (!$servicePrincipalConnection) 
    { 
     $ErrorMessage = "Connection $connectionName not found." 
     throw $ErrorMessage 
    } 
    else 
    { 
     Write-Error -Message $_.Exception 
     throw $_.Exception 
    } 
} 

Write-Output "Current subscription using Get-AzureRmSubscription:" 
Get-AzureRmSubscription 
Write-Output "===============================================================" 

Write-Output "Switch subscription using Select-AzureRmSubscription:" 
Get-AzureRmSubscription -SubscriptionName "S01" | Select-AzureRmSubscription 
Write-Output "===============================================================" 

Write-Output "Switch subscription using Set-AzureRmContext:" 
Set-AzureRmContext -SubscriptionName "S01" 
Write-Output "===============================================================" 

出力:

Logging in to Azure... 

VERBOSE: Performing the operation "log in" on target "ServicePrincipal account in environment 'AzureCloud'". 

***** LOGGED IN (S02). ******* 

Current subscription using Get-AzureRmSubscription: 

WARNING: Unable to acquire token for tenant 'Common' 

SubscriptionId   : 2f301a20-22a3-b321-2a3c-829ac3d4e39a 
SubscriptionName   : S02 
State      : Enabled 
TenantId     : e2g374a3-8732-3466-9876-a7cd32b208de 
CurrentStorageAccountName : 

=============================================================== 

Switch subscription using Select-AzureRmSubscription: 

WARNING: Unable to acquire token for tenant 'Common' 

ERROR: Get-AzureRmSubscription : Subscription S01 was not found in tenant . Please verify that the subscription 
exists in this tenant. 
At line:37 char:2 
+ Get-AzureRmSubscription -SubscriptionName "S01" | Sele ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : CloseError: (:) [Get-AzureRmSubscription], PSArgumentException 
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.GetAzureRMSubscriptionCommand 


=============================================================== 

Switch subscription using Set-AzureRmContext: 

ERROR: Set-AzureRmContext : Provided subscription S01 does not exist 
At line:41 char:2 
+ Set-AzureRmContext -SubscriptionName "S01" 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : CloseError: (:) [Set-AzureRmContext], ArgumentException 
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand 


=============================================================== 

私はそれがすべてAzureRunAsConnectionとAzureRunAsCertificateを中心に展開してたservicePrincipalを使用して推測します。私の推測では、S01のAzureRunAsConnectを使ってログインする必要があると思います.S01からS02へ証明書を取得する必要があることを意味しますが、S02からRunAsCertificateをエクスポートしてS02にインポートすることは大変です。

私は自分のADアプリケーションを作成しようとしましたが、どちらも動作しないようです。

私はそれが可能でなければならないと確信していますが、どうですか?私は閉じて、正しい方法は何ですか?

P.S.どちらのサブスクリプションも同じAzure ADを「共有」します。

TIA

答えて

1

割り当てられた証明書をサービスプリンシパルに一度エクスポートすることはできません。だから、2つのオプションがあります。証明書を使用して新しいサービスプリンシパルを

  1. を作成し、既存のサービスプリンシパルの証明書のコピーを持っている場合は、2番目のAzureへの認証にそれを使用
  2. 両方のサブスクリプションのために同じ証明書を使用しますサブスクリプション。

あなたが選択したアプローチに関係なく、あなたがサービスプリンシパルを作成するステップの説明によってステップのために、ここで見てみる必要があり、証明書、等:https://docs.microsoft.com/en-us/azure/automation/automation-sec-configure-azure-runas-account#update-an-automation-account-using-powershell

+0

感謝。だから、私は正しい道にいる。私はちょっとそのページに従っていましたが、私は "AsymmetricX509Cert"の周りにぶつかりました。私はWindows 10でスクリプトを実行していましたが、正しいバージョンのPKIモジュールがあります。私が正しくリコールしたら、正しい名前空間を提供するために何かをインストールする必要があります。私はもう一度行くと報告します。ありがとう。 – woter324

+0

コメントアウトしてください: #$ KeyCredential.Type = "AsymmetricX509Cert" #$ KeyCredential.Usage = "Verify" これは私のために働いていました。 –

関連する問題