身分與存取權管理 (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 ( |
欄位 | |
---|---|
version |
指定政策的格式。 有效值為 任何影響條件角色繫結的作業都必須指定
重要事項:如果您使用 IAM 條件,每次呼叫 如果政策不包含任何條件,對該政策執行的作業可以指定任何有效版本,也可以不指定欄位。 如要瞭解哪些資源支援 IAM 政策中的條件,請參閱 IAM 說明文件。 |
bindings[] |
將
|
auditConfigs[] |
指定此政策的雲端稽核記錄設定。 |
etag |
重要事項:如果您使用 IAM 條件,每次呼叫 Base64 編碼字串。 |
繫結
將 members
(或主要實體) 與 role
建立關聯。
JSON 表示法 |
---|
{
"role": string,
"members": [
string
],
"condition": {
object ( |
欄位 | |
---|---|
role |
指派給 如要瞭解 IAM 角色和權限的總覽,請參閱 身分與存取權管理說明文件。如需可用預先定義角色的清單,請參閱這裡。 |
members[] |
指定要求 Google Cloud 資源存取權的主體。
|
condition |
與此繫結相關聯的條件。 如果條件評估為 如果條件評估為 如要瞭解哪些資源支援 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 |
使用一般運算語言語法的運算式文字表示法。 |
title |
(非必要) 運算式的標題,即描述其用途的簡短字串。這可用在允許輸入運算式的 UI 中。 |
description |
(非必要) 運算式的說明。這是一段較長的文字,用於描述運算式。舉例來說,使用者在 UI 中將游標懸停在運算式上方時,即可顯示說明文字。 |
location |
(非必要) 指出要提報錯誤的運算式所在位置,例如檔案名稱及檔案內的位置。 |
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 ( |
欄位 | |
---|---|
service |
指定要啟用稽核記錄功能的服務,例如: |
auditLogConfigs[] |
用於記錄各類型權限的設定。 |
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[] |
指定不會導致記錄這類權限的身分識別,遵循 |
LogType
可設定記錄的有效權限類型清單。管理員寫入一律記錄,且無法設定。
列舉 | |
---|---|
LOG_TYPE_UNSPECIFIED |
預設大小寫。一律不應為此值。 |
ADMIN_READ |
管理員讀取,例如 CloudIAM getIamPolicy |
DATA_WRITE |
資料寫入,例如 CloudSQL Users create |
DATA_READ |
資料讀取,例如 CloudSQL Users list |