[ad_1]
Entry management is crucial for multi-tenant software program as a service (SaaS) purposes. SaaS builders should handle permissions, fine-grained authorization, and isolation.
On this submit, we exhibit how you should use Amazon Verified Permissions for entry management in a multi-tenant doc administration SaaS utility utilizing a per-tenant coverage retailer strategy. We additionally describe learn how to implement the tenant boundary.
We often see the next entry management wants in multi-tenant SaaS purposes:
Utility builders have to outline insurance policies that apply throughout all tenants.
Tenant customers want to manage who can entry their assets.
Tenant admins have to handle all assets for a tenant.
Moreover, impartial software program distributors (ISVs) implement tenant isolation to stop one tenant from accessing the assets of one other tenant. Implementing tenant boundaries is crucial for SaaS companies and is without doubt one of the foundational matters for SaaS suppliers.
Verified Permissions is a scalable, fine-grained permissions administration and authorization service that helps you construct and modernize purposes with out having to implement authorization logic throughout the code of your utility.
Verified Permissions makes use of the Cedar language to outline insurance policies. A Cedar coverage is an announcement that declares which principals are explicitly permitted, or explicitly forbidden, to carry out an motion on a useful resource. The gathering of insurance policies defines the authorization guidelines in your utility. Verified Permissions shops the insurance policies in a coverage retailer. A coverage retailer is a container for insurance policies and templates. You’ll be able to study extra about Cedar insurance policies from the Utilizing Open Supply Cedar to Write and Implement Customized Authorization Insurance policies weblog submit.
Earlier than Verified Permissions, you needed to implement authorization logic throughout the code of your utility. Now, we’ll present you the way Verified Permissions helps take away this undifferentiated heavy lifting in an instance utility.
Multi-tenant doc administration SaaS utility
The appliance permits so as to add, share, entry and handle paperwork. It requires the next entry controls:
Utility builders who can outline insurance policies that apply throughout all tenants.
Tenant customers who can management who can entry their paperwork.
Tenant admins who can handle all paperwork for a tenant.
Let’s begin by describing the appliance structure after which dive deeper into the design particulars.
Utility structure overview
There are two approaches to multi-tenant design in Verified Permissions: a single shared coverage retailer and a per-tenant coverage retailer. You’ll be able to study concerning the concerns, trade-offs and steering for these approaches within the Verified Permissions person information.
For the instance doc administration SaaS utility, we determined to make use of the per-tenant coverage retailer strategy for the next causes:
Low-effort tenant insurance policies isolation
The power to customise templates and schema per tenant
Low-effort tenant off-boarding
Per-tenant coverage retailer useful resource quotas
We determined to just accept the next trade-offs:
Excessive effort to implement international insurance policies administration (as a result of the appliance use case doesn’t require frequent modifications to those insurance policies)
Medium effort to implement the authorization stream (as a result of we determined that on this context, the above causes outweigh implementing a mapping from tenant ID to coverage retailer ID)
Determine 1 exhibits the doc administration SaaS utility structure. For simplicity, we omitted the frontend and centered on the backend.
![Figure 1: Document management SaaS application architecture](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img1-3.png)
Determine 1: Doc administration SaaS utility structure
A tenant person indicators in to an identification supplier resembling Amazon Cognito. They get a JSON Internet Token (JWT), which they use for API requests. The JWT comprises claims such because the user_id, which identifies the tenant person, and the tenant_id, which defines which tenant the person belongs to.
The tenant person makes API requests with the JWT to the appliance.
Amazon API Gateway verifies the validity of the JWT with the identification supplier.
If the JWT is legitimate, API Gateway forwards the request to the compute supplier, on this case an AWS Lambda perform, for it to run the enterprise logic.
The Lambda perform assumes an AWS Id and Entry Administration (IAM) function with an IAM coverage that permits entry to the Amazon DynamoDB desk that gives tenant-to-policy-store mapping. The IAM coverage scopes down entry such that the Lambda perform can solely entry information for the present tenant_id.
The Lambda perform appears to be like up the Verified Permissions policy_store_id for the present request. To do that, it extracts the tenant_id from the JWT. The perform then retrieves the policy_store_id from the tenant-to-policy-store mapping desk.
The Lambda perform assumes one other IAM function with an IAM coverage that permits entry to the Verified Permissions coverage retailer, the doc metadata desk, and the doc retailer. The IAM coverage makes use of tenant_id and policy_store_id to scope down entry.
The Lambda perform will get or shops paperwork metadata in a DynamoDB desk. The perform makes use of the metadata for Verified Permissions authorization requests.
Utilizing the knowledge from steps 5 and 6, the Lambda perform calls Verified Permissions to make an authorization resolution or create Cedar insurance policies.
If licensed, the appliance can then entry or retailer a doc.
Utility structure deep dive
Now that you understand the structure for the use instances, let’s evaluation them in additional element and work backwards from the person expertise to the associated a part of the appliance structure. The structure focuses on permissions administration. Accessing and storing the precise doc is out of scope.
Outline insurance policies that apply throughout all tenants
The appliance developer should outline international insurance policies that embrace a primary set of entry permissions for all tenants. We use Cedar insurance policies to implement these permissions.
As a result of we’re utilizing a per-tenant coverage retailer strategy, the tenant onboarding course of ought to create these insurance policies for every new tenant. At present, to replace insurance policies, the deployment pipeline ought to apply modifications to all coverage shops.
The “Add a doc” and “Handle all of the paperwork for a tenant” sections that comply with embrace examples of world insurance policies.
Ensure that a tenant can’t edit the insurance policies of one other tenant
The appliance makes use of IAM to isolate the assets of 1 tenant from one other. As a result of we’re utilizing a per-tenant coverage retailer strategy we will use IAM to isolate one tenant coverage retailer from one other.
Structure
![Figure 2: Tenant isolation](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img2-1.png)
Determine 2: Tenant isolation
A tenant person calls an API endpoint utilizing a legitimate JWT.
The Lambda perform makes use of AWS Safety Token Service (AWS STS) to imagine an IAM function with an IAM coverage that permits entry to the tenant-to-policy-store mapping DynamoDB desk. The IAM coverage solely permits entry to the desk and the entries that belong to the requesting tenant. When the perform assumes the function, it makes use of tenant_id to scope entry to the gadgets whose partition key matches the tenant_id. See the Learn how to implement SaaS tenant isolation with ABAC and AWS IAM weblog submit for examples of such insurance policies.
The Lambda perform makes use of the person’s tenant_id to get the Verified Permissions policy_store_id.
The Lambda perform makes use of the identical mechanism as in step 2 to imagine a special IAM function utilizing tenant_id and policy_store_id which solely permits entry to the tenant coverage retailer.
The Lambda perform accesses the tenant coverage retailer.
Add a doc
When a person first accesses the appliance, they don’t personal any paperwork. So as to add a doc, the frontend calls the POST /paperwork endpoint and provides a document_name within the request’s physique.
Cedar coverage
We want a worldwide coverage that permits each tenant person so as to add a brand new doc. The tenant onboarding course of creates this coverage within the tenant’s coverage retailer.
This coverage permits any principal so as to add a doc. As a result of we’re utilizing a per-tenant coverage retailer strategy, there’s no have to scope the principal to a tenant.
Structure
![Figure 3: Adding a document](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img3-1.png)
Determine 3: Including a doc
A tenant person calls the POST /paperwork endpoint so as to add a doc.
The Lambda perform makes use of the person’s tenant_id to get the Verified Permissions policy_store_id.
The Lambda perform calls the Verified Permissions coverage retailer to examine if the tenant person is permitted so as to add a doc.
After profitable authorization, the Lambda perform provides a brand new doc to the paperwork metadata database and uploads the doc to the paperwork storage.
The database construction is described within the following desk:
tenant_id (Partition key): String
document_id (Type key): String
document_name: String
document_owner: String
<TENANT_ID>
<DOCUMENT_ID>
<DOCUMENT_NAME>
<USER_ID>
tenant_id: The tenant_id from the JWT claims.
document_id: A random identifier for the doc, created by the appliance.
document_name: The title of the doc equipped with the API request.
document_owner: The person who created the doc. The worth is the user_id from the JWT claims.
Share a doc with one other person of a tenant
After a tenant person has created a number of paperwork, they may wish to share them with different customers of the identical tenant. To share a doc, the frontend calls the POST /shares endpoint and gives the document_id of the doc the person needs to share and the user_id of the receiving person.
Cedar coverage
We want a worldwide doc proprietor coverage that permits the doc proprietor to handle the doc, together with sharing. The tenant onboarding course of creates this coverage within the tenant’s coverage retailer.
The coverage permits principals to carry out actions on accessible assets (the doc) when the principal is the doc proprietor. This coverage permits the shareDocument motion, which we describe subsequent, to share a doc.
We additionally want a share coverage that permits the receiving person to entry the doc. The appliance creates these insurance policies for every profitable share motion. We suggest that you simply use coverage templates to outline the share coverage. Coverage templates permit a coverage to be outlined as soon as after which hooked up to a number of principals and assets. Insurance policies that use a coverage template are known as template-linked insurance policies. Updates to the coverage template are mirrored throughout the principals and assets that use the template. The tenant onboarding course of creates the share coverage template within the tenant’s coverage retailer.
We outline the share coverage template as follows:
The next is an instance of a template-linked coverage utilizing the share coverage template:
The coverage consists of the user_id of the receiving person (principal) and the document_id of the doc (useful resource).
Structure
![Figure 4: Sharing a document](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img4-1.png)
Determine 4: Sharing a doc
A tenant person calls the POST /shares endpoint to share a doc.
The Lambda perform makes use of the person’s tenant_id to get the Verified Permissions policy_store_id and coverage template IDs for every motion from the DynamoDB desk that shops the tenant to coverage retailer mapping. On this case the perform wants to make use of the share_policy_template_id.
The perform queries the paperwork metadata DynamoDB desk to retrieve the document_owner attribute for the doc the person needs to share.
The Lambda perform calls Verified Permissions to examine if the person is permitted to share the doc. The request context makes use of the user_id from the JWT claims because the principal, shareDocument because the motion, and the document_id because the useful resource. The doc entity consists of the document_owner attribute, which got here from the paperwork metadata DynamoDB desk.
If the person is permitted to share the useful resource, the perform creates a brand new template-linked share coverage within the tenant’s coverage retailer. This coverage consists of the user_id of the receiving person because the principal and the document_id because the useful resource.
Entry a shared doc
After a doc has been shared, the receiving person needs to entry the doc. To entry the doc, the frontend calls the GET /paperwork endpoint and gives the document_id of the doc the person needs to entry.
Cedar coverage
As proven within the earlier part, throughout the sharing course of, the appliance creates a template-linked share coverage that permits the receiving person to entry the doc. Verified Permissions evaluates this coverage when the person tries to entry the doc.
Structure
![Figure 5: Accessing a shared document](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img5.png)
Determine 5: Accessing a shared doc
A tenant person calls the GET /paperwork endpoint to entry the doc.
The Lambda perform makes use of the person’s tenant_id to get the Verified Permissions policy_store_id.
The Lambda perform calls Verified Permissions to examine if the person is permitted to entry the doc. The request context makes use of the user_id from the JWT claims because the principal, accessDocument because the motion, and the document_id because the useful resource.
Handle all of the paperwork for a tenant
When a buyer indicators up for a SaaS utility, the appliance creates the tenant admin person. The tenant admin will need to have permissions to carry out all actions on all paperwork for the tenant.
Cedar coverage
We want a worldwide coverage that permits tenant admins to handle all paperwork. The tenant onboarding course of creates this coverage within the tenant’s coverage retailer.
This coverage permits each member of the <admin_group_id> group to carry out any motion on any doc.
Structure
![Figure 6: Managing documents](https://d2908q01vomqb2.cloudfront.net/22d200f8670dbdb3e253a90eee5098477c95c23d/2024/02/07/img6.png)
Determine 6: Managing paperwork
A tenant admin calls the POST /paperwork endpoint to handle a doc.
The Lambda perform makes use of the person’s tenant_id to get the Verified Permissions policy_store_id.
The Lambda perform calls Verified Permissions to examine if the person is permitted to handle the doc.
Conclusion
On this weblog submit, we confirmed you the way Amazon Verified Permissions helps to implement fine-grained authorization choices in a multi-tenant SaaS utility. You noticed learn how to apply the per-tenant coverage retailer strategy to the appliance structure. See the Verified Permissions person information for a way to decide on between utilizing a per-tenant coverage retailer or one shared coverage retailer. To study extra, go to the Amazon Verified Permissions documentation and workshop.
When you’ve got suggestions about this submit, submit feedback within the Feedback part beneath. When you’ve got questions on this submit, begin a brand new thread on the Amazon Verified Permissions re:Put up or contact AWS Assist.
[ad_2]
Source link