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



我们有一个PowerShell脚本来安装和配置应用程序。软件和脚本更新是从Windows Azure Storage下载的。该脚本由合作伙伴使用。

目前Azure存储名称和密钥是纯文本形式的。

$context = New-AzureStorageContext
            -StorageAccountName 'myAccountName'
            -StorageAccountKey 'qwertynOc6bmpUhsnFuzSzFLHG7rJgkiakdWpIQ=='
是否有一种方法可以加密Azure存储名称和密钥(或至少密钥),以便合作伙伴不能直接访问Azure存储?

编辑

我也使用Azure表存储日志。

我确实找到了下面的代码,但我猜你必须在使用该脚本的每台机器上重新生成该文件。那对我们没用。

$file = '.myPasswd.txt'
$securedStorageKey = Read-Host -Prompt "Enter Storage Key" -AsSecureString 
ConvertFrom-SecureString $securedStorageKey | Set-Content $file
$accountName = 'myAccountName'
$securedStorageKey = Get-Content $file |  ConvertTo-SecureString
$accountKey = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedStorageKey));
$accountContext = New-AzureStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey

您可能需要考虑通过共享访问签名实现访问。使用SAS,您可以提供对资源的有限访问,并且还可以让该访问定期过期。这确实增加了一些复杂性,因为您需要在某处运行代码来验证用户并生成SAS令牌,但至少您没有放弃对存储资源的完全访问。

这个概念在本文中有很好的解释:http://blogs.msdn.com/b/windowsazurestorage/archive/2012/06/12/introducing-table-sas-shared-access-signature-queue-sas-and-update-to-blob-sas.aspx

我假设你把这个脚本交给你的合作伙伴;没有什么好办法。

New-AzureStorageContext需要凭据才能工作。这意味着,如果您要将此脚本与加密的"密钥"一起分发给您的合作伙伴,您还必须将其与"未加密"方法包装在一起,然后合作伙伴可以使用该方法来解密您的密钥。

如果您不能将密钥分发给您的合作伙伴,我会考虑使用另一种策略来分发和下载您的软件。

配置Azure Storage以提供公共数据如果合作伙伴在下载数据后不需要您的密钥,一种解决方案可能是配置Azure以使用公共url。

http://www.sitefinity.com/documentation/documentationarticles/installation-and-administration-guide/system-settings/configuring-windows-azure-storage-provider

改变你的powershell脚本(你的伙伴正在使用),从公共位置下载脚本/数据/安装,并在那里休息。这样你就不用分发你的密钥了

最新更新