[英]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.