In modern cloud architectures, organizations frequently separate environments into distinct accounts for isolation, cost allocation, and security governance. A common pattern involves a central management account (Management Account) deploying resources in multiple workload accounts (e.g., dev-prod, finance-apps). The challenge arises when these workloads require cross-account access to share data or trigger events. Overly permissive policies granting broad administrative rights across accounts are a primary vector for lateral movement during a breach. This article details a practical drill using AWS IAM Access Analyzer to generate and validate complex least-privilege policies, ensuring that cross-account permissions grant only the specific resources and actions required.
Understanding the Cross-Account Threat Landscape
Before writing code or configuring policies, it is essential to understand the risk profile of cross-account access. When Account A allows Account B to access its S3 buckets or EC2 instances, the attack surface expands significantly. If Account B is compromised, an attacker can potentially pivot into Account A’s infrastructure if the permissions are too broad.
IAM Access Analyzer identifies resources that have external shared access (cross-account). It analyzes your permission policies and determines which resources are accessible from outside your organization’s trusted boundary. By leveraging this tool, you can move from a “trust but verify” mindset to a “verify then restrict” approach. The goal of this drill is not just to find open doors, but to reconstruct the exact key needed to open them—no more, no less.
Lab Setup and Prerequisites
To follow this guide, you will need access to an AWS environment with two distinct accounts:
1. Management Account (Account A): Contains the sensitive resources (e.g., a secure S3 bucket).
2. Workload Account (Account B): The account attempting to access those resources.
Prerequisites:
* Two AWS accounts configured with IAM Access Analyzer enabled in both regions where resources reside.
* An Identity Provider (IdP) like Okta, Azure AD, or Google Workspace connected to AWS SSO for identity federation.
* Basic knowledge of the AWS Console and CLI.
Safety Note: This drill assumes a safe lab environment. Never run these commands against production data without prior approval from your security governance team. Ensure you have backup snapshots of your current policies before making changes.
Step 1: Analyze External Access with IAM Access Analyzer
The first step is to identify what is currently accessible. Log in to the Management Account console and navigate to the IAM Access Analyzer dashboard.
- Select the region containing your resources.
- Click on “External access” under the “Analyze external access” section.
- Review the list of resources. You will see entries indicating which AWS resources are shared with other accounts or federated identities.
Illustrative Output:
Resource: arn:aws:s3:::secure-financial-data/dev
Shared With: Account B (Principal: arn:aws:iam::ACCOUNTB-ID:user/DevOpsLead)
Action: s3:GetObject, s3:ListBucket
Condition: None
In this scenario, the policy grants s3:GetObject and s3:ListBucket. If the business requirement is strictly to read logs for debugging, granting s3:PutObject or s3:DeleteObject would be a violation of the least-privilege principle. The analyzer highlights these shared resources, allowing you to pinpoint exactly where permissions leak.
Step 2: Generate and Refine Least-Privilege Policies
Once identified, do not manually rewrite policies from scratch, as this often leads to syntax errors or missed conditions. Instead, use the policy simulation features within IAM Access Analyzer or AWS Policy Simulator.
- Select the specific resource (e.g., the S3 bucket).
- Choose “Generate least privilege policy” (if available in your region/version) or manually draft a new statement based on the analyzer’s findings.
- Apply strict conditions where possible. For example, restrict access to specific IP ranges or require MFA for the principal user.
Example Policy Statement:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCrossAccountReadAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNTB-ID:user/DevOpsLead"
},
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::secure-financial-data/dev/*",
"arn:aws:s3:::secure-financial-data/dev"
],
"Condition": {
"StringEquals": {
"aws:PrincipalTag/Environment": "production"
}
}
}
]
}
Explanation of the Code:
* Action: Limits rights to reading (GetObject) and listing (ListBucket). Writing or deleting is removed.
* Resource: Specifies both the bucket and the objects within it using the wildcard /*.
* Condition: Adds a tag-based condition requiring the principal to have an environment tag of production. This prevents the same user from accessing the bucket in a staging account even if they share the same username.
Step 3: Verification and Simulation
Before applying the new policy, you must verify it does not break existing workflows or grant unintended access. Use the AWS Policy Simulator to test the configuration.
- In the IAM console, navigate to Policy Simulator.
- Paste the generated JSON policy.
- Select the target resource and the principal user from Account B.
- Run the simulation.
Expected Results:
* The simulator should return True for s3:GetObject.
* The simulator should return False (or indicate a violation) for any action not explicitly listed, such as s3:PutObject.
* If you attempt to simulate access from a user without the required Environment tag, the simulation should fail.
Common Errors and Fixes:
* Error: “Access Denied” during simulation when it should work.
* Fix: Check for conflicting Deny statements in the root policy or attached group policies. Ensure the principal ARN is formatted correctly (Account ID must match exactly).
* Error: Syntax error due to missing commas or quotes.
* Fix: Use the JSON validator tool within the console or an external linter like aws-lint.
Step 4: Implementation and Monitoring
After verification, attach the new inline policy or update the managed policy in the Management Account. Ensure that the change is logged via AWS CloudTrail for audit trails.
Once implemented, set up continuous monitoring. IAM Access Analyzer can be configured to send notifications when external access is detected. This allows your security team to receive alerts immediately if a new cross-account permission is granted without approval.
Student Practice Task:
Create a scenario where Account B needs to read logs from Account A’s CloudWatch Logs but must not be able to delete them. Draft the policy, simulate it for two different users (one with proper tags, one without), and document your findings in a lab report. Explain how the tag condition enforces security boundaries.
Industry Application: Cost Controls and Governance
Beyond security, this approach aids in cost control. By restricting access to specific resources, you prevent accidental data modification that could lead to financial loss (e.g., ransomware encryption of critical buckets). Furthermore, granular permissions allow for better accountability; if a user accesses only the finance-apps bucket, their activity is easier to audit and trace compared to a wildcard policy covering all buckets.
To verify policy terms and ensure compliance with local laws, always consult the specific AWS Region’s compliance documentation. Remember that while IAM Access Analyzer provides powerful insights, it does not replace legal review of data residency requirements or industry-specific regulations like GDPR or HIPAA. Always assume that your current configuration is a starting point for optimization, not a final state. Regularly re-run the analysis drill as your architecture evolves to ensure your least-privilege stance remains valid.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

