简体   繁体   English

Azure旋转存储密钥并更新ADF链接服务

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

I am looking for a way to implement doing key rotation in an Azure Automation I have found a way to create a powershell runbook and have implemented the following code: 我正在寻找一种在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

When I ran this, it worked, however, it broke my Azure Data Factory Linked Service. 当我运行它时,它起作用了,但是,它破坏了我的Azure数据工厂链接服务。 I realized that the connection string for the linked service is broken, so I set out to try to reset the connection string in the automation script. 我意识到链接服务的连接字符串已损坏,因此我着手尝试在自动化脚本中重置连接字符串。 I was able to get the connection string by doing: 我能够通过执行以下操作获取连接字符串:

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

I cannot find a way to set this connection string using powershell and azure automation. 我找不到使用Powershell和Azure自动设置该连接字符串的方法。

You could use Power Shell to rest this connection. 您可以使用Power Shell来保持此连接。 But you need use Remove-AzureRmDataFactoryLinkedService (Removes a linked service from Azure Data Factory.) and use New-AzureRmDataFactoryLinkedService to re-link your storage account to data factory. 但是,您需要使用Remove-AzureRmDataFactoryLinkedService (从Azure数据工厂中删除链接的服务。),并使用New-AzureRmDataFactoryLinkedService将存储帐户重新链接到数据工厂。

Please refer to this tutorial . 请参考本教程

You need create a json file like below: 您需要创建一个json文件,如下所示:

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

Use New-AzureRmDataFactoryLinkedService to link. 使用New-AzureRmDataFactoryLinkedService进行链接。

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

But if you use Azure automation to execute this, there is a issue you will meet. 但是,如果使用Azure自动化执行此操作,则会遇到一个问题。 On runbook, you could not store a json file, maybe you could save on a public github(no safe). 在Runbook上,您无法存储json文件,也许可以保存在公共github上(不安全)。 Another solution is use Hybrid Runbook Worker . 另一个解决方案是使用Hybrid Runbook Worker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Blob 存储密钥更新到应用程序 - Update Blob Storage Keys to apps 如何更新 Azure 数据工厂链接服务中使用的 Cosmos DB 帐户密钥 - How do you update the Cosmos DB account key used in an Azure Data Factory linked service Microsoft Azure Blob存储更新 - Microsoft Azure Blob storage update 如何使用 API 测试 Azure 数据工厂链接服务 - How to test Azure Data factory linked service using API 使用 PowerShell 更新 Azure DevOps 中的服务挂钩 - Update Service Hook in Azure DevOps Using PowerShell Azure-Powershell 对存储帐户启用文件服务加密 - Azure-Powershell Enable File Service Encryption on storage account 通过 Powershell 通过 Azure Key Vault 管理的密钥访问 Azure 存储 - Accessing Azure Storage through keys managed by Azure Key Vault via Powershell 如何使用Powershell将Azure表存储中实体的属性更新为null? - How to use Powershell to update property of an entity in Azure Table Storage to null? Powershell的更新实体命令用于蔚蓝表存储 - Powershell's Update Entity command for azure table storage 使用 PowerShell 更新数据集/管道/链接服务/触发器的 Azure 数据工厂属性 - Update Azure Data Factory Properties for Datasets/Pipelines/Linked Services/Triggers using PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM