Policy

身分與存取權管理 (IAM) 政策,可指定 Google Cloud 資源的存取權控管。

Policybindings 的集合。binding 會將一或多個 members (或主體) 繫結至單一 role。主體可以是使用者帳戶、服務帳戶、Google 群組和網域 (例如 G Suite)。role 是具名權限清單,每個 role 可以是 IAM 預先定義的角色,或使用者建立的自訂角色。

對於某些類型的 Google Cloud 資源,binding 也可以指定 condition,這是邏輯運算式,只有在運算式評估為 true 時,才能存取資源。條件可以根據要求或資源的屬性 (或兩者) 新增限制。如要瞭解哪些資源支援 IAM 政策中的條件,請參閱 IAM 說明文件

JSON 範例:

    {
      "bindings": [
        {
          "role": "roles/resourcemanager.organizationAdmin",
          "members": [
            "user:mike@example.com",
            "group:admins@example.com",
            "domain:google.com",
            "serviceAccount:my-project-id@appspot.gserviceaccount.com"
          ]
        },
        {
          "role": "roles/resourcemanager.organizationViewer",
          "members": [
            "user:eve@example.com"
          ],
          "condition": {
            "title": "expirable access",
            "description": "Does not grant access after Sep 2020",
            "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')",
          }
        }
      ],
      "etag": "BwWWja0YfJA=",
      "version": 3
    }

YAML 範例:

    bindings:
    - members:
      - user:mike@example.com
      - group:admins@example.com
      - domain:google.com
      - serviceAccount:my-project-id@appspot.gserviceaccount.com
      role: roles/resourcemanager.organizationAdmin
    - members:
      - user:eve@example.com
      role: roles/resourcemanager.organizationViewer
      condition:
        title: expirable access
        description: Does not grant access after Sep 2020
        expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
    etag: BwWWja0YfJA=
    version: 3

如需 IAM 及其功能的說明,請參閱 IAM 說明文件

JSON 表示法
{
  "version": integer,
  "bindings": [
    {
      object (Binding)
    }
  ],
  "auditConfigs": [
    {
      object (AuditConfig)
    }
  ],
  "etag": string
}
欄位
version

integer

指定政策的格式。

有效值為 013。系統會拒絕指定無效值的要求。

任何影響條件角色繫結的作業都必須指定 3 版本。這項規定適用於下列作業:

  • 取得包含條件式角色繫結的政策
  • 將條件角色繫結新增至政策
  • 變更政策中的條件式角色繫結
  • 從包含條件的政策中移除任何角色繫結 (不論是否有條件)

重要事項:如果您使用 IAM 條件,每次呼叫 setIamPolicy 時都必須加入 etag 欄位。如果您省略這個欄位,IAM 就會允許您使用版本 1 政策覆寫版本 3 政策,而版本 3 政策中的所有條件都會遺失。

如果政策不包含任何條件,對該政策執行的作業可以指定任何有效版本,也可以不指定欄位。

如要瞭解哪些資源支援 IAM 政策中的條件,請參閱 IAM 說明文件

bindings[]

object (Binding)

members 或主體清單與 role 建立關聯。您可以視需要指定 condition,以決定套用 bindings 的方式和時機。每個 bindings 都必須包含至少一個主要元素。

Policy 中的 bindings 最多可參照 1,500 個主體,其中最多 250 個主體可為 Google 群組。每個主體都會計入這些限制。舉例來說,如果 bindings 將 50 個不同角色授予 user:alice@example.com,但沒有授予其他主體,您就可以在 Policy 中將其他 1,450 個主體新增至 bindings

auditConfigs[]

object (AuditConfig)

指定此政策的雲端稽核記錄設定。

etag

string (bytes format)

etag 用於開放式並行控制,有助防止政策在同時更新時相互覆寫。強烈建議系統在讀取-修改-寫入週期中使用 etag 執行政策更新,以避免發生競爭狀況:getIamPolicy 的回應會傳回 etag,系統應將該 etag 放入 setIamPolicy 的要求中,確保變更會套用至相同版本的政策。

重要事項:如果您使用 IAM 條件,每次呼叫 setIamPolicy 時都必須加入 etag 欄位。如果您省略這個欄位,IAM 就會允許您使用版本 1 政策覆寫版本 3 政策,而版本 3 政策中的所有條件都會遺失。

Base64 編碼字串。

繫結

members (或主要實體) 與 role 建立關聯。

