提供意見
Policy
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Identity and Access Management (IAM) 政策,用於指定 Google Cloud 資源的存取權控管。
Policy
是 bindings
的集合。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
)
}
] ,
"etag" : string
}
欄位
version
integer
指定政策格式。
有效值為 0
、1
和 3
。如果要求指定無效值,系統會拒絕要求。
凡是會影響條件式角色繫結的作業,都必須指定版本 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
。
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/viewer
、roles/editor
或 roles/owner
。
如要瞭解身分與存取權管理角色和權限,請參閱身分與存取權管理說明文件 。如需可用預先定義角色的清單,請參閱這篇文章 。
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.com
或 example.com
。
principal://iam.googleapis.com/locations/global/workforcePools/{poolId}/subject/{subject_attribute_value}
:員工身分集區中的單一身分。
principalSet://iam.googleapis.com/locations/global/workforcePools/{poolId}/group/{groupId}
:群組中的所有員工身分。
principalSet://iam.googleapis.com/locations/global/workforcePools/{poolId}/attribute.{attributeName}/{attributeValue}
:具有特定屬性值的所有員工身分。
principalSet://iam.googleapis.com/locations/global/workforcePools/{poolId}/*
:員工身分集區中的所有身分。
principal://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{poolId}/subject/{subject_attribute_value}
:workload identity pool 中的單一身分。
principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{poolId}/group/{groupId}
:工作負載身分集區群組。
principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{poolId}/attribute.{attributeName}/{attributeValue}
:特定 workload identity pool 中具有特定屬性的所有身分。
principalSet://iam.googleapis.com/projects/{projectNumber}/locations/global/workloadIdentityPools/{poolId}/*
:Workload Identity Pool 中的所有身分。
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/{poolId}/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 說明文件 。
提供意見
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權 ,程式碼範例則為阿帕契 2.0 授權 。詳情請參閱《Google Developers 網站政策 》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-10-19 (世界標準時間)。
想進一步說明嗎?
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-10-19 (世界標準時間)。"],[],[]]