workload-manager-basics

workload-manager-basics

熱門

使用此 Skill 透過公開 Client Library 及 REST API 管理 Google Cloud Workload Manager 的評估、規則、已掃描資源與驗證結果。適用於需要檢視工作負載最佳做法規則、針對 Google Cloud 一般最佳做法、SAP、SQL Server 或自訂組織規則建立並執行評估、審查違規項目、將結果匯出至 BigQuery,或因缺乏特定服務的公開 CLI 或 MCP 伺服器而需透過 Client Library 自動化 Workload Manager 的情境。請勿用於一般的 Google Compute Engine 執行個體管理、VPC 設定或標準 IAM 稽核。

1.5萬星標
1209分支
更新於 2026/8/1
SKILL.md
唯讀
名稱
workload-manager-basics
描述

使用此 Skill 透過公開 Client Library 及 REST API 管理 Google Cloud Workload Manager 的評估、規則、已掃描資源與驗證結果。適用於需要檢視工作負載最佳做法規則、針對 Google Cloud 一般最佳做法、SAP、SQL Server 或自訂組織規則建立並執行評估、審查違規項目、將結果匯出至 BigQuery,或因缺乏特定服務的公開 CLI 或 MCP 伺服器而需透過 Client Library 自動化 Workload Manager 的情境。請勿用於一般的 Google Compute Engine 執行個體管理、VPC 設定或標準 IAM 稽核。

Workload Manager 基礎概念

Workload Manager 會對照 Google Cloud 的最佳做法與建議來驗證企業工作負載。公開 Client Library 的核心運作圍繞著「評估」(evaluations):先定義資源範圍、選擇內建或自訂規則、執行評估,最後檢查結果與已掃描的資源。

建議流程

flowchart LR
    Rules["列出規則"] --> Eval["建立或更新評估"]
    Resources["專案、資料夾或組織範圍"] --> Eval
    Eval --> Run["執行評估"]
    Run --> Results["檢視評估結果"]
    Results --> Remediate["修復發現項目"]
    Results --> Export["可選的 BigQuery 匯出"]

核心 API 限制

為確保相容性、安全性與成功整合,請務必遵循以下規範:

  • 僅限使用公開介面: 你「必須」嚴格使用官方公開的 google-cloud-workloadmanager Client Library 或公開 REST API (workloadmanager.googleapis.com/v1) 來與 Workload Manager 互動。
  • 禁止使用內部或未公開 API: 「切勿」嘗試使用內部 RPC 協定、私有服務後端或未公開的探索機制(discovery mechanisms)。公開整合不支援這些方式且必然會失敗。
  • 無特定服務 CLI: 目前並沒有公開的 gcloud workload-manager CLI 命令群組。gcloud 僅能用於身分驗證、IAM 角色指派以及獲取原始 REST token。
  • 沙盒執行強健性(驗證/Mock 備援機制): 當在沙盒或受限環境中 gcloud 驗證或 Workload Manager API 呼叫失敗時(例如因情境感知存取權 token 阻擋、未啟用 API,或 Mock 資源回傳 404/403),應立即退回並改為展示參考資料中的程式碼範例與靜態發現項目,而非陷入重試迴圈。請提供正確的 Client Library 程式碼結構或 REST API Payload 範例,清晰說明驗證或資源限制,並以靜態方式列出常見規則或 Mock 發現項目以滿足請求。

前置需求

  1. 啟用 Workload Manager API:

    gcloud services enable workloadmanager.googleapis.com --quiet
    
  2. 使用 Client Library 前,先在本地透過應用程式預設憑證(ADC)完成身分驗證:

    gcloud auth application-default login
    
  3. 確保已在專案中授予 Workload Manager Service Agent 所需的角色(此為使用 API/Client Library 的必要條件,詳見 IAM & Security)。

  4. 依工作需求授予最小權限角色。對於評估資源的唯讀存取,請先使用 roles/workloadmanager.viewer;僅在需要建立、更新、執行或刪除評估時,才使用 roles/workloadmanager.evaluationAdminroles/workloadmanager.admin

Client Library 快速範例

使用 Python Client Library 作為首選的自動化實作路徑:

python3 -m pip install --upgrade google-cloud-workloadmanager
from google.cloud import workloadmanager_v1

project_id = "PROJECT_ID"
location = "LOCATION"
parent = f"projects/{project_id}/locations/{location}"

client = workloadmanager_v1.WorkloadManagerClient()

rules = client.list_rules(
    request=workloadmanager_v1.ListRulesRequest(
        parent=parent,
        evaluation_type=workloadmanager_v1.Evaluation.EvaluationType.OTHER,
    )
)

for rule in rules.rules:
    print(rule.name, rule.display_name, rule.severity)

參考指南目錄

  • Core Concepts:評估、規則、結果、已掃描資源、支援的工作負載類型與 API 結構。

  • General Best Practices:Google Cloud 一般最佳做法姿態檢查(posture checks)、OTHER 評估指引、自訂 Rego 規則,以及大規模自動化模式。

  • Client Libraries:包含列出規則、建立評估、執行評估與讀取發現項目的 Python 和 Go Client Library 範例。

  • REST Usage:公開 Workload Manager API 的直接 REST 使用範例與 Operation 輪詢(polling)。

  • Public CLI Status:目前無官方記載的特定服務 gcloud workload-manager 命令群組;gcloud 僅用於驗證、IAM、啟用 API 及取得 REST token。

  • Public MCP Status:目前無官方記載的公開 Workload Manager MCP 伺服器;請改用 Client Library 或 REST API。

  • Setup Prerequisites:僅提供相關前置作業(如 API 啟用、IAM、BigQuery 匯出資料集及 KMS 金鑰)的 Terraform 範例。這並非 Workload Manager 資源管理本身。

  • IAM & Security:Workload Manager 角色、最小權限指引、Service Agent、資料處理及 CMEK 說明。

若產品行為或 API 欄位未在此列出,請在實作前查閱最新的 Workload Manager 產品說明文件與 Client Library 參考文件。

權威參考資料

補充資訊