

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

# 每個租戶政策存放區
<a name="avp-design-per-tenant-store"></a>

Amazon Verified Permissions 中的每個租用戶政策存放區設計模型會將 SaaS 應用程式中的每個租用戶與其自己的政策存放區建立關聯。此模型類似於 SaaS [孤立隔離](https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/silo-isolation.html)模型。這兩種模型都需要建立租戶特定的基礎設施，並具有類似的優點和缺點。此方法的主要優點是基礎設施強制執行租用戶隔離、支援每個租用戶的唯一授權模型、消除[雜訊鄰近](https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/noisy-neighbor.html)問題，以及減少政策更新或部署失敗的影響範圍。此方法的缺點包括更複雜的租戶加入程序、部署和操作。如果解決方案具有每個租用戶的唯一政策，則建議使用每個租用戶政策存放區。

如果您的 SaaS 應用程式需要，每個租戶政策存放區模型可以提供高度孤立的租戶隔離方法。您也可以將此模型與[集區隔離](https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/pool-isolation.html)搭配使用，但您的 Verified Permissions 實作不會共用更廣泛的集區隔離模型的標準優點，例如簡化的管理和操作。

在各租用戶政策存放區中，租用戶隔離是透過在使用者註冊程序期間將租用戶的政策存放區識別符映射至使用者的 SaaS 身分來實現，如前所述。此方法會將租戶的政策存放區與使用者主體緊密關聯，並提供在整個 SaaS 解決方案 中共用映射的一致方式。您可以透過將 SaaS 應用程式維護為 IdP 的一部分或在 DynamoDB 等外部資料來源中提供映射。這也可確保委託人是租用戶的一部分，並使用租用戶的政策存放區。

此範例顯示包含 `tenant` `policyStoreId`和 使用者的 JWT 如何從 API 端點傳遞到 AWS Lambda 授權方中的政策評估點，該授權方會將請求路由到正確的政策存放區。

![Amazon Verified Permissions 中的每個租戶政策存放區模型](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/saas-multitenant-api-access-authorization/images/avp-per-tenant.png)


下列範例政策說明每個租用戶的政策存放區設計範例。使用者`Alice`屬於 `TenantA.` policyStoreId `store-a`也會對應至 的租戶身分，`Alice,`並強制使用正確的政策存放區。這可確保`TenantA`使用 的政策。

**注意**  
每個租用戶的政策存放區模型會隔離租用戶的政策。授權會強制執行允許使用者對其資料執行的動作。使用這個模型的任何假設性應用程式中涉及的資源應使用其他隔離機制進行隔離，如 [AWS Well-Architected Framework SaaS Lens 文件](https://docs.aws.amazon.com/wellarchitected/latest/saas-lens/core-isolation-concepts.html)所定義。

在此政策中， `Alice`具有檢視所有 資源資料的許可。

```
permit (
    principal == MultiTenantApp::User::"Alice",
    action == MultiTenantApp::Action::"viewData",
    resource
);
```

若要提出授權請求並使用 Verified Permissions 政策開始評估，您需要提供對應至對應至租用戶的唯一 ID 的政策存放區 ID`store-a`。

```
{
   "policyStoreId":"store-a",
   "principal":{
      "entityType":"MultiTenantApp::User",
      "entityId":"Alice"
   },
   "action":{
      "actionType":"MultiTenantApp::Action",
      "actionId":"viewData"
   },
   "resource":{
      "entityType":"MultiTenantApp::Data",
      "entityId":"my_example_data"
   },
   "entities":{
      "entityList":[
         [
            {
               "identifier":{
                  "entityType":"MultiTenantApp::User",
                  "entityId":"Alice"
               },
               "attributes":{},
               "parents":[]
            },
            {
               "identifier":{
                  "entityType":"MultiTenantApp::Data",
                  "entityId":"my_example_data"
               },
               "attributes":{},
               "parents":[]
            }
         ]
      ]
   }
}
```

使用者`Bob`屬於租戶 B，且 policyStoreId `store-b`也會對應至 的租戶身分`Bob`，強制使用正確的政策存放區。這可確保使用租用戶 B 的政策。

在此政策中， `Bob`具有自訂所有資源資料的許可。在此範例中， `customizeData`可能是僅適用於租用戶 B 的動作，因此政策對於租用戶 B 是唯一的。每個租用戶的政策存放區模型本質上支援每個租用戶的自訂政策。

```
permit (
    principal == MultiTenantApp::User::"Bob",
    action == MultiTenantApp::Action::"customizeData",
    resource
);
```

若要提出授權請求並使用 Verified Permissions 政策開始評估，您需要提供對應至對應至租用戶的唯一 ID 的政策存放區 ID`store-b`。

```
{
   "policyStoreId":"store-b",
   "principal":{
      "entityType":"MultiTenantApp::User",
      "entityId":"Bob"
   },
   "action":{
      "actionType":"MultiTenantApp::Action",
      "actionId":"customizeData"
   },
   "resource":{
      "entityType":"MultiTenantApp::Data",
      "entityId":"my_example_data"
   },
   "entities":{
      "entityList":[
         [
            {
               "identifier":{
                  "entityType":"MultiTenantApp::User",
                  "entityId":"Bob"
               },
               "attributes":{},
               "parents":[]
            },
            {
               "identifier":{
                  "entityType":"MultiTenantApp::Data",
                  "entityId":"my_example_data"
               },
               "attributes":{},
               "parents":[]
            }
         ]
      ]
   }
}
```

使用 Verified Permissions，可以但不需要將 IdP 與政策存放區整合。此整合可讓 政策明確參考身分存放區中的委託人做為政策的委託人。如需如何將 與 Amazon Cognito 整合為 Verified Permissions IdP 的詳細資訊，請參閱 [Verified Permissions 文件](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)和 [Amazon Cognito 文件](https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-authorization-with-avp.html)。

當您將政策存放區與 IdP 整合時，每個政策存放區只能使用一個[身分來源](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。例如，如果您選擇將 Verified Permissions 與 Amazon Cognito 整合，則必須鏡像用於租戶隔離 Verified Permissions 政策存放區和 Amazon Cognito 使用者集區的策略。政策存放區和使用者集區也必須位於相同的 中 AWS 帳戶。

![將已驗證許可與每個租用戶的設計模型中的 Amazon Cognito 整合](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/saas-multitenant-api-access-authorization/images/cognito-per-tenant.png)


在操作層級上，每個租用戶政策存放區具有稽核優勢，因為您可以為每個租用戶單獨查詢 [中的記錄活動](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/monitoring-overview.html)AWS CloudTrail 。不過，仍建議您將每個租用戶維度上的其他自訂指標記錄到 Amazon CloudWatch。

每個租用戶的政策存放區方法也需要密切注意兩個[已驗證許可配額](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/quotas.html)，以確保它們不會干擾 SaaS 解決方案的操作。這些配額是*每個帳戶每個區域的政策存放*區，以及*每個帳戶每個區域的每秒 IsAuthorized 請求*。您可以為這兩個配額請求增加。

如需如何實作每個租用戶政策存放區模型的更詳細範例，請參閱 AWS 部落格文章[使用 Amazon Verified Permissions 搭配每個租用戶政策存放區的 SaaS 存取控制](https://aws.amazon.com/blogs/security/saas-access-control-using-amazon-verified-permissions-with-a-per-tenant-policy-store/)。