使用Azure Vault Secret访问Azure容器文件

发布于 2025-02-11 00:04:31 字数 825 浏览 2 评论 0原文

我有使用SAS令牌列出容器文件的脚本,但是在我们的组织中,他们将此SAS令牌存储在Azure Vault中,并与我们共享了读取访问。我们无法从保险库中查看SAS令牌,我们可以使用保险库秘密名称。

请使用Azure Vault Secrets帮助列出容器文件。

 $ContainerSAS = "sas*******"
 $StorageAccountName = "trialstorageaccount3"
 $ContainerName = "trialcontainer1"
 $Blob1Name = "AdventureWorksLT2019.bak"
 $TargetFolderPath = "D:\Anand\Downloads\HTC\DATA\AzureBlob\"
    
 $context = New-AzureStorageContext -StorageAccountName $StorageAccountName -SASToken $ContainerSAS
    
 $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $context
    
 foreach($blob in $blobs) {
     Write-Host $blob.Name
     # New-Item -ItemType Directory -Force -Path $destination_path
     # Get-AzureStorageBlobContent -Container $ContainerName -Blob $blob.Name -Destination $TargetFolderPath -Context $context
 }

I have the script to list the container files using the SAS token, But in our organization, they have stored this SAS token in the Azure vault and shared the read access with us. We are not able to view the SAS token from the vault instead we can use the vault secret name.

Please help to list the container files using Azure vault Secrets.

 $ContainerSAS = "sas*******"
 $StorageAccountName = "trialstorageaccount3"
 $ContainerName = "trialcontainer1"
 $Blob1Name = "AdventureWorksLT2019.bak"
 $TargetFolderPath = "D:\Anand\Downloads\HTC\DATA\AzureBlob\"
    
 $context = New-AzureStorageContext -StorageAccountName $StorageAccountName -SASToken $ContainerSAS
    
 $blobs = Get-AzureStorageBlob -Container $ContainerName -Context $context
    
 foreach($blob in $blobs) {
     Write-Host $blob.Name
     # New-Item -ItemType Directory -Force -Path $destination_path
     # Get-AzureStorageBlobContent -Container $ContainerName -Blob $blob.Name -Destination $TargetFolderPath -Context $context
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦与时光遇 2025-02-18 00:04:31

您可以使用下面的PowerShell脚本列出容器内的斑点。在下面的脚本中,将使用存储的秘密值来创建存储上下文。

$ContainerName="<containerName>"
$StorageAccountName = "<storageAccountName>"
$secretName="<KeyVaultSecretnName>"
$KeyvaultName="<KeyVaultName>"

$secret = Get-AzKeyVaultSecret -VaultName $KeyvaultName -Name $secretName -AsPlainText #Pull the secret value from keyvault and Stored in secret variable as plaintext format

$context= New-AzStorageContext -StorageAccountName $StorageAccountName -SasToken $secret

Get-AzStorageBlob -Container $ContainerName -Context $context | select -Property Name,ContentType

我已经测试了上述PowerShell脚本,并且从我们的目的开始工作。我建议您也从头开始检查相同的情况。

You can use the PowerShell script below to list the blobs inside the container. In the script below Storage context will be created using the secret value that is stored in the keyvault.

$ContainerName="<containerName>"
$StorageAccountName = "<storageAccountName>"
$secretName="<KeyVaultSecretnName>"
$KeyvaultName="<KeyVaultName>"

$secret = Get-AzKeyVaultSecret -VaultName $KeyvaultName -Name $secretName -AsPlainText #Pull the secret value from keyvault and Stored in secret variable as plaintext format

$context= New-AzStorageContext -StorageAccountName $StorageAccountName -SasToken $secret

Get-AzStorageBlob -Container $ContainerName -Context $context | select -Property Name,ContentType

I have tested the above PowerShell Script and it is working from our end . I would suggest you to check the same from your end as well.

々眼睛长脚气 2025-02-18 00:04:31

您可以使用 get-azkeyvaultSecret keyVault 秘密中获取访问令牌,并具有相应的SAS定义。

要检索特定的SAS定义,您必须


# Take a substring of vault secret from the secret identifier 
# https://<keyvaultName>.vault.azure.net/secrets/<vault name>/<vault secret>

$sas = Set-AzKeyVaultManagedStorageSasDefinition -AccountName <StorageAccount Name> -VaultName <vault Name> -Name accountsas -TemplateUri <Template Uri> -SasType 'account' -ValidityPeriod ([System.Timespan]::FromDays(30))

Get-AzKeyVaultSecret -VaultName <Keyvault Name> -Name $sas.Sid.Substring($sas.Sid.LastIndexOf('/')+1)

在检索SAS定义后使用以下PowerShell命令尝试列出容器文件。

请参阅此处有关更多信息。

You can use the Get-AzKeyVaultSecret to get the access token from the keyVault secret with respective SAS Definition.

To retrieve the specific SAS Definition, you have to use the below PowerShell Command


# Take a substring of vault secret from the secret identifier 
# https://<keyvaultName>.vault.azure.net/secrets/<vault name>/<vault secret>

$sas = Set-AzKeyVaultManagedStorageSasDefinition -AccountName <StorageAccount Name> -VaultName <vault Name> -Name accountsas -TemplateUri <Template Uri> -SasType 'account' -ValidityPeriod ([System.Timespan]::FromDays(30))

Get-AzKeyVaultSecret -VaultName <Keyvault Name> -Name $sas.Sid.Substring($sas.Sid.LastIndexOf('/')+1)

After retrieving the SAS Definition try to list the container files.

Refer here for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文