查看及套用機構政策建議

本頁面說明如何查看、瞭解及套用組織政策建議。組織政策建議可協助您設定正確的組織政策,而不會中斷系統。

事前準備

  • 啟用 Organization Policy 和 Recommender API (如果尚未啟用)。

    啟用 API 所需的角色

    如要啟用 API,您必須具備 serviceusage.services.enable 權限。如果您建立了專案,可能已透過擁有者角色 (roles/owner) 取得這項權限。否則,您可以透過 Service Usage 管理員角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。

    啟用 API

  • 設定驗證方法。

    請根據您打算如何使用本頁範例,選取對應的分頁標籤:

    gcloud

    在 Google Cloud 控制台啟用 Cloud Shell。

    啟用 Cloud Shell

    Google Cloud 控制台底部會開啟 Cloud Shell 工作階段,並顯示指令列提示。Cloud Shell 是已安裝 Google Cloud CLI 的殼層環境,並已設定適用於您目前專案的值。工作階段可能要幾秒鐘的時間才能初始化。

    REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI。

      若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。

    詳情請參閱 Google Cloud 驗證說明文件中的「使用 REST 進行驗證」一節。

  • 瞭解組織政策建議。

必要的 IAM 角色

本節說明使用組織政策建議所需的 IAM 角色和權限。

如要取得管理組織政策建議所需的權限,請要求管理員在您要管理建議的資源 (專案、資料夾或組織) 中,授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這些預先定義的角色具備管理組織政策建議所需的權限。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

必須具備下列權限,才能管理組織政策建議:

  • 如要查看組織政策建議,請按照下列步驟操作:
    • recommender.orgPolicyRecommendations.get
    • recommender.orgPolicyRecommendations.list
  • 如要套用及關閉組織政策建議,請按照下列步驟操作:
    • recommender.orgPolicyRecommendations.get
    • recommender.orgPolicyRecommendations.list
    • recommender.orgPolicyRecommendations.update
  • 如要管理組織政策:
    • orgpolicy.policy.get
    • orgpolicy.policy.set
    • orgpolicy.constraints.list
    • orgpolicy.policies.create
    • orgpolicy.policies.delete
    • orgpolicy.policies.list
    • orgpolicy.policies.update

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

限制

組織政策推薦工具預先發布版有下列限制:

  • 只有具備建議的專案、資料夾和組織,才能使用洞察。

  • 系統只會針對未在指定資源或其任何子項資源上設定的限制提供建議。

支援的限制

建議僅適用於下列組織政策限制:

查看及套用建議

您可以使用 Google Cloud CLI 和 Recommender API,查看及套用組織政策建議。

gcloud

查看最佳化建議:

如要列出建議,請執行 gcloud recommender recommendations list 指令:

gcloud recommender recommendations list \
    --location=global \
    --recommender=google.orgpolicy.policy.Recommender \
    --RESOURCE_TYPE=RESOURCE_ID \
    --filter="recommenderSubtype:RECOMMENDER_SUBTYPE" \
    --format=FORMAT

替換下列值:

  • RESOURCE_TYPE: 要列出建議的資源類型。請使用 project、folder 或 organization 值。

  • RESOURCE_ID:要列出建議的 Google Cloud 專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 為數字,例如 123456789012。

  • RECOMMENDER_SUBTYPE:選用。要查看最佳化建議的子類型 ID。有效的子類型包括:

    • ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION 會提供 iam.managed.disableServiceAccountKeyCreation 限制的建議。
    • ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_UPLOAD 會提供 iam.managed.disableServiceAccountKeyUpload 限制的建議
  • FORMAT:回覆格式。請使用 json 或 yaml 值。

回應內容大致如下。在本範例中,系統分析了兩項資源的外部服務帳戶金鑰,未偵測到任何違規事項。因此,建議您設定 iam.managed.disableServiceAccountKeyCreation,以免日後發生違規情形。

