简体   繁体   English

在 PowerShell 脚本中加密 Azure 存储帐户密钥

[英]Encrypt Azure Storage account key in powershell script

I'm developing a new powershell script in order to download any blobs from a specific container and the problem is due to security reasons because I do not want to paste in text plain the azure account key.我正在开发一个新的 powershell 脚本,以便从特定容器下载任何 blob,问题是由于安全原因,因为我不想将 azure 帐户密钥粘贴到纯文本中。 So I have implemented a solution using 'ConvertTo-SecureString' command but the problem still exists because when I create a connection string to the blob, there appears a message who said: "Server Failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. HTTP Status Code 403 - HTTP Error".因此,我使用“ConvertTo-SecureString”命令实现了一个解决方案,但问题仍然存在,因为当我创建到 blob 的连接字符串时,会出现一条消息:“服务器无法验证请求。确保授权的值标头的格式正确,包括签名。HTTP 状态代码 403 - HTTP 错误”。

With the key in plain text I'm able to create the connection string properly and then list and download all blobs from the container.使用纯文本密钥,我可以正确创建连接字符串,然后列出并下载容器中的所有 blob。 I tried other solutions for example ' $Credential= New-Object System.Management.Automation.PSCredential ('$ShareUser, $SharePassword)' but there is other problem related with the input is not valid base64 string.我尝试了其他解决方案,例如' $Credential= New-Object System.Management.Automation.PSCredential ('$ShareUser, $SharePassword)' 但还有其他与输入相关的问题不是有效的 base64 字符串。

Do you know how to avoid this issues and create a secure connection string with an Azure Storage Account?您知道如何避免此问题并使用 Azure 存储帐户创建安全连接字符串吗?

Best regards and thanks in advance提前致以最诚挚的问候和感谢

Here a part of my powershell script这是我的PowerShell脚本的一部分

$SecurePassword= Read-Host -AsSecureString | ConvertFrom-SecureString
$SecurePassword | Out-File -FilePath C:\test_blob\pass_file.xml

$ConfigFile= 'C:\Users\\config_file.xml'

IF (Test-Path) { 

[xml]$Config= Get-Content $ConfigFile 

[string] $Server = $Config.Config.Server;
[string] $SharePassword = $Config.Config.SharePassword;

 } ELSE
{
write-host "File do not exists: $ConfigFile"

}


 #BlobStorageInformation   

$StorageAccountName='test_acc'
$Container='test'
$DestinationFolder= 'C:\Users\user1\Blobs'


$Context = New-AzStorageConext -StorageAccountName $StorageAccountName -StorageAccountKey $SharePassword

#List of Blobs 

$ListBlob=@()
$ListBlob+= Get-AzStorageBlob -context $Context -container $Container | Where-Object {$_.LastModified -lt (Get-Date).AddDAys(-1)}

Why would you maintain the password files or enter storage key manually when you have az powershell.当您拥有 az powershell 时,为什么要维护密码文件或手动输入存储密钥。 Just login using az powershell, set the subscription and enjoy !只需使用 az powershell 登录,设置订阅即可享受!

$ResourceGroupName = "YOURRESOURCEGROUPNAME"
$StorageAccountName = "YOURSTORAGEACCOUNTNAME"
$ContainerName = "YOURCONTAINERNAME"
$LocalPath = "D:\Temp"
        
Write-Output 'Downloading Content from Azure blob to local...'
$storageKey = (Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName).value[0]
$storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey
$blobs = Get-AzStorageBlob -Container $ContainerName -Context $storageContext
foreach($blob in $blobs)
{
        Get-AzStorageBlobContent -Container $ContainerName -Context $storageContext -Force -Destination $LocalPath -Blob $blob.Name
}
Write-Output 'Content Downloaded Successfully !!!'

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

相关问题 在PowerShell脚本中加密Azure存储帐户名和密钥 - Encrypt Azure Storage account name and key in PowerShell script 在 Powershell Function 应用程序中获取 Azure 存储帐户密钥 - Get Azure Storage Account Key inside Powershell Function App 如何使用 powershell 将脚本的 output 存储到 azure 存储帐户 - How to store output of script using powershell to azure storage account 查询 Azure 存储帐户已用容量 - PowerShell 脚本? - Query Azure Storage Account Used Capacity - PowerShell Script? 是否可以使用密钥保管库加密文件并使用“ Azure存储数据移动库”将其存储在存储帐户中 - Is it possible to encrypt the file using key vault and store it in storage account using “Azure Storage Data Movement Library” 需要 powershell 脚本来启用存储帐户和密钥保管库的诊断日志记录 - Need powershell script to enable diagnostic logging for Storage account and Key vault 使用Powershell删除Azure存储帐户 - remove azure storage account with powershell 无法使用 ansible 加密 Azure 存储帐户 - Unable to encrypt Azure storage account using ansible Azure Powershell将Azure存储帐户复制到另一个Azure存储帐户 - Azure Powershell to copy azure storage account to another azure storage account 删除 Azure 存储帐户密钥 - Remove Azure Storage Account Key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM