

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

# Amazon Verified Permissions 與 Cedar 政策語言之間的差異
<a name="terminology-differences-avp-cedar"></a>

Amazon Verified Permissions 使用 Cedar 政策語言引擎來執行其授權任務。不過，原生 Cedar 實作與 Verified Permissions 中 Cedar 實作之間有一些差異。本主題識別這些差異。

## 命名空間定義
<a name="differences-namespaces"></a>

Cedar 的 Verified Permissions 實作與原生 Cedar 實作有下列差異：
+ Verified Permissions 在政策存放[區中定義的結構描述中僅支援一個命名空間](https://docs.cedarpolicy.com/schema/schema.html#namespace)。
+ Verified Permissions 不允許您建立空白字串或包含下列值的[命名空間](https://docs.cedarpolicy.com/schema/schema.html#namespace)：`aws`、 `amazon`或 `cedar`。

## 政策範本支援
<a name="differences-schema"></a>

Verified Permissions 和 Cedar 都只允許 `principal`和 範圍內的預留位置`resource`。不過，Verified Permissions 也要求 `principal`和 `resource` 都不受限制。

下列政策在 Cedar 中有效，但會遭到驗證許可拒絕，因為 `principal` 不受限制。

```
permit(principal, action == Action::"view", resource == ?resource);
```

下列兩個範例在 Cedar 和 Verified Permissions 中都有效，因為 `principal`和 `resource` 都有限制。

```
permit(principal == User::"alice", action == Action::"view", resource == ?resource);
```

```
permit(principal == ?principal, action == Action::"a", resource in ?resource);
```

## 結構描述支援
<a name="differences-templates"></a>

Verified Permissions 要求所有結構描述 JSON 金鑰名稱都是非空白字串。Cedar 允許在少數情況下使用空字串，例如屬性或命名空間。

## 動作群組定義
<a name="differences-action-groups"></a>

Cedar 授權方法要求根據政策評估授權請求時要考慮的實體清單。

您可以在結構描述中定義應用程式使用的動作和動作群組。不過，Cedar 不會將結構描述包含在評估請求中。相反地，Cedar 只會使用結構描述來驗證您提交的政策和政策範本。由於 Cedar 不會在評估請求期間參考結構描述，即使您已在結構描述中定義動作群組，您也必須將任何動作群組的清單包含在實體清單中，您必須傳遞給授權 API 操作。

Verified Permissions 會為您執行此操作。您在結構描述中定義的任何動作群組都會自動附加到您做為 參數傳遞至 `IsAuthorized`或 `IsAuthorizedWithToken`操作的實體清單中。

## 實體格式化
<a name="differences-entities"></a>

使用 `entityList` 參數的 Verified Permissions 中實體的 JSON 格式與 Cedar 不同，方式如下：
+ 在 Verified Permissions 中，JSON 物件必須將其所有鍵值對包裝在名為 的 JSON 物件中`Record`。
+ Verified Permissions 中的 JSON 清單必須包裝在金鑰名稱為 `Set`且值為 Cedar 原始 JSON 清單的 JSON 鍵/值對中。
+ 對於 `String`、 `Long`和 `Boolean`類型名稱，Cedar 中的每個鍵值對都會被 Verified Permissions 中的 JSON 物件取代。物件的名稱是原始金鑰名稱。在 JSON 物件中，有一個索引鍵/值對，其中索引鍵名稱是純量值的類型名稱 (`String`、 或 `Boolean`)`Long`，而值是來自 Cedar 實體的值。
+ Cedar 實體和 Verified Permissions 實體的語法格式在下列方面有所不同：    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/verifiedpermissions/latest/userguide/terminology-differences-avp-cedar.html)

**Example - 清單**  
下列範例顯示實體清單如何分別以 Cedar 和 Verified Permissions 表示。  

```
[
  {
    "number": 1
  },
  {
    "sentence": "Here is an example sentence"
  },
  {
    "Question": false
  }
]
```

```
{
  "Set": [
    {
      "Record": {
        "number": {
          "Long": 1
        }
      }
    },
    {
      "Record": {
        "sentence": {
          "String": "Here is an example sentence"
        }
      }
    },
    {
      "Record": {
        "question": {
          "Boolean": false
        }
      }
    }
  ]
}
```

**Example - 政策評估**  
下列範例顯示實體的格式如何分別評估 Cedar 和 Verified Permissions 中授權請求中的政策。  

```
[
    {
        "uid": {
            "type": "PhotoApp::User",
            "id": "alice"
        },
        "attrs": {
            "age": 25,
            "name": "alice",
            "userId": "123456789012"
        },
        "parents": [
            {
                "type": "PhotoApp::UserGroup",
                "id": "alice_friends"
            },
            {
                "type": "PhotoApp::UserGroup",
                "id": "AVTeam"
            }
        ]
    },
    {
        "uid": {
            "type": "PhotoApp::Photo",
            "id": "vacationPhoto.jpg"
        },
        "attrs": {
            "private": false,
            "account": {
                "__entity": {
                    "type": "PhotoApp::Account",
                    "id": "ahmad"
                }
            }
        },
        "parents": []
    },
    {
        "uid": {
            "type": "PhotoApp::UserGroup",
            "id": "alice_friends"
        },
        "attrs": {},
        "parents": []
    },
    {
        "uid": {
            "type": "PhotoApp::UserGroup",
            "id": "AVTeam"
        },
        "attrs": {},
        "parents": []
    }
]
```

```
[
    {
        "Identifier": {
            "EntityType": "PhotoApp::User",
            "EntityId": "alice"
        },
        "Attributes": {
            "age": {
                "Long": 25
            },
            "name": {
                "String": "alice"
            },
            "userId": {
                "String": "123456789012"
            }
        },
        "Parents": [
            {
                "EntityType": "PhotoApp::UserGroup",
                "EntityId": "alice_friends"
            },
            {
                "EntityType": "PhotoApp::UserGroup",
                "EntityId": "AVTeam"
            }
        ]
    },
    {
        "Identifier": {
            "EntityType": "PhotoApp::Photo",
            "EntityId": "vacationPhoto.jpg"
        },
        "Attributes": {
            "private": {
                "Boolean": false
            },
            "account": {
                "EntityIdentifier": {
                    "EntityType": "PhotoApp::Account",
                    "EntityId": "ahmad"
                }
            }
        },
        "Parents": []
    },
    {
        "Identifier": {
            "EntityType": "PhotoApp::UserGroup",
            "EntityId": "alice_friends"
        },
        "Parents": []
    },
    {
        "Identifier": {
            "EntityType": "PhotoApp::UserGroup",
            "EntityId": "AVTeam"
        },
        "Parents": []
    }
]
```

## 長度和大小限制
<a name="differences-length-limits"></a>

Verified Permissions 支援以政策存放區的形式儲存，以保留您的結構描述、政策和政策範本。該儲存體會導致 Verified Permissions 強加一些與 Cedar 無關的長度和大小限制。


| 物件 | 驗證許可限制 （以位元組為單位） | Cedar 限制 | 
| --- | --- | --- | 
| 政策大小1 | 10,000  | 無 | 
| 內嵌政策描述 | 150  | 不適用於 Cedar | 
| 政策範本大小 | 10,000  | 無 | 
| 結構描述大小 | 100,000  | 無 | 
| 實體類型 | 200  | 無 | 
| 政策 ID | 64  | 無 | 
| 政策範本 ID | 64  | 無 | 
| 實體 ID | 200  | 無 | 
| 政策存放區 ID | 64  | 不適用於 Cedar | 

1 根據政策存放區中建立之政策的主體、動作和資源的合併大小，驗證許可中每個政策存放區的政策有限制。與單一資源相關的所有政策總大小不得超過 200，000 個位元組。對於範本連結政策，政策範本的大小只會計算一次，加上用於執行個體化每個範本連結政策之每組參數的大小。