[
  {
    "associatedInsights": [
      {
        "insight": "projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/fb927dc1-9695-4436-0000-f0f285007c0f"
      }
    ],
    "content": {
      "operationGroups": [
        {
          "operations": [
            {
              "action": "add",
              "path": "/",
              "resource": "//orgpolicy.googleapis.com/projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation",
              "resourceType": "orgpolicy.googleapis.com/Policy",
              "value": {
                "etag": "",
                "name": "projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation",
                "spec": {
                  "etag": "",
                  "inheritFromParent": false,
                  "reset": false,
                  "rules": [
                    {
                      "enforce": true
                    }
                  ]
                }
              }
            }
          ]
        }
      ],
      "overview": {
        "constraint": {
          "id": "constraints/iam.managed.disableServiceAccountKeyCreation",
          "name": "Disable service account key creation"
        },
        "enforcedResources": [
          {
            "numOfResources": "2",
            "resourceType": "iam.googleapis.com/ServiceAccountKey"
          },
          {
            "numOfResources": "1",
            "resourceType": "cloudresourcemanager.googleapis.com/Project"
          }
        ]
      }
    },
    "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
    "etag": "\"826e992a0f9793ff\"",
    "lastRefreshTime": "2024-12-07T08:00:00Z",
    "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
    "primaryImpact": {
      "category": "SECURITY"
    },
    "priority": "P1",
    "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
    "stateInfo": {
      "state": "ACTIVE",
      "stateMetadata": {
        "reviewedBy": "alice",
        "priority": "high"
      }
    },
    "targetResources": [
      "//cloudresourcemanager.googleapis.com/projects/123456789012"
    ]
  }
]

如要進一步瞭解建議的組成部分,請參閱「瞭解建議」。

如要套用最佳化建議,請按照下列步驟操作:

  1. 使用 gcloud recommender recommendations mark-claimed 指令將建議狀態變更為 CLAIMED,防止建議在套用時變更:

    gcloud recommender recommendations mark-claimed \
        RECOMMENDATION_ID \
        --location=global \
        --recommender=google.orgpolicy.policy.Recommender \
        --RESOURCE_TYPE=RESOURCE_ID \
        --format=FORMAT \
        --etag=ETAG \
        --state-metadata=STATE_METADATA
    

    替換下列值:

    • RECOMMENDATION_ID:建議的專屬 ID。這個值會顯示在建議中 name 欄位的結尾。在上述範例中,ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。
    • RESOURCE_TYPE:要管理建議的資源類型。請使用 project、folder 或 organization 值。
    • RESOURCE_ID:要列出建議的 Google Cloud專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 則為數字,例如 123456789012。
    • FORMAT:回覆格式。請使用 json 或 yaml 值。
    • ETAG:建議版本的 ID,例如 "7caf4103d7669e12"。請注意,這個值可以包含引號。
    • STATE_METADATA:選用。以半形逗號分隔的鍵/值組合,包含您選擇的建議中繼資料。例如:--state-metadata=reviewedBy=alice,priority=high。中繼資料會取代建議中的 stateInfo.stateMetadata 欄位。

    如果指令執行成功,回應會顯示處於 CLAIMED 狀態的建議,如下例所示。為求明確,範例省略了大部分欄位:

    
      {
        "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
        "etag": "\"826e992a0f9793ff\"",
        "lastRefreshTime": "2024-12-07T08:00:00Z",
        "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
        "primaryImpact": {
          "category": "SECURITY"
        },
        "priority": "P1",
        "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
        "stateInfo": {
          "state": "CLAIMED",
          "stateMetadata": {\
            "reviewedBy": "alice",
            "priority": "high"
          }
        },
        "targetResources": [
          "//cloudresourcemanager.googleapis.com/projects/123456789012"
        ]
      }
    
  2. 更新並套用 RESOURCE_TYPE 和 RESOURCE_ID 指定的專案、資料夾或組織的組織政策,以反映建議。

  3. 如果您可以套用建議,請將建議狀態更新為 SUCCEEDED;如果無法套用建議,請將建議狀態更新為 FAILED:

    gcloud recommender recommendations COMMAND \
        RECOMMENDATION_ID \
        --location=global \
        --recommender=google.iam.policy.Recommender \
        --RESOURCE_TYPE=RESOURCE_ID \
        --format=FORMAT \
        --etag=ETAG \
        --state-metadata=STATE_METADATA
    

    替換下列值:

    • COMMAND:如果成功套用最佳化建議,請使用 mark-succeeded;如果無法套用最佳化建議,請使用 mark-failed。
    • RECOMMENDATION_ID:建議的專屬 ID。這個值會顯示在建議中 name 欄位的結尾。在上述範例中,ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。
    • RESOURCE_TYPE:要管理建議的資源類型。請使用 project、folder 或 organization 值。
    • RESOURCE_ID:要列出建議的 Google Cloud專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 則為數字,例如 123456789012。
    • FORMAT:回覆格式。請使用 json 或 yaml 值。
    • ETAG:建議版本的 ID,例如 "7caf4103d7669e12"。請注意,這個值可以包含引號。
    • STATE_METADATA:選用。以半形逗號分隔的鍵/值組合,包含您選擇的建議中繼資料。例如:--state-metadata=reviewedBy=alice,priority=high。中繼資料會取代建議中的 stateInfo.stateMetadata 欄位。

    舉例來說,如果您將建議標示為成功,回應會顯示處於 SUCCEEDED 狀態的建議。為求明確,這個範例省略了大部分欄位:

    
      {
        "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
        "etag": "\"826e992a0f9793ff\"",
        "lastRefreshTime": "2024-12-07T08:00:00Z",
        "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
        "primaryImpact": {
          "category": "SECURITY"
        },
        "priority": "P1",
        "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
        "stateInfo": {
          "state": "SUCCEEDED",
          "stateMetadata": {
            "reviewedBy": "alice",
            "priority": "high"
          }
        },
        "targetResources": [
          "//cloudresourcemanager.googleapis.com/projects/123456789012"
        ]
      }
    

    如要還原組織政策變更,請將組織政策設為原始設定,相關洞察的 configuredPolicy 欄位會提供這項設定。