JSON 表示法
{
  "role": string,
  "members": [
    string
  ],
  "condition": {
    object (Expr)
  }
}
欄位
role

string

指派給 members 清單或主體的角色。例如 roles/viewerroles/editorroles/owner

如要瞭解 IAM 角色和權限的總覽,請參閱 身分與存取權管理說明文件。如需可用預先定義角色的清單,請參閱這裡

members[]

string

指定要求 Google Cloud 資源存取權的主體。members 的值可能如下:

  • allUsers:這種特殊的身分識別代表網際網路上的所有使用者,無論該使用者是否有 Google 帳戶。

  • allAuthenticatedUsers:這種特殊的身分識別代表任何透過 Google 帳戶或服務帳戶進行驗證的使用者。不包含透過身分聯盟機制取得的第三方身分提供者 (IdP) 所提供的身分。

  • user:{emailid}:代表特定 Google 帳戶的電子郵件地址,例如:alice@example.com

  • serviceAccount:{emailid}:代表 Google 服務帳戶的電子郵件地址。例如:my-other-app@appspot.gserviceaccount.com

  • serviceAccount:{projectid}.svc.id.goog[{namespace}/{kubernetes-sa}]Kubernetes 服務帳戶的 ID。例如:my-project.svc.id.goog[my-namespace/my-kubernetes-sa]

  • group:{emailid}:代表 Google 群組的電子郵件地址。例如:admins@example.com

  • domain:{domain}:代表該網域所有使用者的 G Suite 網域 (主要),例如 google.comexample.com
  • principal://iam.googleapis.com/locations/global/workforcePools/{pool_id}/subject/{subject_attribute_value}:工作團隊身分集區中的單一身分。

  • principalSet://iam.googleapis.com/locations/global/workforcePools/{pool_id}/group/{groupId}:群組中的所有員工身分。

  • principalSet://iam.googleapis.com/locations/global/workforcePools/{pool_id}/attribute.{attribute_name}/{attribute_value}:具有特定屬性值的所有工作群體身分。

  • principalSet://iam.googleapis.com/locations/global/workforcePools/{pool_id}/*:工作團隊身分集區中的所有身分。

  • principal://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{pool_id}/subject/{subject_attribute_value}:工作負載身分金鑰容器中的單一身分。

  • principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{pool_id}/group/{groupId}:工作負載身分集區群組。

  • principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{pool_id}/attribute.{attribute_name}/{attribute_value}:具有特定屬性的 workload identity pool 中的所有身分。

  • principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{pool_id}/*:工作負載身分集區中的所有身分。

  • deleted:user:{emailid}?uid={uniqueid}:代表最近刪除的使用者電子郵件地址 (加上專屬 ID)。例如:alice@example.com?uid=123456789012345678901。如果使用者已復原,這個值會還原為 user:{emailid},且復原的使用者會保留綁定中的角色。

  • deleted:serviceAccount:{emailid}?uid={uniqueid}:代表最近刪除的服務帳戶的電子郵件地址 (加上專屬 ID)。例如 my-other-app@appspot.gserviceaccount.com?uid=123456789012345678901。如果服務帳戶未刪除,這個值會還原為 serviceAccount:{emailid},且未刪除的服務帳戶會保留繫結中的角色。

  • deleted:group:{emailid}?uid={uniqueid}:代表最近已刪除的 Google 群組的電子郵件地址 (加上專屬 ID)。例如,admins@example.com?uid=123456789012345678901。如果群組已復原,這個值會還原為 group:{emailid},且復原的群組會保留繫結中的角色。

  • deleted:principal://iam.googleapis.com/locations/global/workforcePools/{pool_id}/subject/{subject_attribute_value}:在工作團隊身分集區中刪除單一身分。例如:deleted:principal://iam.googleapis.com/locations/global/workforcePools/my-pool-id/subject/my-subject-attribute-value

condition

object (Expr)

與此繫結相關聯的條件。

如果條件評估為 true,則此繫結會套用至目前要求。

如果條件評估為 false,則此繫結不適用於目前要求。不過,不同的角色繫結可能會為此繫結中的一或多個主體授予相同的角色。

如要瞭解哪些資源支援 IAM 政策中的條件,請參閱 IAM 說明文件

Expr

代表一般運算語言 (CEL) 語法中的文字運算式。CEL 是類似 C 的運算式語言。如要查看 CEL 的語法和語意,請前往 https://github.com/google/cel-spec

範例 (比較):

title: "Summary size limit"
description: "Determines if a summary is less than 100 chars"
expression: "document.summary.size() < 100"

範例 (相等):

title: "Requestor is owner"
description: "Determines if requestor is the document owner"
expression: "document.owner == request.auth.claims.email"

範例 (邏輯):

title: "Public documents"
description: "Determine whether the document should be publicly visible"
expression: "document.type != 'private' && document.type != 'internal'"

示例 (資料操控):

title: "Notification string"
description: "Create a notification string with a timestamp."
expression: "'New message received at ' + string(document.create_time)"

運算式中可參照的確切變數和函式,取決於評估運算式的服務。如需更多資訊,請參閱服務說明文件。

JSON 表示法
{
  "expression": string,
  "title": string,
  "description": string,
  "location": string
}
欄位
expression

string

使用一般運算語言語法的運算式文字表示法。

title

string

(非必要) 運算式的標題,即描述其用途的簡短字串。這可用在允許輸入運算式的 UI 中。

description

string

(非必要) 運算式的說明。這是一段較長的文字,用於描述運算式。舉例來說,使用者在 UI 中將游標懸停在運算式上方時,即可顯示說明文字。

location

string

(非必要) 指出要提報錯誤的運算式所在位置,例如檔案名稱及檔案內的位置。

AuditConfig

指定服務的稽核設定。這類設定可判斷要記錄的權限類型,以及哪些身分識別不必記錄 (如適用)。AuditConfig 必須具有一或多個 AuditLogConfig。

如果 allServices 和特定服務都有 AuditConfigs,則該服務會使用這兩個 AuditConfig 的聯集:每個 AuditConfig 中指定的 log_types 都會啟用,而每個 AuditLogConfig 中的 exemptedMembers 則不啟用。

具有多個 AuditConfigs 的範例政策:

{
  "auditConfigs": [
    {
      "service": "allServices",
      "auditLogConfigs": [
        {
          "logType": "DATA_READ",
          "exemptedMembers": [
            "user:jose@example.com"
          ]
        },
        {
          "logType": "DATA_WRITE"
        },
        {
          "logType": "ADMIN_READ"
        }
      ]
    },
    {
      "service": "sampleservice.googleapis.com",
      "auditLogConfigs": [
        {
          "logType": "DATA_READ"
        },
        {
          "logType": "DATA_WRITE",
          "exemptedMembers": [
            "user:aliya@example.com"
          ]
        }
      ]
    }
  ]
}

針對 sampleservice,這項政策會啟用 DATA_READ、DATA_WRITE 和 ADMIN_READ 記錄功能。此外,該政策會將 jose@example.com 從 DATA_READ 記錄中排除,並將 aliya@example.com 從 DATA_WRITE 記錄中排除。

JSON 表示法
{
  "service": string,
  "auditLogConfigs": [
    {
      object (AuditLogConfig)
    }
  ]
}
欄位
service

string

指定要啟用稽核記錄功能的服務,例如:storage.googleapis.comcloudsql.googleapis.comallServices 是涵蓋所有服務的特殊值。

auditLogConfigs[]

object (AuditLogConfig)

用於記錄各類型權限的設定。

AuditLogConfig

提供用於記錄權限類型的設定,例如:

{
  "auditLogConfigs": [
    {
      "logType": "DATA_READ",
      "exemptedMembers": [
        "user:jose@example.com"
      ]
    },
    {
      "logType": "DATA_WRITE"
    }
  ]
}

這樣可以啟用「DATA_READ」和「DATA_WRITE」記錄功能,同時避免 DATA_READ 記錄 jose@example.com

JSON 表示法
{
  "logType": enum (LogType),
  "exemptedMembers": [
    string
  ]
}
欄位
logType

enum (LogType)

此設定啟用的記錄類型。

exemptedMembers[]

string

指定不會導致記錄這類權限的身分識別,遵循 Binding.members 格式。

LogType

可設定記錄的有效權限類型清單。管理員寫入一律記錄,且無法設定。

列舉
LOG_TYPE_UNSPECIFIED 預設大小寫。一律不應為此值。
ADMIN_READ 管理員讀取,例如 CloudIAM getIamPolicy
DATA_WRITE 資料寫入,例如 CloudSQL Users create
DATA_READ 資料讀取,例如 CloudSQL Users list