2016-08-03 15 views
0

私はAzure(特にHDInsight)と個人アカウント(仕事/学校のacocunt)を使用して作業しています。Azure Powershellプログラムによるログイン

私は、azureに自動的にログインしていくつかのアクションを実行するスクリプトを作成します。

資格情報でログした後、晴れのpublishsetting jsonファイルを保存するソリューションが見つかりましたが、この設定ファイルには期限切れのトークンが含まれています。

どうすればこの問題に対処できますか?この自動ログオンを実行する最良の方法は何ですか?

おかげ ロベルト

答えて

0

あなたはサービスプリンシパルを作成する必要があります。サービスプリンシパルを作成したら、Role-Based Access Controlを使用して特定のリソースにアクセス許可を割り当てることができます。そこから、あなたのスクリプトは対話的にログインしなくてもサービスプリンシパルとしてログインできます。

この方法の主な問題は、Azureリソースへのアクセスを許可する認証情報が含まれているため、スクリプトへのアクセスを保護することです。

このarticleは良いチュートリアルを持っている:

#First, login as yourself so you can setup the service principal 
Login-AzureRmAccount 

#Password doesn't have to be *your* password, but the password the script will use 
$app = New-AzureRmADApplication –DisplayName "<Your script name>" –HomePage "http://localhost" –IdentifierUris "http://localhost/YourAppName" –Password "<Password>" 

#Create the service principal 
New-AzureRmADServicePrincipal –ApplicationId $app.ApplicationId 

#Assign the Reader role to your new service principal. Other roles listed at 
#https://azure.microsoft.com/en-us/documentation/articles/role-based-access-built-in-roles/ 
New-AzureRmRoleAssignment –RoleDefinitionName Reader –ServicePrincipalName $app.ApplicationId 

$pass = ConvertTo-SecureString "<Password>" -AsPlainText –Force 

#Servce principal username looks like [email protected] 
#the GUID part is $app.ApplicationId and the domain part is found in the Azure portal 
$cred = New-Object -TypeName pscredential –ArgumentList "<Service Principal UserName>", $pass 

Login-AzureRmAccount -Credential $cred -ServicePrincipal –TenantId <TenantId> 
0

それが生産/共有設定とより多くのあなたも行うことができます開発者のセットアップ、慎重でない場合は、パスワードはここにプレーンテキストです:

$SubscriptionName = 'MySubscription' 
$pswd = 'MyPassword' | ConvertTo-SecureString -AsPlainText -Force 
$creds = New-Credential -UserName '[email protected]' -Password $pswd 
Add-AzureRmAccount -Credential $creds 
Set-AzureRmContext -SubscriptionName $SubscriptionName 
Login-AzureRmAccount -Credential $creds -SubscriptionName $SubscriptionName 
0

ここでは、起動するためのいくつかのコマンドを紹介します。情報以下は

$credentials = Get-Credential 

Login-AzureRmAcoount -Credential $credentials 

$SubscriptionName 
Select-AzureRmSubscription -SubscriptionName "The name of your subscription" 
Select-AzureRmSubscription -SubscriptionName $SubscriptionName 
0

はあなた

  • (例えば variablename = loginazure)スクリプトを自動的に紺碧にログイン下記(変数として自動アカウントで資格情報を追加Azureの
  • でオートメーションアカウントを作成するのに役立つかもしれませんPowershellワークフローランブックを使用してください)。

    $AzureLogin = Get-AutomationPSCredential -Name 'loginazure' 
    $AzurePortalLogin = New-Object -TypeName System.Management.Automation.PSCredential$AzureLogin 
    Add-AzureRmAccount -Credential $AzurePortalLogin 
    Get-AzureRmSubscription -SubscriptionName "your subscription name" | Set-AzureRmContext 
    

Inline Script {}

よろしく

タマライSelvan S

内に上記のスクリプトを使用
関連する問題