REST

查看最佳化建議:

如要列出專案、資料夾或組織的所有可用建議,請使用 Recommender API 的 recommendations.list 方法。

使用任何要求資料之前,請先修改下列項目的值:

  • RESOURCE_TYPE:要管理建議的資源類型。請使用 projects、folders 或 organizations 值。
  • RESOURCE_ID:要管理建議的Google Cloud 專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 為數字,例如 123456789012。
  • PAGE_SIZE:選用。這項要求傳回的結果數量上限。如未指定,伺服器會決定要傳回的結果數量。如果建議數量大於頁面大小,回應會包含分頁權杖,可用於擷取下一頁結果。
  • PAGE_TOKEN:選用。這個方法先前傳回的回應中,所含的分頁權杖。如果指定這個參數,建議清單會從上一個要求結束的位置開始。
  • FILTER:選用。篩選運算式,用於限制傳回的建議。您可以根據 stateInfo.state 欄位篩選建議。例如 stateInfo.state:"DISMISSED" 或 stateInfo.state:"FAILED"。
  • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 是英數字串,例如 my-project。

HTTP 方法和網址:

GET https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations?pageSize=PAGE_SIZE&pageToken=PAGE_TOKEN&filter=FILTER

請展開以下其中一個選項,以傳送要求:

回應內容大致如下。在本範例中,系統分析了兩項資源的外部服務帳戶金鑰,未偵測到任何違規事項。因此,建議您設定 iam.managed.disableServiceAccountKeyCreation,以免日後發生違規情形。

[
  {
    "associatedInsights": [
      {
        "insight": "projects/123456789012/locations/global/insightTypes/google.orgpolicy.policy.Insight/insights/66d543f3-845d-49d6-a26b-80d84804d8a8"
      }
    ],
    "content": {
      "operationGroups": [
        {
          "operations": [
            {
              "action": "add",
              "path": "/",
              "resource": "//orgpolicy.googleapis.com/projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation",
              "resourceType": "orgpolicy.googleapis.com/Policy",
              "value": {
                "etag": "",
                "name": "projects/123456789012/policies/iam.managed.disableServiceAccountKeyCreation",
                "spec": {
                  "etag": "",
                  "inheritFromParent": false,
                  "reset": false,
                  "rules": [
                    {
                      "enforce": true
                    }
                  ]
                }
              }
            }
          ]
        }
      ],
      "overview": {
        "constraint": {
          "id": "constraints/iam.managed.disableServiceAccountKeyCreation",
          "name": "Disable service account key creation"
        },
        "enforcedResources": [
          {
            "numOfResources": "2",
            "resourceType": "iam.googleapis.com/ServiceAccountKey"
          },
          {
            "numOfResources": "1",
            "resourceType": "cloudresourcemanager.googleapis.com/Project"
          }
        ]
      }
    },
    "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
    "etag": "\"826e992a0f9793ff\"",
    "lastRefreshTime": "2024-12-07T08:00:00Z",
    "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
    "primaryImpact": {
      "category": "SECURITY"
    },
    "priority": "P1",
    "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
    "stateInfo": {
      "state": "ACTIVE",
      "stateMetadata": {
        "reviewedBy": "alice",
        "priority": "high"
      }
    },
    "targetResources": [
      "//cloudresourcemanager.googleapis.com/projects/123456789012"
    ]
  }
]

如要進一步瞭解建議的組成部分,請參閱「瞭解建議」。

