TL;DR
This guide shows you how to restrict access for different tenants (customers) in your AWS environment using IAM policies, VPCs, and potentially other services like KMS. It focuses on practical steps to prevent data leakage and ensure each tenant only accesses their own resources.
1. Understand Your Tenant Model
Before you start, define how tenants are separated within your application. Common models include:
- Isolated Accounts: Each tenant gets a dedicated AWS account. This is the most secure but also the most complex to manage.
- Shared Account with Namespaces: Tenants share an AWS account, but their resources are logically separated using tags, IAM policies, and potentially VPCs.
This guide will focus on the Shared Account with Namespaces model as it’s more common for smaller deployments.
2. Tagging Strategy
Tags are crucial for identifying tenant resources. Establish a consistent tagging strategy:
- Tenant ID: A unique identifier for each tenant (e.g.,
tenant-id=12345). - Environment: (e.g.,
environment=production,environment=development) - Application: (e.g.,
application=my-app)
Apply these tags to *all* relevant resources – EC2 instances, S3 buckets, databases, etc.
3. IAM Policies for Tenant Access
Create IAM policies that grant tenants access only to their tagged resources. Use the aws:ResourceTag condition key:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:*" ], "Resource": "arn:aws:s3:::*", "Condition": { "StringEquals": { "aws:ResourceTag/tenant-id": "${tenantId}" } } } ] }
Replace ${tenantId} with the actual tenant ID. You’ll need to create a separate policy for each tenant or use a system to dynamically generate policies.
4. IAM Roles and Users
Create IAM roles for tenants, attaching the appropriate policies from Step 3. Assign users to these roles:
- Least Privilege: Grant only the minimum necessary permissions.
- Federation: Consider using a federation service (e.g., AWS SSO) to manage tenant user identities.
5. VPC Isolation
For increased isolation, use separate VPCs for each tenant:
- Network ACLs & Security Groups: Control network traffic within and between VPCs.
- Route Tables: Prevent direct communication between tenant networks unless explicitly allowed.
This is more complex to set up but provides a stronger security boundary.
6. Data Encryption (KMS)
If you’re storing sensitive data, use AWS Key Management Service (KMS):
- Customer Master Keys (CMKs): Create separate CMKs for each tenant to control access to encryption keys.
- IAM Policies: Restrict access to CMKs based on tenant ID using IAM policies similar to Step 3.
This ensures that even if a tenant gains unauthorized access to data storage, they cannot decrypt the data without permission.
7. Monitoring and Auditing
Implement robust monitoring and auditing:
- AWS CloudTrail: Log all API calls made within your AWS account.
- CloudWatch Alarms: Set alarms for suspicious activity (e.g., unauthorized access attempts).
- Regular Audits: Periodically review IAM policies, tags, and resource configurations to ensure they are still appropriate.
8. Automation
Automate tenant provisioning and de-provisioning:
- Infrastructure as Code (IaC): Use tools like Terraform or CloudFormation to define your infrastructure in code.
- CI/CD Pipelines: Automate the deployment of IAM policies, VPCs, and other resources.

