用於自動核准和拒絕存取政策的聲明結構和內建運算子 - AWS Systems Manager

AWS Systems ManagerChange Manager 不再開放給新客戶。現有客戶可以繼續正常使用該服務。如需詳細資訊,請參閱AWS Systems ManagerChange Manager可用性變更

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

用於自動核准和拒絕存取政策的聲明結構和內建運算子

下表顯示自動核准與拒絕存取政策的結構。

元件 語法
效用

permit | forbid

scope

(principal, action, resource)

條件子句
when { principal or resource has attribute name };

政策元件

自動核准或拒絕存取政策包含下列元件:

  • 效果permit (允許) 或 forbid (拒絕) 存取。

  • 範圍 – 套用效果的主體、動作和資源。您可以不識別特定主體、動作或資源,讓 Cedar 中的範圍保持未定義的狀態。在此情況下,政策適用於所有可能的主體、動作和資源。對於即時節點存取,action 一律為 AWS::SSM::Action::"getTokenForInstanceAccess"

  • 條件子句 – 套用效果的內容。

說明

您可以在政策中包含註解。註解定義為以 // 開頭和以換行符號字元結尾的行。

以下範例顯示政策中的註解。

// Allows users in the Engineering group from the Platform org to automatically connect to nodes tagged with Engineering and Production keys. permit ( principal in AWS::IdentityStore::Group::"d4q81745-r081-7079-d789-14da1EXAMPLE", action == AWS::SSM::Action::"getTokenForInstanceAccess", resource ) when { principal has organization && resource.hasTag("Engineering") && resource.hasTag("Production") && principal.organization == "Platform" };

多個子句

您可以使用 && 運算子,在政策陳述式中使用多個條件子句。

// Allow access if node has tag where the tag key is Environment // & tag value is Development permit(principal, action == AWS::SSM::getTokenForInstanceAccess, resource) when { resource.hasTag("Environment") && resource.getTag("Environment") == "Development" };

保留字元

下列範例顯示如何在內容屬性使用 : (分號) (這是政策語言中的保留字元) 時寫入政策。

permit ( principal, action == AWS::SSM::Action::"getTokenForInstanceAccess", resource ) when { principal has employeeNumber && principal.employeeNumber like "E-1*" && resource.hasTag("Purpose") && resource.getTag("Purpose") == "Testing" }

如需額外的範例,請參閱政策陳述式範例

即時節點存取結構描述

以下是即時節點存取的 Cedar 結構描述。

namespace AWS::EC2 { entity Instance tags String; } namespace AWS::IdentityStore { entity Group; entity User in [Group] { employeeNumber?: String, costCenter?: String, organization?: String, division?: String, }; } namespace AWS::IAM { entity Role; type AuthorizationContext = { principalTags: PrincipalTags, }; entity PrincipalTags tags String; } namespace AWS::SSM { entity ManagedInstance tags String; action "getTokenForInstanceAccess" appliesTo { principal: [AWS::IdentityStore::User], resource: [AWS::EC2::Instance, AWS::SSM::ManagedInstance], context: { "iam": AWS::IAM::AuthorizationContext } }; }

內建運算子

使用各種條件建立自動核准或拒絕存取政策的內容時,您可以使用 && 運算子新增其他條件。您也可以使用許多其他內建運算子,為您的政策條件新增額外的表述能力。下表包含所有內建運算子,以供參考。

運算子 類型與多載 描述

!

布林值 → 布林值

邏輯非。

==

任何 → 任何

相等。適用於任何類型的引數,即使類型並不相符。不同類型的值永遠不會彼此相等。

!= 任何 → 任何

不相等;與相等完全相反 (請參閱上文)。

<

(長整數、長整數) → 布林值

長整數小於。

<=

(長整數、長整數) → 布林值

長整數小於等於。

>

(長整數、長整數) → 布林值

長整數大於。

>=

(長整數、長整數) → 布林值

長整數大於等於。

in (實體、實體) → 布林值 階層成員資格 (自反:A 中的 A 一律為 true)。
(實體、集合(實體)) → 布林值 階層成員資格:如果 (A 和 B) || (C 中的 A) || 則 [B, C, ...] 中的 A 為 true;如果集合包含非實體,則錯誤。
&& (布林值、布林值) → 布林值

邏輯和 (short-circuiting)。

|| (布林值、布林值) → 布林值

邏輯或 (short-circuiting)。

.exists() 實體 → 布林值 實體存在。
has (實體、屬性) → 布林值 infix 運算子。e has f 測試記錄或實體 e 是否具有屬性 f 的繫結。如果 e 不存在或 e 存在但沒有屬性 f,則傳回 false。屬性可以表示為識別碼或字串常值。
like (字串、字串) → 布林值 Infix 運算子。t like p 檢查文字 t 是否符合模式 p,其中可能包含符合 0 或多個任何字元的萬用字元 *。為了符合 t 中的常值星形字元,您可以使用 p 中的特殊逸出字元序列 \*
.hasTag() (實體、字串) → 布林值 檢查實體是否已套用指定標籤。
.getTag() (實體、字串) → 布林值 傳回指定標籤鍵的值。
.contains() (集合、任何) → 布林值 設定成員資格 (B 為 A 的元素)。
.containsAll() (集合、集合) → 布林值 測試集合 A 是否包含集合 B 中的所有元素。
.containsAny() (集合、集合) → 布林值 測試集合 A 是否包含集合 B 中的任何元素。

政策陳述式範例

以下是政策陳述式範例。

// Users assuming IAM roles with a principal tag of "Elevated" can automatically access nodes tagged with the "Environment" key when the value equals "prod" permit(principal, action == AWS::SSM::getTokenForInstanceAccess, resource) when { // Verify IAM role principal tag context.iam.principalTags.getTag("AccessLevel") == "Elevated" && // Verify the node has a tag with "Environment" tag key and a tag value of "prod" resource.hasTag("Environment") && resource.getTag("Environment") == "prod" };
// Identity Center users in the "Contractor" division can automatically access nodes tagged with the "Environment" key when the value equals "dev" permit(principal, action == AWS::SSM::getTokenForInstanceAccess, resource) when { // Verify that the user is part of the "Contractor" division principal.division == "Contractor" && // Verify the node has a tag with "Environment" tag key and a tag value of "dev" resource.hasTag("Environment") && resource.getTag("Environment") == "dev" };
// Identity Center users in a specified group can automatically access nodes tagged with the "Environment" key when the value equals "Production" permit(principal in AWS::IdentityStore::Group::"d4q81745-r081-7079-d789-14da1EXAMPLE", action == AWS::SSM::getTokenForInstanceAccess, resource) when { resource.hasTag("Environment") && resource.getTag("Environment") == "Production" };