簡體   English   中英

Azure旋轉存儲密鑰並更新ADF鏈接服務

[英]Azure Rotate Storage Keys and Update ADF Linked Service

我正在尋找一種在Azure自動化中實現鍵旋轉的方法,我找到了一種創建Powershell Runbook的方法,並實現了以下代碼:

$azureAccountName = <acct_name>
$azurePassword = ConvertTo-SecureString <pass> -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAccountName, $azurePassword)
Login-AzureRmAccount -ServicePrincipal -Credential $psCred -TenantId <tenant id> -SubscriptionId <sub id>

#Optionally you may set the following as parameters
$StorageAccountName = <storage acct name>
$RGName = <rg name>

#Key name. For example key1 or key2 for the storage account
New-AzureRmStorageAccountKey -ResourceGroupName $RGName -Name $StorageAccountName -KeyName "key1" -Verbose
New-AzureRmStorageAccountKey -ResourceGroupName $RGName -Name $StorageAccountName -KeyName "key2" -Verbose

當我運行它時,它起作用了,但是,它破壞了我的Azure數據工廠鏈接服務。 我意識到鏈接服務的連接字符串已損壞,因此我着手嘗試在自動化腳本中重置連接字符串。 我能夠通過執行以下操作獲取連接字符串:

(Get-AzureRmDataFactoryLinkedService -DataFactoryName <adf name> -ResourceGroupName <rg name> -Name <ls name>).Properties.TypeProperties.ConnectionString

我找不到使用Powershell和Azure自動設置該連接字符串的方法。

您可以使用Power Shell來保持此連接。 但是,您需要使用Remove-AzureRmDataFactoryLinkedService (從Azure數據工廠中刪除鏈接的服務。),並使用New-AzureRmDataFactoryLinkedService將存儲帳戶重新鏈接到數據工廠。

請參考本教程

您需要創建一個json文件,如下所示:

{
    "name": "AzureStorageLinkedService",
    "properties": {
        "type": "AzureStorage",
        "typeProperties": {
            "connectionString": "DefaultEndpointsProtocol=https;AccountName=<accountname>;AccountKey=<accountkey>"
        }
    }
 }

使用New-AzureRmDataFactoryLinkedService進行鏈接。

New-AzureRmDataFactoryLinkedService -ResourceGroupName ADFTutorialResourceGroup -DataFactoryName <Name of your data factory> -File .\AzureStorageLinkedService.json

但是,如果使用Azure自動化執行此操作,則會遇到一個問題。 在Runbook上,您無法存儲json文件,也許可以保存在公共github上(不安全)。 另一個解決方案是使用Hybrid Runbook Worker

暫無
暫無

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

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