

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon 验证权限与 Cedar 政策语言之间的区别
<a name="terminology-differences-avp-cedar"></a>

Amazon Verified Permissions 使用 Cedar 策略语言引擎来执行其授权任务。但是，原生 Cedar 实现与 Verified Permissions 中的 Cedar 实现之间存在一些差异。本主题揭示了二者之间存在的差异。

## 命名空间定义
<a name="differences-namespaces"></a>

Verified Permissions 的 Cedar 实现与原生 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` 不受限制，会被 Verified Permissions 拒绝。

```
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 在评估请求期间不会引用架构，因此，即使在架构中定义了操作组，您也需要将所有操作组的列表包含在必须传递给授权 API 操作的实体列表中。

Verified Permissions 可以为您执行此操作。您在架构中定义的所有操作组都会自动附加到您传递至的实体列表中，作为 `IsAuthorized` 或 `IsAuthorizedWithToken` 操作的参数。

## 实体格式设置
<a name="differences-entities"></a>

使用`entityList`参数的 “已验证权限” 中实体的 JSON 格式与 Cedar 在以下方面有所不同：
+ 在 Verified Permissions 中，JSON 对象必须将其所有键值对包装在名为 `Record` 的 JSON 对象中。
+ Verified Permissions 中的 JSON 列表必须包装在 JSON 键值对中，其中，键名称为 `Set`，值为来自 Cedar 的原始 JSON 列表。
+ 对于 `String`、`Long` 和 `Boolean` 类型名称，在 Verified Permissions 中，Cedar 中的每个键值对都会被替换为 JSON 对象。该对象的名称是原始键名称。在 JSON 对象中，有一个键值对，其中键名称是标量值（`String`、`Long` 或 `Boolean`）的类型名称，值是来自 Cedar 实体的值。
+ Cedar 实体和 Verified Permissions 实体的语法格式存在以下不同：    
[\[See the AWS documentation website for more details\]](http://docs.amazonaws.cn/verifiedpermissions/latest/userguide/terminology-differences-avp-cedar.html)

**Example -清单**  
以下示例分别显示了如何在 Cedar 和已验证权限中表示实体列表。  

```
[
  {
    "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 无关的长度和大小限制。


| 对象 | Verified Permissions 限制（以字节为单位） | Cedar 极限 | 
| --- | --- | --- | 
| 策略大小¹ | 10000  | 无 | 
| 内联策略描述 | 150  | 不适用于 Cedar | 
| 策略模板大小 | 10000  | 无 | 
| 架构大小 | 100000  | 无 | 
| 实体类型 | 200  | 无 | 
| 策略 ID | 64  | 无 | 
| 策略模板 ID | 64  | 无 | 
| 实体 ID | 200  | 无 | 
| 策略存储 ID | 64  | 不适用于 Cedar | 

¹ Verified Permissions 中的每个策略存储都有策略限制，具体取决于策略存储中创建的策略的主体、操作和资源的总组合大小。与单个资源相关的所有策略的总大小不能超过 200000 字节。在计算模板链接策略的大小时，策略模板的大小仅计算一次，再加上用于实例化每个模板链接策略的每组参数的大小。