如要套用最佳化建議,請按照下列步驟操作:

  1. 將建議標示為CLAIMED:

    如要將建議標示為 CLAIMED,防止建議在套用時變更,請使用 Recommender API 的 recommendations.markClaimed 方法。

    使用任何要求資料之前,請先修改下列項目的值:

    • RESOURCE_TYPE:要管理建議的資源類型。請使用 projects、folders 或 organizations 值。
    • RESOURCE_ID:要管理建議的Google Cloud 專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 為數字,例如 123456789012。
    • RECOMMENDATION_ID:建議的專屬 ID。這個值會顯示在建議中 name 欄位的結尾。舉例來說,如果 name 欄位為 projects/example-project/locations/global/recommenders/google.iam.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f,則建議 ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。
    • ETAG:建議中 etag 欄位的值,例如 "dd0686e7136a4cbb"。請使用反斜線逸出引號,例如 "\"df7308cca9719dcc\""。
    • STATE_METADATA:選用。這個物件包含鍵/值組合,以及您選擇的建議相關中繼資料。例如:{"reviewedBy": "alice", "priority": "high"}。中繼資料會取代建議中的 stateInfo.stateMetadata 欄位。
    • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 是英數字串,例如 my-project。

    HTTP 方法和網址:

    POST https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/RECOMMENDATION_ID:markClaimed

    JSON 要求主體:

    {
      "etag": "ETAG",
      "stateMetadata": {
        "STATE_METADATA"
      }
    }
    

    請展開以下其中一個選項,以傳送要求:

    回應會顯示處於 CLAIMED 狀態的建議,如以下範例所示。為求明確,這個範例省略了大部分欄位:

    {
      "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
      "etag": "\"826e992a0f9793ff\"",
      "lastRefreshTime": "2024-12-07T08:00:00Z",
      "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
      "primaryImpact": {
        "category": "SECURITY"
      },
      "priority": "P1",
      "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
      "stateInfo": {
        "state": "CLAIMED",
        "stateMetadata": {
          "reviewedBy": "alice",
          "priority": "high"
        }
      },
      "targetResources": [
        "//cloudresourcemanager.googleapis.com/projects/123456789012"
      ]
    }
    

  2. 更新組織政策:針對 RESOURCE_TYPE 和 RESOURCE_ID 指定的專案、資料夾或組織,更新組織政策,反映建議內容。

  3. 如果成功套用建議,請將建議狀態更新為 SUCCEEDED;如果無法套用建議,請將建議狀態更新為 FAILED:

    SUCCEEDED

    如要將建議標示為 SUCCEEDED,表示您已套用建議,請使用 Recommender API 的 recommendations.markSucceeded 方法。

    使用任何要求資料之前,請先修改下列項目的值:

    • RESOURCE_TYPE:要管理建議的資源類型。請使用 projects、folders 或 organizations 值。
    • RESOURCE_ID:要管理建議的Google Cloud 專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 為數字,例如 123456789012。
    • RECOMMENDATION_ID:建議的專屬 ID。這個值會顯示在建議中 name 欄位的結尾。舉例來說,如果 name 欄位為 projects/example-project/locations/global/recommenders/google.iam.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f,則建議 ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。
    • ETAG:建議中 etag 欄位的值,例如 "dd0686e7136a4cbb"。請使用反斜線逸出引號,例如 "\"df7308cca9719dcc\""。
    • STATE_METADATA:選用。這個物件包含鍵/值組合,以及您選擇的建議相關中繼資料。例如:{"reviewedBy": "alice", "priority": "high"}。中繼資料會取代建議中的 stateInfo.stateMetadata 欄位。
    • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 是英數字串,例如 my-project。

    HTTP 方法和網址:

    POST https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/RECOMMENDATION_ID:markSucceeded

    JSON 要求主體:

    {
      "etag": "ETAG",
      "stateMetadata": {
        "STATE_METADATA"
      }
    }
    

    請展開以下其中一個選項,以傳送要求:

    回應會顯示處於 SUCCEEDED 狀態的建議,如以下範例所示。為求明確,這個範例省略了大部分欄位:

    {
      "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
      "etag": "\"826e992a0f9793ff\"",
      "lastRefreshTime": "2024-12-07T08:00:00Z",
      "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
      "primaryImpact": {
        "category": "SECURITY"
      },
      "priority": "P1",
      "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
      "stateInfo": {
        "state": "SUCCEEDED",
        "stateMetadata": {
          "reviewedBy": "alice",
          "priority": "high"
        }
      },
      "targetResources": [
        "//cloudresourcemanager.googleapis.com/projects/123456789012"
      ]
    }
    

    FAILED

    如要將建議標示為 FAILED,表示您無法套用該建議,請使用 Recommender API 的 recommendations.markFailed 方法。

    使用任何要求資料之前,請先修改下列項目的值:

    • RESOURCE_TYPE:要管理建議的資源類型。請使用 projects、folders 或 organizations 值。
    • RESOURCE_ID:要管理建議的Google Cloud 專案、資料夾或組織 ID。專案 ID 是英數字串,例如 my-project。資料夾和組織 ID 為數字,例如 123456789012。
    • RECOMMENDATION_ID:建議的專屬 ID。這個值會顯示在建議中 name 欄位的結尾。舉例來說,如果 name 欄位為 projects/example-project/locations/global/recommenders/google.iam.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f,則建議 ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。
    • ETAG:建議中 etag 欄位的值,例如 "dd0686e7136a4cbb"。請使用反斜線逸出引號,例如 "\"df7308cca9719dcc\""。
    • STATE_METADATA:選用。這個物件包含鍵/值組合,以及您選擇的建議相關中繼資料。例如:{"reviewedBy": "alice", "priority": "high"}。中繼資料會取代建議中的 stateInfo.stateMetadata 欄位。
    • PROJECT_ID:您的 Google Cloud 專案 ID。專案 ID 是英數字串,例如 my-project。

    HTTP 方法和網址:

    POST https://recommender.googleapis.com/v1/RESOURCE_TYPE/RESOURCE_ID/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/RECOMMENDATION_ID:markFailed

    JSON 要求主體:

    {
      "etag": "ETAG",
      "stateMetadata": {
        "STATE_METADATA"
      }
    }
    

    請展開以下其中一個選項,以傳送要求:

    回應會顯示處於 FAILED 狀態的建議,如以下範例所示。為求明確,這個範例省略了大部分欄位:

    {
      "description": "After analyzing 3 resources and finding 0 violations, Organization Policy Recommender recommends that you disable the creation of service account external keys on your project by enforcing constraints/iam.managed.disableServiceAccountKeyCreation.",
      "etag": "\"826e992a0f9793ff\"",
      "lastRefreshTime": "2024-12-07T08:00:00Z",
      "name": "projects/123456789012/locations/global/recommenders/google.orgpolicy.policy.Recommender/recommendations/fb927dc1-9695-4436-0000-f0f285007c0f",
      "primaryImpact": {
        "category": "SECURITY"
      },
      "priority": "P1",
      "recommenderSubtype": "ADD_POLICY_DISABLE_SERVICE_ACCOUNT_KEY_CREATION",
      "stateInfo": {
        "state": "FAILED",
        "stateMetadata": {
          "reviewedBy": "alice",
          "priority": "high"
        }
      },
      "targetResources": [
        "//cloudresourcemanager.googleapis.com/projects/123456789012"
      ]
    }
    

