分析機構政策

本頁面說明如何分析組織政策設定,瞭解哪些資源受哪些組織政策涵蓋。使用組織政策的政策分析工具,您可以建立分析查詢,取得自訂和預先定義組織政策的相關資訊。

分析查詢是由範圍和限制組成。

  • 限制:指定限制的資源名稱。
  • 範圍:指定要分析的組織。分析範圍涵蓋此範圍內定義的所有組織政策,且這些政策均設有指定限制。

  • 如要進一步瞭解組織政策,請參閱「組織政策服務簡介」。

  • 如要進一步瞭解如何建立自訂限制,請參閱「建立及管理自訂限制」。

  • 如要進一步瞭解代管限制,請參閱「使用限制」。

事前準備

  • 啟用 Cloud Asset API (如果尚未啟用)。

    啟用 API 所需的角色

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

    啟用 API

    您必須在要用來傳送查詢的專案中啟用 API。這不一定要與您查詢範圍內的資源相同。

  • 選用:如要每天為每個組織執行超過 20 項政策分析查詢,請確認您已在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 方案。詳情請參閱「帳單問題」。

必要角色和權限

如要取得執行組織政策分析所需的權限,請要求管理員在您要執行分析的組織資源中,授予下列 IAM 角色:

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

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

所需權限

必須具備下列權限,才能執行組織政策分析:

  • 如要進行分析,請按照下列步驟操作:
    • cloudasset.assets.analyzeOrgPolicy
    • cloudasset.assets.searchAllResources
    • cloudasset.assets.searchAllIamPolicies
  • 如要查看自訂和代管限制,請按照下列步驟操作: orgpolicy.customConstraints.get

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

定價與配額

如要大規模使用組織政策的政策分析工具 (每個組織每天超過 20 次查詢),以及繼承視覺化圖表,客戶必須在組織層級啟用 Security Command Center。

組織政策的政策分析工具配額,由所有政策分析工具共用。詳情請參閱「帳單問題」。

分析已設定的政策

組織政策是由限制和強制執行該限制的選用條件所組成。您可以使用政策分析工具,傳回具有特定限制的組織政策清單,以及附加這些政策的資源。

針對在查詢範圍內偵測到的每項組織政策,政策分析工具都會傳回一筆結果項目。結果項目包含下列欄位:

  • consolidatedPolicy:附加組織政策的資源,以及該資源根據階層評估規則強制執行的有效政策。

  • project:這項整併政策所屬專案資源的 ID。

  • folders:任何資料夾資源的 ID,這些資源是附加組織政策的資源的上層資源。

  • organization:組織資源的 ID,該資源是附加組織政策的資源的上層資源。

  • policyBundle:附加至上述資源的完整設定組織政策,以及在資源階層中,為其祖系定義的組織政策。

如果資源受到 VPC Service Controls service perimeter 保護,您必須在組織資源的 perimeter 中建立輸出規則,允許存取 cloudasset.googleapis.com 服務。Cloud Asset API 不支援方法層級限制,因此您必須在輸出規則中指定 method: *,允許所有 Cloud Asset API 方法。如果沒有輸出規則,要求就會失敗,並顯示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER 錯誤。詳情請參閱「對 VPC Service Controls 封鎖的要求進行偵錯」。

