要求安全傳輸以確保安全連線

✔️ 適用於:Azure Blob 儲存體、Azure Data Lake Storage、Azure 佇列儲存體、Azure 資料表儲存體

✖️ 不適用於:Azure 檔案儲存體(Microsoft.Storage或Microsoft.FileShares)

您可以透過設定儲存體帳戶的要求安全傳輸屬性來僅接受來自安全連線的要求。 當您要求安全傳輸時,源自不安全連線的任何要求都會被拒絕。 要求所有儲存帳戶都使用安全傳輸。

當需要安全傳輸時,必須透過 HTTPS 呼叫 Azure 儲存體 REST API 操作。 透過 HTTP 提出的任何要求都會遭到拒絕。 根據預設,當您建立儲存體帳戶時,需要安全傳輸屬性是啟用的。

Azure 原則 提供內建政策,確保您的儲存帳號必須安全傳輸。 欲了解更多資訊,請參閱Azure 原則內建政策定義中Storage章節。

關於 Azure 檔案儲存體,請參見 設定 Azure 檔案儲存體 的傳輸中加密。 包含 Azure 檔案分享的儲存帳號使用相同設定,但它會與 SMB 和 NFS 加密設定互動。 Azure 檔案儲存體 文章描述了關於 Azure 檔案儲存體 的考量。

在 Azure 入口網站中要求安全傳輸

你可以在Azure入口網站建立儲存帳戶時,開啟Secure transfer required屬性。 您也可以為現有的儲存體帳戶啟用它。

需要為新的儲存體帳戶啟用安全傳輸

  1. 登入Azure入口網站,前往 Storage accounts。 選取 + Create。

  2. 在進階標籤的安全性下,選擇「要求 REST API 操作的安全傳輸」勾選框。

    建立儲存帳戶進階分頁

針對現有儲存體帳戶,要求進行安全傳輸

  1. 在 Azure 入口網站中選擇一個現有的儲存帳號。
  2. 在服務選單中,在 設定中選擇 設定。
  3. 在 [需要安全傳輸] 下,選取 [已啟用]。
  4. 選取 [儲存]。

要求從程式碼進行安全傳輸

若要以程式設計方式要求安全傳輸,請在儲存體帳戶上將 EnableHttpsTrafficOnly 屬性設定為 True。 您可以使用儲存體資源提供者 REST API、用戶端程式庫或工具來設定此屬性:

在 PowerShell 中設定安全傳輸要求

注意

我們建議你使用 Azure Az PowerShell 模組來與 Azure 互動。 要開始,請參考 安裝 Azure PowerShell。 想了解如何遷移到 Az PowerShell 模組,請參考 Migrate Azure PowerShell from AzureRM to Az。

此範例需要使用 Azure PowerShell 模組 Az 版本 0.7 或更新版本。 執行 Get-Module -ListAvailable Az 以尋找版本。 如果你需要安裝或升級,請參考 安裝Azure PowerShell模組。

執行 Connect-AzAccount 與 Azure 建立連線。

使用下列命令列檢查設定:

Get-AzStorageAccount -Name "{StorageAccountName}" -ResourceGroupName "{ResourceGroupName}"
StorageAccountName     : {StorageAccountName}
Kind                   : Storage
EnableHttpsTrafficOnly : False
...

使用下列命令列啟用設定:

Set-AzStorageAccount -Name "{StorageAccountName}" -ResourceGroupName "{ResourceGroupName}" -EnableHttpsTrafficOnly $True
StorageAccountName     : {StorageAccountName}
Kind                   : Storage
EnableHttpsTrafficOnly : True
...

要求使用 Azure CLI 進行安全傳輸

要執行此範例,請安裝最新版本的 Azure CLI。 開始時,執行 az login 與 Azure 建立連線。

Azure CLI 的取樣是針對 bash shell 撰寫的。 若要在 Windows PowerShell 或命令提示字元中執行此範例,您可能需要更改腳本的元素。

如果你沒有Azure帳號,請在開始前先建立一個free帳號。

使用下列命令來檢查設定:

az storage account show -g {ResourceGroupName} -n {StorageAccountName}
{
  "name": "{StorageAccountName}",
  "enableHttpsTrafficOnly": false,
  "type": "Microsoft.Storage/storageAccounts"
  ...
}

使用下列命令來啟用設定:

az storage account update -g {ResourceGroupName} -n {StorageAccountName} --https-only true
{
  "name": "{StorageAccountName}",
  "enableHttpsTrafficOnly": true,
  "type": "Microsoft.Storage/storageAccounts"
  ...
}

下一步

適用於 Blob 儲存體的安全性建議