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
(Removes a linked service from Azure Data Factory.) and use New-AzureRmDataFactoryLinkedService
重新link你的存储账户到数据工厂。
请参考这个tutorial。
您需要创建一个 json 文件,如下所示:
{
"name": "AzureStorageLinkedService",
"properties": {
"type": "AzureStorage",
"typeProperties": {
"connectionString": "DefaultEndpointsProtocol=https;AccountName=<accountname>;AccountKey=<accountkey>"
}
}
}
使用New-AzureRmDataFactoryLinkedService
到link。
New-AzureRmDataFactoryLinkedService -ResourceGroupName ADFTutorialResourceGroup -DataFactoryName <Name of your data factory> -File .\AzureStorageLinkedService.json
但是如果你使用 Azure 自动化来执行这个,你会遇到一个问题。在 Runbook 上,您无法存储 json 文件,也许您可以保存在 public github(不安全)上。另一种解决方案是使用 Hybrid Runbook Worker.
我正在寻找一种在 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
(Removes a linked service from Azure Data Factory.) and use New-AzureRmDataFactoryLinkedService
重新link你的存储账户到数据工厂。
请参考这个tutorial。
您需要创建一个 json 文件,如下所示:
{
"name": "AzureStorageLinkedService",
"properties": {
"type": "AzureStorage",
"typeProperties": {
"connectionString": "DefaultEndpointsProtocol=https;AccountName=<accountname>;AccountKey=<accountkey>"
}
}
}
使用New-AzureRmDataFactoryLinkedService
到link。
New-AzureRmDataFactoryLinkedService -ResourceGroupName ADFTutorialResourceGroup -DataFactoryName <Name of your data factory> -File .\AzureStorageLinkedService.json
但是如果你使用 Azure 自动化来执行这个,你会遇到一个问题。在 Runbook 上,您无法存储 json 文件,也许您可以保存在 public github(不安全)上。另一种解决方案是使用 Hybrid Runbook Worker.