控制台

  1. 前往 Google Cloud 控制台的「政策分析工具」頁面。

    前往政策分析工具

  2. 在「Analyze organization policy」(分析組織政策) 部分,找到標示為「Where are specific organization policies configured?」(哪裡已設定特定組織政策?) 的窗格,然後點選該窗格中的「Create query」(建立查詢)。

  3. 在「Select query organization」(選取查詢組織) 方塊中,選取要分析組織政策的組織。

  4. 選取要分析的限制類型。如為預先定義或代管限制,請選取「Built-in constraint」(內建限制)。如要設定自訂限制,請選取「Custom constraint」(自訂限制)。

  5. 輸入要分析的限制名稱。系統已加入您要分析的限制類型前置字元。舉例來說,如果是預先定義的網域限制,請輸入 iam.allowedPolicyMemberDomains;如果是服務帳戶建立代管限制,請輸入 iam.managed.disableServiceAccountKeyCreation;如果是自訂限制,請輸入其名稱,例如 disableGkeAutoUpgrade。

  6. 依序點選「分析」和「執行查詢」。報表頁面會顯示您輸入的查詢參數,以及直接套用這項限制的所有資源結果表格。

  7. 如要儲存這項查詢,以便日後再次查看,請按一下「Copy query URL」(複製查詢網址)。如要查看這項查詢,請前往產生的網址。

  8. 您可以從清單中選取至少一項資源,然後按一下「View inheritance」(查看繼承關係),以圖表呈現分析限制的繼承關係。您也可以在建立分析查詢時,依序點選「Analyze」(分析) 和「Visualize」(視覺化),立即前往視覺化檢視畫面。詳情請參閱「視覺化繼承」。

gcloud

如要分析組織政策限制在組織內的強制執行方式,請使用 gcloud asset analyze-org-policies 指令:

gcloud asset analyze-org-policies \
    --constraint=CONSTRAINT_NAME  \
    --scope=organizations/ORGANIZATION_ID \
    --limit=LIMIT_POLICIES \
    --filter=FILTER_QUERY

更改下列內容:

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • LIMIT_POLICIES:要查看的結果項目數量。如要查看不限數量的項目,請輸入 unlimited。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的政策。唯一可用於篩選的欄位是 consolidated_policy.attached_resource。例如,consolidated_policy.attached_resource="//cloudresourcemanager.googleapis.com/projects/1234567890" 只會傳回附加至專案 ID 為 1234567890 的專案的政策。

YAML 回應應類似下列內容:

YAML 回應範例

---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  rules:
  - enforce: true
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  reset: true
- appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true
---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true

REST

如要分析組織政策限制在組織內的強制執行方式,請使用 Cloud Asset API 的 analyzeOrgPolicies 方法。

HTTP 方法和網址:

GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicies

JSON 要求主體:

JSON_REQUEST="{
  'constraint': 'CONSTRAINT_NAME',
  'filter': 'FILTER_QUERY',
  'page_size': PAGE_SIZE,
  'page_token': PAGE_TOKEN
}"

更改下列內容:

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的政策。唯一可用於篩選的欄位是 consolidated_policy.attached_resource。例如,consolidated_policy.attached_resource="//cloudresourcemanager.googleapis.com/projects/1234567890" 只會傳回附加至專案 ID 為 1234567890 的專案的政策。

  • PAGE_SIZE:每頁要查看的結果項目數量。如要查看不限數量的項目,請輸入 unlimited。如果結果項目總數大於 PAGE_SIZE,使用這個旗標設定的要求會傳回 nextPageToken 值。

  • PAGE_TOKEN:只能在包含 page_size 旗標的第一個要求之後,在要求上設定。您可以使用從先前回應收到的 nextPageToken 值,傳回特定結果頁面。

JSON 回應大致如下:

JSON 回應範例

