8 views
This guide focuses on AI agent IAM for production systems, with practical trade-offs for reliability, security, and cost.
God keys in .env for “the bot” are how you get a very polite breach. Agents need per-tool IAM roles, short-lived credentials, and Access Analyzer on any policy an agent proposes.
⚡ TL;DR: One role per tool family. STS AssumeRole with session tags (run_id). Never embed long-lived keys in prompts. Analyze generated policies before apply.
AI agent IAM: production guidance
hcl
# terraform/agent_roles.tf
resource "aws_iam_role" "agent_s3_read" {
name = "agent-s3-read"
assume_role_policy = data.aws_iam_policy_document.agent_trust.json
}
resource "aws_iam_role" "agent_sandbox_apply" {
name = "agent-sandbox-apply"
assume_role_policy = data.aws_iam_policy_document.agent_trust.json
}
python
# creds.py
import boto3
sts = boto3.client("sts")
def session_for(tool_family: str, run_id: str):
role = ROLES[tool_family]
out = sts.assume_role(
RoleArn=role,
RoleSessionName=f"agent-{run_id}"[:64],
DurationSeconds=900,
Tags=[{"Key": "run_id", "Value": run_id}],
)
c = out["Credentials"]
return boto3.Session(
aws_access_key_id=c["AccessKeyId"],
aws_secret_access_key=c["SecretAccessKey"],
aws_session_token=c["SessionToken"],
)
Access Analyzer on generated policies
bash
❌ Applying model-written IAM JSON because “it looks least-privilege” — validate and human-review.
aws accessanalyzer validate-policy \
--policy-document file://proposed.json \
--policy-type IDENTITY_POLICY
Closing checklist
- [ ] Per-tool roles + STS
- [ ] Session tags with run_id
- [ ] Validate policies before apply
- [ ] Short durations (≤15m)
- [ ] CloudTrail on AssumeRole
Series navigation
Day 62: SSRF and Tool Allowlists · Day 64: Secret-Aware Context Filters Last updated September 11, 2026 Related: IAM for AI Agents: Condition Keys That Limit Blast Radius by Tag; Day 51: Multi-Agent Roles: Planner, Implementer, Critic; Day 76: p99 of Agents: Queueing, Not Just Model Latency.Watch: 100 Days of AI on YouTube
Short videos from CheatCoders, one AI engineering topic per day.
Most viewed
- Python Decorators Explained: From Simple Wrappers to Production Patterns
- Claude Code vs Cursor vs GitHub Copilot: Choose by Workflow, and Set Up One Repo That Works With All Three
- AI Agent Frameworks in 2025: LangGraph vs CrewAI vs AutoGen vs Raw API
- Python String Methods: Every str Method With Real Production Examples
- Css Animation Performance: Performance-Optimized Motion for Modern UIs
Newly added
- AWS Systems Manager Parameter Store: Hierarchical Runtime Config for Coding Agents
- Amazon Cognito Identity Pools: Federate Coding-Agent Tool Callers Without Long-Lived Keys
- Amazon Athena for Coding Agents: Query Tool Audit Logs and Eval Traces on S3 Without a Warehouse
- AWS Batch for Coding Agents: Parallel Overnight PR Reviews and Long-Running Jobs Without Lambda Timeouts
- Amazon Bedrock Prompt Management: Version and A/B Test Coding-Agent System Prompts
Deep-dive PDF
Get the expanded guide for this post — extra diagrams-style checklists, failure modes, and a production walkthrough. Free when you subscribe to CheatCoders.
Already subscribed? or open the subscribe page.
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.
