"Applying Dynamically Generated Isolation Policies in SaaS Environments with the Data Solutions Framework"

tfc

Hatched by tfc

May 20, 2024

5 min read

0

"Applying Dynamically Generated Isolation Policies in SaaS Environments with the Data Solutions Framework"

In today's fast-paced world, Software-as-a-Service (SaaS) environments have become increasingly popular due to their agility and operational efficiency. However, ensuring the security and isolation of tenant data within a multi-tenant SaaS application can be a complex task. This is where dynamically generated isolation policies come into play, providing a solution to this challenge.

Before we delve into the details of applying dynamically generated policies in SaaS environments, let's first understand the key components of such an environment. Figure 1 illustrates a SaaS application consisting of a single serverless product microservice running in Lambda, which is accessed by multiple tenants. Although this example shows a single microservice, it's important to note that a real-world SaaS system would typically consist of a collection of microservices, all utilizing the same isolation mechanism applied to this one microservice.

The microservice in question is responsible for storing and retrieving tenant-scoped data from a database, specifically DynamoDB. When called, the service returns all products associated with a tenant. To achieve maximum agility and operational efficiency, the Lambda functions need to have an execution role that allows them to be used for all tenants. However, additional scoping is required to ensure that each function can only access a single tenant's data for each request. This is where dynamically generated isolation policies come into play.

Now let's walk through the tenant request flow to understand how dynamically generated isolation policies are applied in practice. The flow begins with a tenant sending a request to the Amazon API Gateway. Each request includes a token that contains the context of the tenant making the request. In the example solution, the token is a JSON Web Token (JWT) with custom claims for the tenant ID and tenant name.

Once an authorized request is processed and routed by the Amazon API Gateway, a call is made to the microservice (in this case, a Lambda function). Before the microservice can access the data, it needs to acquire credentials scoped to the tenant's context. This is where the Token Vending Machine (TVM) comes into play. The microservice creates a new instance of the TVM, which is included as a library in an AWS Lambda layer. The TVM is responsible for acquiring tenant-scoped credentials based on the request headers.

The TVM layer looks up dynamic policies in the Lambda layer. These policies are cached locally in the /tmp folder to enhance Lambda performance. If the policy templates are not found locally, they are downloaded from Amazon Simple Storage Service (S3) and saved to the local filesystem. This approach allows for easy management of policy updates and separation of policy updates from the code updates of the Lambda function.

Once the TVM has acquired the dynamic policies, it calls the Security Token Service (STS) to assume the predefined role and injects the dynamically generated policy as an inline policy. This ensures that the microservice has the necessary credentials scoped to the specific tenant's data. The TVM then returns the credentials provider, which can be used by the microservice to make calls to DynamoDB and retrieve the tenant's data.

With the scoped AWS credentials, the microservice can now access the DynamoDB table and retrieve all products owned by a single tenant. The DynamoDB client is created using the tenant-scoped credentials provided by the TVM layer. This ensures that any operation performed on the DynamoDB table is constrained to the tenant making the request.

Now that we have a clear understanding of how dynamically generated isolation policies are applied in a SaaS environment, let's explore some implementation guidance to enhance the performance and usability of this solution.

  1. Reduce request latency by caching TVM-generated tokens: To minimize the time spent on acquiring tenant-scoped credentials, you can cache the TVM-generated tokens for each tenant. These tokens can be used until they expire, controlled by the DurationSeconds parameter in the AssumeRole function of the TVM. This caching mechanism can significantly reduce request latency and improve overall performance.

  2. Use Git tag version numbers for policies: Instead of using commit hashes, consider using Git tag version numbers for the policies. This provides a more readable value that clearly indicates the current version of policies being used. In case of a rollback, you can easily change the version number to revert to a previous set of policies.

  3. Refine loading of policy templates: Currently, the solution loads the entire policies folder from S3. This can lead to increased loading time if there are many templates in the folder. To optimize loading time, consider loading only the necessary policy templates at a given moment. This can be achieved by implementing a mechanism that dynamically loads the required templates based on the specific request or use case.

In conclusion, applying dynamically generated isolation policies in SaaS environments is crucial for ensuring the security and isolation of tenant data. By utilizing the Token Vending Machine (TVM) and dynamic policies, developers can effectively scope access to tenant-specific data and enhance the agility and operational efficiency of their SaaS applications. By following the implementation guidance mentioned above, you can further optimize the performance and usability of this solution.

In summary, the combination of dynamically generated isolation policies and the Data Solutions Framework (DSF) offers a powerful approach to building secure and scalable data solutions on AWS. With DSF, data engineers can focus on their use cases and business logic, while leveraging pre-built building blocks that represent common abstractions in data solutions, such as a data lake. The Spark Data Lake example showcases the flexibility and customization capabilities of DSF, allowing developers to adapt the framework to their specific needs.

In conclusion, both the application of dynamically generated isolation policies in SaaS environments and the utilization of the Data Solutions Framework (DSF) offer robust solutions for building secure and scalable data solutions on AWS. By incorporating these approaches and following the implementation guidance provided, developers can enhance the security, efficiency, and customization of their SaaS applications and data solutions.

Sources

← Back to Library

Hatch New Ideas with Glasp AI 🐣

Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)

Start Hatching 🐣