{
  "orgPolicyResults": [
    {
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012",
        "rules": [
          {
            "values": {
              "allowedValues": [
                "C0265whk2"
              ]
            }
          },
          {
            "values": {
              "allowedValues": [
                "C03kd36xr"
              ]
            }
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012",
          "rules": [
            {
              "values": {
                "allowedValues": [
                  "C03kd36xr"
                ]
              }
            }
          ],
          "inheritFromParent": true,
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/123456789012"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123",
          "rules": [
            {
              "values": {
                "allowedValues": [
                  "C0265whk2"
                ]
              }
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123"
        }
      ]
    },
    {
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123",
        "rules": [
          {
            "values": {
              "allowedValues": [
                "C0265whk2"
              ]
            }
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123",
          "rules": [
            {
              "values": {
                "allowedValues": [
                  "C0265whk2"
                ]
              }
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/234567890123"
        }
      ]
    }
  ]
  "constraint": {
    "googleDefinedConstraint": {
      "name": "constraints/iam.allowedPolicyMemberDomains",
      "displayName": "Domain restricted sharing",
      "description": "This list constraint defines one or more Cloud Identity or Google Workspace customer IDs whose principals can be added to IAM policies. \u003cbr\u003eBy default, all user identities are allowed to be added to IAM policies. Only allowed values can be defined in this constraint, denied values are not supported. \u003cbr\u003eIf this constraint is active, only principals that belong to the allowed customer IDs can be added to IAM policies.",
      "constraintDefault": "ALLOW",
      "listConstraint": {}
    }
  }
}

分析容器

這裡的容器是指專案、資料夾或組織資源。您可以使用政策分析工具,傳回所有已強制執行特定組織政策限制的容器清單。政策分析工具也會傳回每個容器的全名、容器在階層中的父項,以及容器繼承或附加的標記。

對於在查詢範圍內偵測到的每個容器,政策分析工具都會傳回一筆結果項目。結果項目包含下列欄位:

  • consolidatedPolicy:附加組織政策的容器,以及該容器根據階層評估規則強制執行的有效政策。

  • conditionEvaluation:如果納入的條件導致強制執行組織政策,evaluationValue 為 TRUE。如果條件導致組織政策未強制執行,evaluationValue 會FALSE。如果強制執行組織政策的一或多項資源不支援該條件,系統會傳回條件本身。

  • effectiveTags:直接附加至容器或由容器繼承的所有標記,以及階層中容器的父項。

  • folders:任何資料夾資源的 ID,其中包含附加組織政策的容器。

  • fullResourceName:容器的全名。

  • organization:組織資源的 ID,該資源是附加組織政策的容器的上層資源。

  • parent:這個容器父項的完整資源名稱。

  • policyBundle:直接在容器上設定的組織政策 (如有),以及在資源階層中容器上層定義的組織政策。

  • project:如果組織政策是專案資源,則為附加組織政策的容器 ID。

如果資源受到 VPC Service Controls service perimeter 保護,您必須在組織資源的 perimeter 中建立輸出規則,允許存取 cloudasset.googleapis.com 服務。Cloud Asset API 不支援方法層級限制,因此您必須在輸出規則中指定 method: *,允許所有 Cloud Asset API 方法。如果沒有輸出規則,要求就會失敗,並顯示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER 錯誤。詳情請參閱「對 VPC Service Controls 封鎖的要求進行偵錯」。

控制台

  1. 前往 Google Cloud 控制台的「政策分析工具」頁面。

    前往政策分析工具

  2. 在「Analyze organization policy」(分析組織政策) 部分,找到標示為「Which projects or folders are affected by an organization policy constraint?」(哪些專案或資料夾受組織政策限制影響?) 的窗格,然後點選該窗格中的「Create query」(建立查詢)。

  3. 在「Select query organization」(選取查詢組織) 方塊中,選取要分析組織政策的組織。

  4. 選取要分析的限制類型。如為預先定義或代管限制,請選取「Built-in constraint」(內建限制)。如要使用自訂限制,請選取「Custom constraint」(自訂限制)。

  5. 輸入要分析的限制名稱。系統已加入您要分析的限制類型前置字元。舉例來說,如果是預先定義的網域限制,請輸入 iam.allowedPolicyMemberDomains;如果是服務帳戶建立代管限制,請輸入 iam.managed.disableServiceAccountKeyCreation;如果是自訂限制,請輸入其名稱,例如 disableGkeAutoUpgrade。

  6. 按一下「Run query」(執行查詢)。報表頁面會顯示您輸入的查詢參數,以及強制執行或沿用這項限制的所有容器結果表格。

  7. 如要儲存這項查詢,以便日後再次查看,請按一下「Copy query URL」(複製查詢網址)。如要查看這項查詢,請前往產生的網址。

  8. 如要以圖表呈現分析限制的繼承關係,請從清單中選取至少一個容器,然後按一下「View inheritance」(查看繼承關係)。您也可以在建立分析查詢時,依序點選「Analyze」(分析) 和「Visualize」(視覺化),立即前往視覺化檢視畫面。詳情請參閱「視覺化繼承」。

gcloud

如要分析組織政策限制在組織內容器的強制執行情形,請使用 gcloud asset analyze-org-policy-governed-containers 指令:

gcloud asset analyze-org-policy-governed-containers \
    --constraint=CONSTRAINT_NAME  \
    --scope=organizations/ORGANIZATION_ID \
    --limit=LIMIT_CONTAINERS \
    --filter=FILTER_QUERY

更改下列內容:

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • LIMIT_CONTAINERS:要查看的結果項目數量。如要查看不限數量的項目,請輸入 unlimited。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的容器。唯一可用於篩選的欄位是 parent。舉例來說,parent="//cloudresourcemanager.googleapis.com/organizations/012345678901" 只會傳回組織 ID 為 012345678901 的組織子項容器。

YAML 回應應類似下列內容:

YAML 回應範例

---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1
  attachedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1
  rules:
  - values:
      allowedValues:
      - projects/donghe-project1/zones/us-central1-a/instances/instance-1
fullResourceName: //cloudresourcemanager.googleapis.com/projects/donghe-project1
parent: //cloudresourcemanager.googleapis.com/folders/86513245445
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1
  attachedResource: //cloudresourcemanager.googleapis.com/projects/donghe-project1
  inheritFromParent: true
  rules:
  - values:
      allowedValues:
      - projects/donghe-project1/zones/us-central1-a/instances/instance-1
---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1
  attachedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1
  rules:
  - denyAll: true
fullResourceName: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1
parent: //cloudresourcemanager.googleapis.com/organizations/474566717491
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1
  attachedResource: //cloudresourcemanager.googleapis.com/projects/jeffreyai-prj01-on-ipa1
  inheritFromParent: true
  rules:
  - denyAll: true
---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  rules:
  - values:
      allowedValues:
      - projects/opa-test-project-1-364621/zones/us-central1-a/instances/instance-1
fullResourceName: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
parent: //cloudresourcemanager.googleapis.com/folders/666681422980
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-1-364621
  rules:
  - values:
      allowedValues:
      - projects/opa-test-project-1-364621/zones/us-central1-a/instances/instance-1

REST

如要分析組織政策限制在組織內容器的強制執行情形,請使用 Cloud Asset API 的 analyzeOrgPolicyGovernedContainers 方法。

HTTP 方法和網址:

GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicyGovernedContainers

JSON 要求主體:

JSON_REQUEST="{
  'constraint': 'CONSTRAINT_NAME',
  'filter': '"FILTER_QUERY"',
  'page_size': PAGE_SIZE,
  'page_token': PAGE_TOKEN
}"

更改下列內容:

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的容器。唯一可用於篩選的欄位是 parent。例如,parent="//cloudresourcemanager.googleapis.com/organizations/012345678901" 只會傳回組織 ID 為 012345678901 的組織子項容器。

  • PAGE_SIZE:您要查看的結果項目頁數。如要查看不限數量的項目,請輸入 unlimited。如果結果項目總數大於 PAGE_SIZE,使用這個旗標設定的要求會傳回 nextPageToken 值。

  • PAGE_TOKEN:只能在包含 page_size 旗標的第一個要求之後,在要求上設定。您可以使用從先前回應收到的 nextPageToken 值,傳回特定結果頁面。

JSON 回應大致如下:

JSON 回應範例

{
  "governedContainers": [
    {
      "fullResourceName": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2",
      "parent": "//cloudresourcemanager.googleapis.com/folders/513502730678",
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678",
        "rules": [
          {
            "enforce": false
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678",
          "rules": [
            {
              "enforce": false
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980",
          "rules": [
            {
              "enforce": true
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980"
        }
      ]
    },
    {
      "fullResourceName": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-1",
      "parent": "//cloudresourcemanager.googleapis.com/folders/513502730678",
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678",
        "rules": [
          {
            "enforce": false
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678",
          "rules": [
            {
              "enforce": false
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/513502730678"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980",
          "rules": [
            {
              "enforce": true
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/666681422980"
        }
      ]
    }
  ]
  "constraint": {
    "googleDefinedConstraint": {
      "name": "constraints/compute.requireOsLogin",
      "displayName": "Require OS Login",
      "description": "This boolean constraint, when set to \u003ccode\u003etrue\u003c/code\u003e, enables OS Login on all newly created Projects. All VM instances created in new projects will have OS Login enabled. On new and existing projects, this constraint prevents metadata updates that disable OS Login at the project or instance level. \u003cbr\u003eBy default, the OS Login feature is disabled on Compute Engine projects.\u003cbr\u003eGKE instances in private clusters running node pool versions 1.20.5-gke.2000 and later support OS Login. GKE instances in public clusters do not currently support OS Login. If this constraint is applied to a Project running public clusters, GKE instances running in that Project may not function properly.",
      "constraintDefault": "ALLOW",
      "booleanConstraint": {}
    }
  }
}

分析資產

這裡的資產是指 Google Cloud 資源或 Identity and Access Management (IAM) 允許政策。您可以使用政策分析工具,傳回所有資產的清單,其中列出已強制執行特定限制的組織政策。支援自訂限制、代管限制和下列預先定義的限制:

  • constraints/ainotebooks.accessMode
  • constraints/ainotebooks.disableFileDownloads
  • constraints/ainotebooks.disableRootAccess
  • constraints/ainotebooks.disableTerminal
  • constraints/ainotebooks.environmentOptions
  • constraints/ainotebooks.requireAutoUpgradeSchedule
  • constraints/ainotebooks.restrictVpcNetworks
  • constraints/compute.disableGuestAttributesAccess
  • constraints/compute.disableInstanceDataAccessApis
  • constraints/compute.disableNestedVirtualization
  • constraints/compute.disableSerialPortAccess
  • constraints/compute.disableSerialPortLogging
  • constraints/compute.disableVpcExternalIpv6
  • constraints/compute.requireOsLogin
  • constraints/compute.requireShieldedVm
  • constraints/compute.restrictLoadBalancerCreationForTypes
  • constraints/compute.restrictProtocolForwardingCreationForTypes
  • constraints/compute.restrictXpnProjectLienRemoval
  • constraints/compute.setNewProjectDefaultToZonalDNSOnly
  • constraints/compute.skipDefaultNetworkCreation
  • constraints/compute.trustedImageProjects
  • constraints/compute.vmCanIpForward
  • constraints/compute.vmExternalIpAccess
  • constraints/gcp.detailedAuditLoggingMode
  • constraints/gcp.resourceLocations
  • constraints/iam.allowedPolicyMemberDomains
  • constraints/iam.automaticIamGrantsForDefaultServiceAccounts
  • constraints/iam.disableServiceAccountCreation
  • constraints/iam.disableServiceAccountKeyCreation
  • constraints/iam.disableServiceAccountKeyUpload
  • constraints/iam.restrictCrossProjectServiceAccountLienRemoval
  • constraints/iam.serviceAccountKeyExpiryHours
  • constraints/resourcemanager.accessBoundaries
  • constraints/resourcemanager.allowedExportDestinations
  • constraints/sql.restrictAuthorizedNetworks
  • constraints/sql.restrictNoncompliantDiagnosticDataAccess
  • constraints/sql.restrictNoncompliantResourceCreation
  • constraints/sql.restrictPublicIp
  • constraints/storage.publicAccessPrevention
  • constraints/storage.restrictAuthTypes
  • constraints/storage.uniformBucketLevelAccess

政策分析工具會傳回每項資產的全名、資產在階層中的上層,以及階層中資產上方的任何祖系專案、資料夾和組織資源。

對於在查詢範圍內偵測到的每項資產,政策分析工具都會傳回一筆結果項目。

資源的結果項目包含下列欄位:

  • consolidatedPolicy:附加組織政策的資源,以及該資源根據階層評估規則強制執行的有效政策。

  • conditionEvaluation:如果納入的條件導致強制執行組織政策,evaluationValue 為 TRUE。如果條件導致組織政策未強制執行,evaluationValue 會FALSE。如果強制執行組織政策的一或多項資源不支援該條件,系統會傳回條件本身。

  • assetType:資產的資源類型。

  • effectiveTags:直接附加至組織政策所附加資源的所有標記,或由該資源繼承的所有標記,以及階層中該資源的父項。

  • folders:任何資料夾資源的 ID,其中包含附加組織政策的資源。

  • fullResourceName:資源的完整資源名稱。

  • organization:包含資源的組織相對資源名稱。

  • parent:資源上層的完整資源名稱。

  • project:資源所在專案的 ID。

  • policyBundle:附加至上述資源的完整設定組織政策,以及在資源階層中,為其祖系定義的組織政策。

允許政策的結果項目包含下列欄位:

  • consolidatedPolicy:附加組織政策的資源,以及該資源根據階層評估規則強制執行的有效政策。

  • assetType:附加允許政策的資源類型。

  • attachedResource:附加允許政策的資源全名。

  • folders:包含允許政策的任何資料夾相對資源名稱。

  • organization:包含允許政策的組織相對資源名稱。

  • policy:允許政策。

  • project:包含允許政策的專案相對資源名稱。

  • policyBundle:附加至上述資源的完整設定組織政策,以及在資源階層中,為其祖系定義的組織政策。

如果資源受到 VPC Service Controls service perimeter 保護,您必須在組織資源的 perimeter 中建立輸出規則,允許存取 cloudasset.googleapis.com 服務。Cloud Asset API 不支援方法層級限制,因此您必須在輸出規則中指定 method: *,允許所有 Cloud Asset API 方法。如果沒有輸出規則,要求就會失敗,並顯示 NETWORK_NOT_IN_SAME_SERVICE_PERIMETER 錯誤。詳情請參閱「對 VPC Service Controls 封鎖的要求進行偵錯」。

控制台

  1. 前往 Google Cloud 控制台的「政策分析工具」頁面。

    前往政策分析工具

  2. 在「Analyze organization policy」(分析組織政策) 部分,找到標示為「Which resources are affected by an organization policy constraint?」(哪些資源受組織政策限制影響?) 的窗格,然後點選該窗格中的「Create query」(建立查詢)。

  3. 在「Select query organization」(選取查詢組織) 方塊中,選取要分析組織政策的組織。

  4. 選取要分析的限制類型。如要使用預先定義或代管限制,請選取「Built-in constraint」(內建限制)。如要使用自訂限制,請選取「Custom constraint」(自訂限制)。

  5. 輸入要分析的限制名稱。系統已加入您要分析的限制類型前置字元。舉例來說,如果是預先定義的值區層級存取權限制,請輸入 storage.uniformBucketLevelAccess;如果是服務帳戶建立代管限制,請輸入 iam.managed.disableServiceAccountKeyCreation;如果是自訂限制,請輸入其名稱,例如 disableGkeAccess。

  6. 按一下「Run query」(執行查詢)。報表頁面會顯示您輸入的查詢參數,以及強制執行或繼承這項限制的所有資產結果表格。

  7. 如要儲存這項查詢,以便日後再次查看,請按一下「Copy query URL」(複製查詢網址)。如要查看這項查詢,請前往產生的網址。

  8. 如要以視覺化方式呈現分析限制的繼承關係,請從清單中選取至少一項資產,然後按一下「View inheritance」(查看繼承關係)。您也可以在建立分析查詢時,依序點選「Analyze」(分析) 和「Visualize」(視覺化),立即前往視覺化檢視畫面。詳情請參閱「視覺化繼承」。

gcloud

如要分析組織政策限制對組織內資產的強制執行方式,請使用 gcloud asset analyze-org-policy-governed-assets 指令:

gcloud asset analyze-org-policy-governed-assets \
    --constraint=CONSTRAINT_NAME  \
    --scope=organizations/ORGANIZATION_ID \
    --limit=LIMIT_ASSETS \
    --filter=FILTER_QUERY

更改下列內容:

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • LIMIT_ASSETS:要查看的結果項目數量。如要查看不限數量的項目,請輸入 unlimited。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的資產。可用於篩選的欄位包括 governed_resource.folders、governed_resource.project、governed_iam_policy.folders 和 governed_iam_policy.project。舉例來說,governed_resource.project="projects/1234567890" 只會傳回附加至專案 ID 為 1234567890 的專案資產。

YAML 回應應類似下列內容:

YAML 回應範例

---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2
  rules:
  - enforce: false
governedResource:
  folders:
  - folders/513502730678
  - folders/666681422980
  fullResourceName: //container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1/nodePools/default-pool
  organization: organizations/474566717491
  parent: //container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1
  project: projects/892625391619
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2
  attachedResource: //cloudresourcemanager.googleapis.com/projects/opa-test-project-2
  reset: true
- appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true
---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918
  attachedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918
  rules:
  - enforce: false
governedResource:
  folders:
  - folders/800636178739
  - folders/408342778736
  fullResourceName: //container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1/nodePools/default-pool
  organization: organizations/474566717491
  parent: //container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1
  project: projects/761097189269
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918
  attachedResource: //cloudresourcemanager.googleapis.com/projects/project2-244918
  rules:
  - enforce: false
- appliedResource: //cloudresourcemanager.googleapis.com/folders/408342778736
  attachedResource: //cloudresourcemanager.googleapis.com/folders/408342778736
  rules:
  - condition:
      description: cond-desc1
      expression: resource.matchTag("474566717491/env", "prod")
      title: cond-title1
    enforce: false
  - enforce: true
- appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true
---
consolidatedPolicy:
  appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true
governedResource:
  fullResourceName: //container.googleapis.com/projects/probe-per-rt-project/zones/us-west1-a/clusters/test-cluster-for-backup/nodePools/default-pool
  organization: organizations/474566717491
  parent: //container.googleapis.com/projects/probe-per-rt-project/zones/us-west1-a/clusters/test-cluster-for-backup
  project: projects/896190383908
policyBundle:
- appliedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  attachedResource: //cloudresourcemanager.googleapis.com/organizations/474566717491
  rules:
  - enforce: true

REST

如要分析組織政策限制對組織內資產的強制執行情形,請使用 Cloud Asset API 的 analyzeOrgPolicyGovernedAssets 方法。

HTTP 方法和網址:

GET https://cloudasset.googleapis.com/v1/organizations/ORGANIZATION_ID:analyzeOrgPolicyGovernedAssets

JSON 要求主體:

JSON_REQUEST="{
  'constraint': 'CONSTRAINT_NAME',
  'filter': 'FILTER_QUERY',
  'page_size': PAGE_SIZE,
  'page_token': PAGE_TOKEN
}"

更改下列內容:

  • ORGANIZATION_ID:組織資源的 ID。如要進一步瞭解如何找出組織 ID,請參閱「建立及管理組織」。

  • CONSTRAINT_NAME:要分析的組織政策限制名稱。如需限制清單,請參閱「組織政策限制」。

  • FILTER_QUERY:篩選查詢,只查看符合篩選運算式的資產。可用於篩選的欄位包括 governed_resource.folders、governed_resource.project、governed_iam_policy.folders 和 governed_iam_policy.project。舉例來說,governed_resource.project="projects/1234567890" 只會傳回附加至專案 ID 為 1234567890 的專案資產。

  • PAGE_SIZE:您要查看的結果項目頁數。如要查看不限數量的項目,請輸入 unlimited。如果結果項目總數大於 PAGE_SIZE,使用這個旗標設定的要求會傳回 nextPageToken 值。

  • PAGE_TOKEN:只能在包含 page_size 旗標的第一個要求之後,在要求上設定。您可以使用從先前回應收到的 nextPageToken 值,傳回特定結果頁面。

JSON 回應大致如下:

JSON 回應範例

{
  "governedAssets": [
    {
      "governedResource": {
        "fullResourceName": "//container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1/nodePools/default-pool",
        "parent": "//container.googleapis.com/projects/opa-test-project-2/zones/us-central1-c/clusters/opa-test-project-2-cluster-1",
        "project": "projects/892625391619",
        "folders": [
          "folders/513502730678",
          "folders/666681422980"
        ],
        "organization": "organizations/474566717491"
      },
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2",
        "rules": [
          {
            "enforce": false
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2",
          "reset": true,
          "appliedResource": "//cloudresourcemanager.googleapis.com/projects/opa-test-project-2"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491",
          "rules": [
            {
              "enforce": true
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491"
        }
      ]
    },
    {
      "governedResource": {
        "fullResourceName": "//container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1/nodePools/default-pool",
        "parent": "//container.googleapis.com/projects/project2-244918/zones/us-central1-c/clusters/cluster-1",
        "project": "projects/761097189269",
        "folders": [
          "folders/800636178739",
          "folders/408342778736"
        ],
        "organization": "organizations/474566717491"
      },
      "consolidatedPolicy": {
        "attachedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918",
        "rules": [
          {
            "enforce": false
          }
        ],
        "appliedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918"
      },
      "policyBundle": [
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918",
          "rules": [
            {
              "enforce": false
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/projects/project2-244918"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/folders/408342778736",
          "rules": [
            {
              "enforce": false,
              "condition": {
                "expression": "resource.matchTag(\"474566717491/env\", \"prod\")",
                "title": "cond-title1",
                "description": "cond-desc1"
              }
            },
            {
              "enforce": true
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/folders/408342778736"
        },
        {
          "attachedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491",
          "rules": [
            {
              "enforce": true
            }
          ],
          "appliedResource": "//cloudresourcemanager.googleapis.com/organizations/474566717491"
        }
      ]
    }
  ]
  "constraint": {
    "customConstraint": {
      "name": "organizations/474566717491/customConstraints/custom.disableGkeAutoUpgrade",
      "resourceTypes": [
        "container.googleapis.com/NodePool"
      ],
      "methodTypes": [
        "CREATE",
        "UPDATE"
      ],
      "condition": "resource.management.autoUpgrade == false",
      "actionType": "ALLOW",
      "displayName": "Disable GKE auto upgrade",
      "description": "Only allow GKE NodePool resource create or updates if AutoUpgrade is not enabled"
    }
  }
}

以圖表呈現繼承關係

如果您在組織層級啟用 Security Command Center 的 Premium 或 Enterprise 級別,可以使用 Google Cloud 控制台,以視覺化方式呈現已分析的組織政策繼承關係。

如要查看沿用關係圖,請針對已設定的政策、容器或資產建立組織政策分析查詢。在「Run query analysis」(執行查詢分析) 頁面中,依序點選「Analyze」(分析) 和「Visualize」(視覺化)。

您也可以前往已儲存的查詢的網址,選取要醒目顯示的資源,然後按一下 「View inheritance」(查看繼承關係)。

「Resource inheritance」(資源繼承) 頁面會以視覺化方式,呈現分析查詢中所選資源的資源階層:

資源階層中組織政策沿用情形的圖表。 未強制執行的布林值政策示意圖。

  1. 指出資源是組織、資料夾或專案。

  2. 藍色圓點表示查詢中已選取該資源。

  3. 表示資源會覆寫父項資源的政策。

  4. 表示資源會將組織政策重設為 Google 代管的預設值。如果資源將政策重設為預設值,則會以虛線連接至父項。

  5. 表示資源會與父項合併政策。

  6. 表示這項資源的組織政策會強制執行布林限制,或具有允許值的清單限制。

  7. 表示這項資源的組織政策是清單限制,且含有遭拒的值。

  8. 表示這項資源的組織政策是未強制執行的布林限制。

後續步驟