自動承認ポリシーとアクセス拒否ポリシーのステートメントの構造とビルトイン演算子 - AWS Systems Manager

自動承認ポリシーとアクセス拒否ポリシーのステートメントの構造とビルトイン演算子

次の表は、自動承認ポリシーとアクセス拒否ポリシーの構造を示しています。

コンポーネント 構文
effect

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" };

複数の句

&& 演算子を使用すると、1 つのポリシーステートメントに複数の条件句を含めることができます。

// 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 } }; }

ビルトイン演算子

さまざまな条件を使用して自動承認ポリシーまたはアクセス拒否ポリシーのコンテキストを作成する場合は、&& 演算子を使用して追加条件を指定できます。ポリシー条件にさらに表現力を加えるために使用できるビルトイン演算子は他にも多数あります。参照用にすべてのビルトイン演算子を下表に示します。

演算子 タイプとオーバーロード 説明

!

Boolean → Boolean

論理否定。

==

any → any

等価。タイプが一致しなくても、いずれかのタイプの引数で機能します。異なるタイプの値が互いに等しくなることはありません。

!= any → any

不等価。等価の正反対 (上記参照)。

<

(long, long) → Boolean

Long integer less-than.

<=

(long, long) → Boolean

Long integer less-than-or-equal-to.

>

(long, long) → Boolean

Long integer greater-than.

>=

(long, long) → Boolean

Long integer greater-than-or-equal-to.

in (entity, entity) → Boolean 階層メンバーシップ (再帰形:A の A は常にトゥルー)。
(entity, set(entity)) → Boolean 階層メンバーシップ:(A and B) || (A in C) || であれば A in [B, C, ...] はトゥルー... セットに non-entity が含まれている場合はエラーになります。
&& (Boolean, Boolean) → Boolean

Logical and (short-circuiting).

|| (Boolean, Boolean) → Boolean

Logical or (short-circuiting).

.exists() entity → Boolean Entity existence.
has (entity, attribute) → Boolean 中置演算子。 e has f レコードまたはエンティティに e 属性 f へのバインディングがあるかどうかをテストします。e が存在しないか、e が存在しても属性 f を持たない場合は false を返します。属性は識別子または文字列リテラルとして表現できます。
like (string, string) → Boolean 中置演算子。 t like p テキスト t がパターン p と一致するかどうかを確認します。パターンには、0 個以上の文字と一致するワイルドカード文字 * が含まれる場合があります。t のリテラルスター文字と一致させるには、p で特殊なエスケープ文字シーケンス \* を使用できます。
.hasTag() (entity, string) → Boolean エンティティに指定されたタグが適用されているかどうかを確認します。
.getTag() (entity, string) → Boolean 指定されたタグキーの値を返します。
.contains() (set, any) → Boolean メンバーシップ (B が A の要素かどうか) を設定します。
.containsAll() (set, set) → Boolean セット A にセット B のすべての要素が含まれているかどうかをテストします。
.containsAny() (set, set) → Boolean セット 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" };