

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# 例 2: Verified Permissions と Cedar を使用した基本的な RBAC
<a name="avp-basic-rbac-examples"></a>

この例では、Verified Permissions と Cedar を使用して基本的な RBAC を示します。前述のように、Cedar の基本コンストラクトはエンティティです。開発者は独自のエンティティを定義し、オプションでエンティティ間の関係を作成できます。次の例には、`Users`、、 の 3 種類のエンティティが含まれています`Problems`。 `Students` および は、 タイプのエンティティと見な`Role,`す`Teachers`ことができ`Roles`、それぞれを 0 または のいずれかに関連付ける`User`ことができます`Roles`。

![PDP を実装するための Amazon Verified Permissions と Cedar を使用した基本的な RBAC 実装の例](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/saas-multitenant-api-access-authorization/images/avp-example-2.png)


Cedar では、これらの関係は `Role``Student`を親`User``Bob`として にリンクすることで表現されます。この関連付けは、すべての学生ユーザーを 1 つのグループに論理的にグループ化します。Cedar でのグループ化の詳細については、[Cedar ドキュメント](https://docs.cedarpolicy.com/overview/terminology.html#term-group)を参照してください。

次のポリシーは、タイプ `Students`の論理グループにリンクされている`submitProblem,`すべてのプリンシパル`ALLOW`のアクションの決定を評価します`Role`。

```
permit (
    principal in ElearningApp::Role::"Students",
    action == ElearningApp::Action::"submitProblem",
    resource
);
```

次のポリシーは、タイプ `Teachers`の論理グループにリンクされているすべてのプリンシパルについて`answerProblem`、`ALLOW`アクション `submitProblem`または の決定を評価します`Role`。

```
permit (
    principal in ElearningApp::Role::"Teachers",
    action in [
        ElearningApp::Action::"submitProblem",
        ElearningApp::Action::"answerProblem"
    ],
    resource
);
```

これらのポリシーを使用してリクエストを評価するには、評価エンジンは、認可リクエスト内で参照されるプリンシパルが適切なグループのメンバーであるかどうかを知る必要があります。したがって、アプリケーションは認可リクエストの一部として関連するグループメンバーシップ情報を評価エンジンに渡す必要があります。これは `entities`プロパティを通じて行われます。これにより、認可呼び出しに関連するプリンシパルとリソースの属性とグループのメンバーシップデータを Cedar 評価エンジンに提供できます。次のコードでは、グループメンバーシップは、 `User::"Bob"`を という親として定義することで示されます`Role::"Students"`。

```
{
  "policyStoreId": "ELEARNING_POLICYSTOREID",
  "principal": {
    "entityType": "ElearningApp::User",
    "entityId": "Bob"
  },
  "action": {
    "actionType": "ElearningApp::Action",
    "actionId": "answerProblem"
  },
  "resource": {
    "entityType": "ElearningApp::Problem",
    "entityId": "SomeProblem"
  },
  "entities": {
    "entityList": [
        {
            "identifier": {
                "entityType": "ElearningApp::User",
                "entityId": "Bob"
            },
            "attributes": {},
            "parents": [
                {
                    "entityType": "ElearningApp::Role",
                    "entityId": "Students"
                } 
            ]
        },
        {
          "identifier": {
            "entityType": "ElearningApp::Problem",
            "entityId": "SomeProblem"
          },
          "attributes": {},
          "parents": []
        }
      ]
  }
}
```

この例では、Bob は`answerProblem`リクエストを行うログインユーザーです。したがって、Bob はプリンシパルであり、エンティティはタイプ です`User`。Bob が実行しようとしているアクションは です`answerProblem`。Bob が`answerProblem`アクションを実行できるかどうかを評価するには、エンティティを の値`User`にリンク`Bob`し、親エンティティを としてリストしてグループメンバーシップを割り当てるエンティティ構造を指定する必要があります`Role::"Students"`。ユーザーグループのエンティティ`Role::"Students"`はアクションを実行することしか許可されないため`submitProblem`、この認可リクエストは に評価されます`DENY`。

一方、 の値を持ち、 グループの一部`User`である タイプが`answerProblem`アクションを実行`Role::"Teachers"` しようとする`Alice`と、ポリシーはグループ内のプリンシパルがすべてのリソース`answerProblem`に対してアクションを実行することを許可するように指示するため`ALLOW`、認可リクエスト`Role::"Teachers"`は に評価されます。次のコードは、 に評価されるこのタイプの 認可リクエストを示しています`ALLOW`。

```
{
  "policyStoreId": "ELEARNING_POLICYSTOREID",
  "principal": {
    "entityType": "ElearningApp::User",
    "entityId": "Alice"
  },
  "action": {
    "actionType": "ElearningApp::Action",
    "actionId": "answerProblem"
  },
  "resource": {
    "entityType": "ElearningApp::Problem",
    "entityId": "SomeProblem"
  },
  "entities": {
    "entityList": [
        {
            "identifier": {
                "entityType": "ElearningApp::User",
                "entityId": "Alice"
            },
            "attributes": {},
            "parents": [
                {
                    "entityType": "ElearningApp::Role",
                    "entityId": "Teachers"
                } 
            ]
        },
        {
            "identifier": {
                "entityType": "ElearningApp::Problem",
                "entityId": "SomeProblem"
            },
            "attributes": {},
            "parents": []
        }
      ]
  }
}
```