確保安全性的最佳做法
本文件提供有關如何安全使用 Terraform for Trusted Cloud的指南和建議。Terraform 需要敏感的雲端基礎架構存取權才能運作。遵循安全性最佳做法,有助於降低相關風險並改善整體雲端安全性。
本指南並非 Terraform 的介紹。如要瞭解如何搭配使用 Terraform 和 Trusted Cloud by S3NS,請參閱「開始使用 Terraform」。
使用遠端狀態
Trusted Cloud 客戶建議使用 Cloud Storage 狀態後端。這種做法會鎖定狀態,讓團隊成員能進行協作。它也會將狀態和所有可能的機密資訊與版本控制分開。
請確認只有建構系統和擁有高度權限的管理員可以存取用於遠端狀態的資料夾。
為避免不小心將開發狀態提交至原始碼控制,請為 Terraform 狀態檔案使用 gitignore。
加密狀態
雖然 Trusted Cloud 儲存格會在靜止時加密,但您可以使用客戶提供的加密金鑰,為資料多添一層保護。方法是使用 GOOGLE_ENCRYPTION_KEY
環境變數。雖然狀態檔案不應包含任何機密資料,但請一律加密狀態,做為額外的防護措施。
請勿在狀態中儲存密鑰
Terraform 中有許多資源和資料供應器,會在狀態檔案中以純文字形式儲存機密值。盡可能避免在狀態中儲存機密。以下是一些以明文儲存機密資料的供應商範例:
標示敏感輸出內容
請不要嘗試手動加密機密值,而是依賴 Terraform 內建的機密狀態管理功能。將機密值匯出至輸出內容時,請務必將值標示為「機密」。
確保權責劃分
如果您無法從沒有使用者存取權的自動化系統執行 Terraform,請透過分隔權限和目錄來實施職責分離。舉例來說,網路專案會對應至網路 Terraform 服務帳戶或使用者,而這類使用者的存取權僅限於這個專案。
執行持續稽核
執行 terraform apply
指令後,請執行自動安全性檢查。這些檢查可確保基礎架構不會進入不安全的狀態。以下工具適用於這類檢查:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["Utilize the Cloud Storage state backend for Terraform state management to enable team collaboration and separate sensitive information from version control."],["Encrypt the Terraform state using customer-supplied encryption keys via the `GOOGLE_ENCRYPTION_KEY` environment variable, even though no secrets should be in the state file."],["Avoid storing secrets directly within the Terraform state file, as certain providers like `vault_generic_secret` and `google_service_account_key` may store them in plaintext."],["Mark sensitive outputs as such within Terraform configurations to prevent the exposure of sensitive data in command-line output and implement separation of duties by restricting access to Terraform resources."],["Implement pre-apply checks with tools like `gcloud terraform vet` and continuous audits using Security Health Analytics, InSpec, or Serverspec to detect security regressions and ensure infrastructure security."]]],[]]