Applying Dynamically Generated Isolation Policies in SaaS Environments and the Anemic Domain Model

tfc

Hatched by tfc

Jan 23, 2024

5 min read

0

Applying Dynamically Generated Isolation Policies in SaaS Environments and the Anemic Domain Model

Introduction:
In today's digital landscape, SaaS environments play a crucial role in enabling businesses to provide scalable and efficient services to their customers. However, ensuring data security and access control in these environments can be a complex task. In this article, we will explore the concept of dynamically generated isolation policies in SaaS environments and discuss how they can be applied effectively. Additionally, we will also touch upon the issue of anemic domain models and its impact on software development.

Understanding the SaaS Environment:
Before delving into the specifics of dynamically generated isolation policies, it is essential to understand the key components of a SaaS environment. In a typical setup, a SaaS application consists of multiple microservices that are accessed by various tenants. These microservices, such as serverless products running in Lambda, interact with a shared database, like DynamoDB, to retrieve tenant-specific data. To ensure operational efficiency, it is desirable to run Lambda functions with an execution role that allows them to be used for all tenants. However, this broader scoping necessitates additional measures to enforce data access restrictions for each tenant.

Implementing Dynamically Generated Isolation Policies:
To address the challenge of data access control in a multi-tenant SaaS environment, dynamically generated isolation policies can be utilized. Let's walk through the process flow of a tenant request to understand how these policies are applied.

Step 1: Tenant Sends Request:
A tenant initiates a request to the Amazon API Gateway, including a token that contains the tenant's context. This token typically takes the form of a JSON Web Token (JWT) with custom claims like tenant_id and tenant_name.

Step 2: Microservice Processes Request:
After authentication and routing by the Amazon API Gateway, the request is forwarded to the microservice, such as a Lambda function. Before accessing the shared data in DynamoDB, the microservice needs to acquire tenant-scoped credentials. This is where the Token Vending Machine (TVM) comes into play. The microservice creates an instance of the TVM, which is included as a library in an AWS Lambda layer, and calls it to obtain tenant-specific credentials.

Step 3: TVM Lookup of Dynamic Policies:
In the TVM layer, the dynamically generated isolation policies are looked up. These policies are cached locally in the /tmp folder for improved performance. If the policies are not found locally, they are downloaded from Amazon S3 and saved to the local file system. The version of the policies is controlled by an environment variable, facilitating easy policy updates.

Step 4: TVM Calls STS:
The TVM layer injects the tenant context into the policy templates, assembles them, and makes a call to STS (Security Token Service). The dynamically generated policy is passed as an inline policy when assuming the predefined role. The TVM then returns the scoped credentials, which can be used by the microservice to access tenant-specific data in DynamoDB.

Step 5: Access Data with Limited Scope:
Armed with the scoped AWS credentials, the microservice can now make calls to DynamoDB, constrained to the requesting tenant's data. The DynamoDB client is created using the tenant-scoped credentials obtained from the TVM layer. This ensures that any operation performed on the DynamoDB table is limited to the tenant making the request.

Implementation Guidance:
To effectively implement the TVM and dynamic policies in your SaaS architecture, consider the following implementation strategies:

  1. Reduce Request Latency through Token Caching:
    To minimize request latency, consider caching TVM-generated tokens for each tenant to their respective resources. Cached tokens can be used until they expire, and the expiration time can be controlled using the DurationSeconds parameter in the AssumeRole function of the TVM.

  2. Use Git Tag Version Numbers for Policies:
    Instead of relying on commit hashes, use Git tag version numbers for policies. This approach provides a more readable value that indicates the current policies version. When rolling back, simply change the version number to the desired lower value.

  3. Optimize Loading of Policy Templates:
    Currently, the solution loads the entire policies folder from Amazon S3. This can lead to longer loading times, especially when there are numerous templates in the folder. Consider refining the loading process to only load the necessary policy templates at a given moment, improving overall performance.

Addressing the Anemic Domain Model:
In addition to discussing dynamically generated isolation policies, it is important to address the issue of anemic domain models. An anemic domain model refers to a model that appears to be comprehensive on the surface, with objects and relationships mirroring the domain space. However, these models lack behavior and often come with design rules that prohibit the inclusion of domain logic within the domain objects themselves.

Instead, anemic domain models rely on service objects to handle all the domain logic, leaving the domain objects as mere data containers. This approach can result in a bloated service layer and limited expressiveness of the domain objects.

Conclusion:
In conclusion, applying dynamically generated isolation policies in SaaS environments is crucial for ensuring data security and access control. By leveraging the Token Vending Machine (TVM) and dynamic policy templates, developers can enforce tenant-specific data access restrictions effectively. Additionally, addressing the issue of anemic domain models is essential for developing robust and maintainable software.

Actionable Advice:

  1. Implement token caching to reduce request latency and optimize performance in your SaaS environment.
  2. Utilize Git tag version numbers instead of commit hashes for policies to simplify rollback processes.
  3. Refine the loading of policy templates to only load necessary templates at a given moment, improving loading times and overall performance.

By incorporating these actionable advice and understanding the concepts discussed in this article, you can enhance the security, scalability, and efficiency of your SaaS environment while ensuring the integrity of your domain models.

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 🐣