[アップデート] Amazon Verified Permissions の API でエンティティとコンテキストに Cedar JSON をそのまま渡せるようになりました
いわさです。
Amazon Verified Permissions は Cedar 言語を使ったポリシー評価を行います。
従来 Amazon Verified Permissions とネイティブの Cedar の間でいくつか Cedar 実装に関する差分があり、ユーザーはそれを意識して使う必要がありました。
先日のアップデートで Verified Permissions の API でコンテキストとエンティティに対して Cedar の JSON 形式(以降は公式ドキュメントに倣って Cedar JSON と記載)をそのままパラメータとして受けることができるようになりました。
変更された要点だけ先にまとめておくと、Amazon Verified Permissions のBatchIsAuthorized
、BatchIsAuthorizedWithToken
、IsAuthorized
、IsAuthorizedWithToken
でエンティティやコンテキストを指定する時に、従来の形式ではなくcedarJson
というパラメータを指定できるようになりました。
以下はIsAuthorized
の入力形式です。
{
"policyStoreId": "",
"principal": { ... },
"action": { ... },
"resource": { ... },
"context": {
"contextMap": {
...
},
"cedarJson": ""
},
"entities": {
"entityList": [
...
],
"cedarJson": ""
}
}
メリットとしては、Cedar を使って独自にアプリケーションと Amazon Verified Permissions を組み込んでいるアプリケーションの間で差が少なくなったので、従来よりも少し移行しやすくなった感じでしょうか。
Cedar JSON 形式
通常 Cedar の場合は次のようにuid
、parents
、attrs
、tags
などで構成された JSON 配列からEntities::from_json_value()
やPContext::from_json_str()
を呼び出して使用します。
しかし、Amazon Verified Permissions がサポートするエンティティ形式と Cedar のエンティティ形式に差があるため、例えば独自で Cedar を実装して認可処理を実装しているところから Verified Permissions に移行しようとすると、その差を吸収(変換など)する必要がありました。
例えば上記ドキュメントによると Cedar の形式と Verifed 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": []
}
]
結構構造が違うので、Cedar を独自で組み込んでいるアプリケーションが Verified Permissions に移行しようとする場合(あるいはその逆)にこの部分は変更対応が必要でした。
Cedar JSON 形式で評価させてみる
前述のとおりコンテキストとエンティティで Cedar JSON 形式が使えるようになったので、従来のアプリケーションで使っていたエンティティ形式をそのまま Verified Permissions でも使うことが出来ます。
今回はサンプルポリシーストアと公式ドキュメントのポリシー例を参考に次のようなポリシーを作って試してみます。
まずは従来の形式です。
entities
パラメータにはentityList
を設定しています。
% cat hoge.json
{
"policyStoreId": "XBYUkBDfYb4myyisscdwiD",
"principal": {
"entityType": "PhotoFlash::User",
"entityId": "Alice"
},
"action": {
"actionType": "PhotoFlash::Action",
"actionId": "ViewPhoto"
},
"resource": {
"entityType": "PhotoFlash::Photo",
"entityId": "VacationPhoto94.jpg"
},
"entities": {
"entityList": [
{
"identifier": {
"entityType": "PhotoFlash::User",
"entityId": "Alice"
},
"attributes": {
"Account": {
"entityIdentifier": {
"entityType": "PhotoFlash::Account",
"entityId": "11111"
}
}
},
"parents": []
},
{
"identifier": {
"entityType": "PhotoFlash::Photo",
"entityId": "VacationPhoto94.jpg"
},
"attributes": {
"IsPrivate": {
"boolean": false
}
},
"parents": []
}
]
}
}
% aws-v1 verifiedpermissions is-authorized --cli-input-json file://hoge.json --profile hoge
{
"decision": "ALLOW",
"determiningPolicies": [
{
"policyId": "LE29EVkmngawMbG96MjJJt"
}
],
"errors": []
}
許可されましたね。
では続いて Cedar JSON 形式で試してみます。
まず上記エンティティを Cedar JSON 形式で表現すると以下のようになります。
[
{
"uid": {
"type": "PhotoFlash::User",
"id": "Alice"
},
"attrs": {
"Account": {
"__entity": {
"type": "PhotoFlash::Account",
"id": "11111"
}
}
},
"parents": []
},
{
"uid": {
"type": "PhotoFlash::Photo",
"id": "VacationPhoto94.jpg"
},
"attrs": {
"IsPrivate": false
},
"parents": []
}
]
こちらを文字列形式に変換した上で、entities
のcedarJson
に設定します。
それ以外のパラメータは同じですが、注意点としてentityList
と併用して使用することは出来ません。
% cat hoge2.json
{
"policyStoreId": "XBYUkBDfYb4myyisscdwiD",
"principal": {
"entityType": "PhotoFlash::User",
"entityId": "Alice"
},
"action": {
"actionType": "PhotoFlash::Action",
"actionId": "ViewPhoto"
},
"resource": {
"entityType": "PhotoFlash::Photo",
"entityId": "VacationPhoto94.jpg"
},
"entities": {
"cedarJson": "[{\"uid\":{\"type\":\"PhotoFlash::User\",\"id\":\"Alice\"},\"attrs\":{\"Account\":{\"__entity\":{\"type\":\"PhotoFlash::Account\",\"id\":\"11111\"}}},\"parents\":[]},{\"uid\":{\"type\":\"PhotoFlash::Photo\",\"id\":\"VacationPhoto94.jpg\"},\"attrs\":{\"IsPrivate\":false},\"parents\":[]}]"
}
}
% aws-v1 verifiedpermissions is-authorized --cli-input-json file://hoge2.json --profile hoge
{
"decision": "ALLOW",
"determiningPolicies": [
{
"policyId": "LE29EVkmngawMbG96MjJJt"
}
],
"errors": []
}
こちらも無事許可されました。
今回エンティティでだけ試しましたが、コンテキストについてもcedarJson
プロパティが追加されており、こちらも使えるようになっています。
さいごに
本日は Amazon Verified Permissions の API でエンティティとコンテキストに Cedar JSON をそのまま渡せるようになっていたので使ってみました。
Verified Permissions 使わずに Cedar だけ使って認可制御しているアプリケーションがどの程度あるのか個人的には気になっています。
Cedar はもともと Rust で提供されはじめていましたが、以下のリポジトリを眺めてみると Java や Go でも提供されているようです。
Cedar から使い始めつつ、Verified Permissions に移行しやすくさせるためのアップデートというところでしょうか。