瞭解最佳化建議

每項建議都包含相關資訊,協助您瞭解建議原因,以及組織政策設定的變更建議。核心屬性包括:

  • description::建議的人類可讀摘要。

  • recommenderSubtype:建議子類型的 ID。每個限制都有專屬的 recommenderSubtype。

  • content:包含組織政策的建議變更。

    • overview:建議的簡要總覽資訊。

    • constraint:提供限制的相關資訊。

    • enforced_resources:提供套用建議後,這項組織政策會影響哪些資源的相關資訊。

    • operationGroups: 套用建議時,對組織政策執行的一或多項作業。

  • associatedInsights:產生這項建議的洞察資源名稱。

如要進一步瞭解建議的屬性,請參閱建議參考資料。

如果資源或其任何子資源未設定支援的組織政策,系統就會產生洞察和建議。如要查看這項建議依據的組織政策設定,請查看與建議相關聯的組織政策洞察。這些洞察資料會列在 associatedInsights 欄位中。如要查看與建議相關聯的組織政策洞察,請按照下列步驟操作:

  1. 找出 associatedInsights 欄位中哪些洞察資料是組織政策洞察資料。組織政策洞察的洞察類型為 google.orgpolicy.policy.Insight。這個類型會顯示在 insight 欄位的 insightTypes 之後。

  2. 複製組織政策洞察的 ID。ID 是 insight 欄位中 insights/ 之後的所有內容。舉例來說,如果洞察欄位顯示 projects/123456789012/locations/us/insightTypes/google.orgpolicy.policy.Insight/insights/fb927dc1-9695-4436-0000-f0f285007c0f,則洞察 ID 為 fb927dc1-9695-4436-0000-f0f285007c0f。

  3. 按照操作說明,使用複製的洞察 ID 取得組織政策洞察。

將建議匯出至 BigQuery

如要查看組織所有建議 (包括組織政策建議) 的每日快照,可以將建議匯出至 BigQuery。

如要將建議匯出至 BigQuery,您必須使用 BigQuery 資料移轉服務設定資料移轉作業。如要瞭解如何設定資料移轉作業,請參閱「將建議匯出至 BigQuery」。

後續步驟