簡體   English   中英

更改 Azure 存儲帳戶 TLS 版本

[英]Change Azure Storage Account TLS versions

有人會看到或看到批量更改 Azure Strorage Account TLS 版本的腳本嗎? 我們有數百個存儲帳戶仍啟用了 TLS 1.0 或 1.1,我們希望將它們更改為 1.2。 因為他們中有太多人手動點擊那些真的不是選項..

我現在已經用谷歌搜索並嘗試自己編寫腳本,但我的頭撞到了牆上。

我已經設法遍歷我的所有訂閱和存儲帳戶並將存儲帳戶名稱、資源組和 tls 版本保存到 csv 但現在我需要下一步的幫助:如果它是 1.0,我怎么能將 TLS 版本更改為 1.2或 1.1 使用該數據。

更改 tls 的行是 ( https://learn.microsoft.com/en-us/azure/storage/common/transport-layer-security-configure-minimum-version?tabs=powershell#configure-the-minimum-tls -版本存儲帳戶

Set-AzStorageAccount -ResourceGroupName $rgName `
    -Name $accountName `
    -MinimumTlsVersion TLS1_2

我現在的劇本

$Subscriptions = Get-AzSubscription
$data = foreach ($sub in $Subscriptions) {
    # suppress output on this line
    Write-Host Working with Subscription $sub.Name 
    $null = Get-AzSubscription -SubscriptionName $sub.Name | Set-AzContext
    # let Select-Object output the objects that will be collected in variable $data
    Get-AzStorageAccount | Select-Object StorageAccountName, ResourceGroupName,
                                         @{Name = 'TLSVersion'; Expression = {$_.MinimumTlsVersion}}

}

# write a CSV file containing this data
$data | Export-Csv -Path C:\temp\data.csv -NoTypeInformation

尖端?

• 我想感謝您准備的用於更改跨各種訂閱的多個存儲帳戶的 TLS 版本的腳本。 我還嘗試測試用於更改訂閱中多個存儲帳戶的 TLS 版本的特定 cmdlet,因為我沒有多個訂閱並且效果很好。 此外,如果您無法通過多個訂閱訪問資源,則無法執行此腳本。

此腳本成功執行所需的最低 Azure 資源管理器角色是所有訂閱的“參與者您需要使用該用戶 ID 登錄該訂閱,該訂閱在管理組中的層次結構高於其他訂閱,以便它具有相應地執行和訪問這些訂閱中的資源的權限。

• 因此,可以成功更改用戶 ID 有權訪問的任何訂閱中存儲帳戶的 TLS 版本的實際腳本如下所示。 此外,它還導出一個 CSV 文件,其中包含此腳本訪問的所有存儲帳戶的列表:-

   $Subscriptions = Get-AzSubscription
   $data = foreach ($sub in $Subscriptions) {
Write-Host Working with Subscription $sub.Name 
$null = Get-AzSubscription -SubscriptionName $sub.Name | Set-AzContext
Get-AzStorageAccount | Set-AzStorageAccount -MinimumTlsVersion TLS1_2 @{Name = 'TLSVersion'; Expression = {$_.MinimumTlsVersion}}
}
   $data | Export-Csv -Path C:\data.csv -NoTypeInformation ‘

您還可以配置Azure 策略以在存儲帳戶上強制執行 TLS v2.0,以便通過在 Azure 策略分配中輸入以下 JSON 代碼作為策略來強制在存儲帳戶上使用 TLS v2.0。

{
   "policyRule": {
   "if": {
  "allOf": [
    {
      "field": "type",
      "equals": "Microsoft.Storage/storageAccounts"
    },
    {
      "not": {
        "field": "Microsoft.Storage/storageAccounts/minimumTlsVersion",
        "equals": "TLS1_2"
      }
    }
  ]
},
"then": {
  "effect": "deny"
       }
      }
     }

有關這方面的更多詳細信息,請參閱下面的文檔鏈接:-

https://learn.microsoft.com/en-us/azure/storage/common/transport-layer-security-configure-minimum-version?tabs=powershell#use-azure-policy-to-enforce-the-minimum- tls版本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM