新增內容 - Amazon Verified Permissions

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

新增內容

內容是與政策決策相關的資訊,但不屬於委託人、動作或資源的身分。存取權杖宣告是內容。您可能只允許來自一組來源 IP 地址的動作,或只有在您的使用者已使用 MFA 登入時。您的應用程式可以存取此內容式工作階段資料,且必須填入授權請求。Verified Permissions 授權請求中的內容資料必須在 contextMap元素中格式化為 JSON。

說明此內容的範例來自範例政策存放區。若要遵循,請在您的測試環境中建立 DigitalPetStore 範例政策存放區。

下列內容物件會根據範例 DigitalPetStore 政策存放區,宣告應用程式的其中一個 Cedar 資料類型。

"context": { "contextMap": { "MfaAuthorized": { "boolean": true }, "AccountCodes": { "set": [ { "long": 111122223333 }, { "long": 444455556666 }, { "long": 123456789012 } ] }, "UserAgent": { "string": "My UserAgent 1.12" }, "RequestedOrderCount": { "long": 4 }, "NetworkInfo": { "record": { "IPAddress": { "string": "192.0.2.178" }, "Country": { "string": "United States of America" }, "SSL": { "boolean": true } } }, "approvedBy": { "entityIdentifier": { "entityId": "Bob", "entityType": "DigitalPetStore::User" } } } }
授權內容中的資料類型
Boolean

二進位truefalse值。在範例中, true的布林值MfaAuthenticated表示客戶在請求檢視其順序之前已執行多重要素驗證。

設定

內容元素的集合。集合成員可以是所有相同的類型,如本範例所示,也可以是不同類型的,包括巢狀集。在此範例中,客戶與 3 個不同的帳戶相關聯。

字串

字母、數字或符號的序列,以"字元括住。在範例中,UserAgent字串代表客戶用來請求檢視其順序的瀏覽器。

Long

整數。在此範例中, RequestedOrderCount 表示此請求是批次的一部分,該批次是由客戶要求檢視其四個過去的訂單所產生。

記錄

屬性的集合。您必須在請求內容中宣告這些屬性。具有結構描述的政策存放區必須包含此實體和結構描述中實體的屬性。在此範例中,NetworkInfo記錄包含使用者原始 IP、用戶端所決定的 IP 地理位置,以及傳輸中加密的相關資訊。

EntityIdentifier

對請求的 entities元素中宣告的實體和屬性的參考。在此範例中,使用者順序已由員工 核准Bob

若要在 DigitalPetStore 應用程式範例中測試此範例內容,您必須更新請求 entities、政策存放區結構描述,以及靜態政策,並描述 Customer Role - Get Order

修改 DigitalPetStore 以接受授權內容

DigitalPetStore 一開始不是非常複雜的政策存放區。它不包含任何預先設定的政策或內容屬性,以支援我們呈現的內容。若要使用此內容資訊評估範例授權請求,請對政策存放區和授權請求進行下列修改。如需使用存取權杖資訊做為內容的 內容範例,請參閱 映射存取權杖

Schema

將下列更新套用至您的政策存放區結構描述,以支援新的內容屬性。在 GetOrderactions更新,如下所示。

"GetOrder": { "memberOf": [], "appliesTo": { "resourceTypes": [ "Order" ], "context": { "type": "Record", "attributes": { "UserAgent": { "required": true, "type": "String" }, "approvedBy": { "name": "User", "required": true, "type": "Entity" }, "AccountCodes": { "type": "Set", "required": true, "element": { "type": "Long" } }, "RequestedOrderCount": { "type": "Long", "required": true }, "MfaAuthorized": { "type": "Boolean", "required": true } } }, "principalTypes": [ "User" ] } }

若要參考請求內容NetworkInfo中名為 的record資料類型,請在結構描述中建立 commonType 建構,如下所示。commonType 建構是一組共用屬性,您可以套用至不同的實體。

注意

Verified Permissions 視覺化結構描述編輯器目前不支援commonType建構。當您將它們新增至結構描述時,您無法再以視覺化模式檢視結構描述。

"commonTypes": { "NetworkInfo": { "attributes": { "IPAddress": { "type": "String", "required": true }, "SSL": { "required": true, "type": "Boolean" }, "Country": { "required": true, "type": "String" } }, "type": "Record" } }
Policy

下列政策會設定條件,這些條件必須由每個提供的內容元素滿足。它以現有的靜態政策為基礎,並描述客戶角色 - 取得訂單。此政策最初只需要提出請求的主體是資源的擁有者。

permit ( principal in DigitalPetStore::Role::"Customer", action in [DigitalPetStore::Action::"GetOrder"], resource ) when { principal == resource.owner && context.MfaAuthorized == true && context.UserAgent like "*My UserAgent*" && context.RequestedOrderCount <= 4 && context.AccountCodes.contains(111122223333) && context.NetworkInfo.Country like "*United States*" && context.NetworkInfo.SSL == true && context.NetworkInfo.IPAddress like "192.0.2.*" && context.approvedBy in DigitalPetStore::Role::"Employee" };

現在,我們要求擷取訂單的請求符合我們新增至請求的其他內容條件。

  1. 使用者必須已使用 MFA 登入。

  2. 使用者的 Web 瀏覽器User-Agent必須包含字串 My UserAgent

  3. 使用者必須已請求檢視 4 個或更少的訂單。

  4. 其中一個使用者的帳戶代碼必須是 111122223333

  5. 使用者的 IP 地址必須源自美國,且必須位於加密的工作階段,且其 IP 地址必須以 開頭192.0.2.

  6. 員工必須已核准其訂單。在授權請求的 entities元素中,我們將宣告具有 角色Bob的使用者Employee

Request body

使用適當的結構描述和政策設定政策存放區之後,您可以將此授權請求呈現給 Verified Permissions API 操作 IsAuthorized。請注意,客entities群包含 的定義Bob,即角色為 的使用者Employee

{ "principal": { "entityType": "DigitalPetStore::User", "entityId": "Alice" }, "action": { "actionType": "DigitalPetStore::Action", "actionId": "GetOrder" }, "resource": { "entityType": "DigitalPetStore::Order", "entityId": "1234" }, "context": { "contextMap": { "MfaAuthorized": { "boolean": true }, "UserAgent": { "string": "My UserAgent 1.12" }, "RequestedOrderCount":{ "long": 4 }, "AccountCodes": { "set": [ {"long": 111122223333}, {"long": 444455556666}, {"long": 123456789012} ] }, "NetworkInfo": { "record": { "IPAddress": {"string": "192.0.2.178"}, "Country": {"string": "United States of America"}, "SSL": {"boolean": true} } }, "approvedBy": { "entityIdentifier": { "entityId": "Bob", "entityType": "DigitalPetStore::User" } } } }, "entities": { "entityList": [ { "identifier": { "entityType": "DigitalPetStore::User", "entityId": "Alice" }, "attributes": { "memberId": { "string": "801b87f2-1a5c-40b3-b580-eacad506d4e6" } }, "parents": [ { "entityType": "DigitalPetStore::Role", "entityId": "Customer" } ] }, { "identifier": { "entityType": "DigitalPetStore::User", "entityId": "Bob" }, "attributes": { "memberId": { "string": "49d9b81e-735d-429c-989d-93bec0bcfd8b" } }, "parents": [ { "entityType": "DigitalPetStore::Role", "entityId": "Employee" } ] }, { "identifier": { "entityType": "DigitalPetStore::Order", "entityId": "1234" }, "attributes": { "owner": { "entityIdentifier": { "entityType": "DigitalPetStore::User", "entityId": "Alice" } } }, "parents": [] } ] }, "policyStoreId": "PSEXAMPLEabcdefg111111" }