Introduction
AI agents stopped being chat windows. Kiro CLI, Amazon Q and MCP servers like awslabs.aws-api-mcp-server run AWS CLI calls and shell commands on your machine, with whatever credentials your terminal has. In many teams, that means the engineer’s own SSO session, often with admin rights.
This post is part 1 of the series Agentic DevSecOps on AWS. Here I map what can go wrong. Part 2 builds the IAM guardrails, and part 3 builds the detection.
Quick Answer
An AI agent inherits every permission of the credential it runs with, and its client-side settings are not a security boundary: an agent that can run a shell can call aws directly. The risks fall into five groups: destructive mistakes, prompt injection, data exposure, privilege escalation and cost. The controls that hold are the ones enforced by AWS: a dedicated, short-lived role per agent session, a permission boundary, attribution in CloudTrail and detection on agent activity.
How an agent actually touches your account
There are three paths, and they matter because each one has different controls:
| Path | Example | Credential used | Client-side control |
|---|---|---|---|
| Native AWS tool | Kiro CLI aws tool (use_aws) | Current profile / env | allowedServices, deniedServices, autoAllowReadonly |
| Shell | Agent runs aws ec2 terminate-instances ... | Current profile / env | allowedCommands, deniedCommands, denyByDefault |
| MCP server | awslabs.aws-api-mcp-server | AWS_API_MCP_PROFILE_NAME or default chain | READ_OPERATIONS_ONLY, REQUIRE_MUTATION_CONSENT |
The trap is in the second row. You can deny iam in the AWS tool and the agent can still run aws iam create-access-key through the shell. And the shell allowlist is regex matching on a command string, which the Kiro docs themselves warn can be bypassed with things like a variable assignment before the command.
Client-side settings are good for reducing prompts and accidents. They are not where you enforce security.
The threat model
I use five categories. For each one: how it happens with an agent, the impact and the control that actually holds.
1. Destructive mistakes (no attacker needed)
The most likely failure isn’t malicious. The agent misreads the task, picks the wrong account or region, or “cleans up” resources it thinks are unused.
- Vector: ambiguous prompt, wrong
AWS_PROFILE, auto-approved commands, long sessions where the context drifts. - Impact: deleted buckets, terminated instances, dropped tables, broken networking.
- Control that holds: a permission boundary that denies irreversible actions (
s3:DeleteBucket,rds:DeleteDBInstance,kms:ScheduleKeyDeletion, …) and allows terminating only resources tagged as agent-managed.
2. Prompt injection
The agent reads untrusted content (a README, a GitHub issue, a log line, an S3 object, a web page) that contains instructions. It treats them as part of the task.
- Vector: anything the agent reads during the session. You don’t need a compromised machine, only a poisoned input.
- Impact: the attacker effectively gets your agent’s permissions.
- Control that holds: assume injection will eventually happen and limit what a hijacked session can do. Least privilege on the role, no secret reads, approved regions only, and an alert on every write call.
3. Data exposure
The agent needs to see configuration. It rarely needs to read data. But the managed policy most people grab for “read-only”, ReadOnlyAccess, includes s3:GetObject, DynamoDB reads and more.
- Vector: an agent dumping objects, table items or parameters into its context, which then goes to a model provider or into a log.
- Impact: customer data or secrets leaving the account through the model context.
- Control that holds: use
ViewOnlyAccess(configuration, not content) for the read-only role, and explicitly denysecretsmanager:GetSecretValue,ssm:GetParameter*andkms:Decryptin the boundary.
4. Privilege escalation and persistence
If the agent’s role can change IAM, a single injected instruction becomes a permanent backdoor: a new access key, a new user or a role with a trust policy pointing outside.
- Vector:
iam:CreateAccessKey,iam:AttachRolePolicy,iam:PassRole,iam:UpdateAssumeRolePolicy. - Impact: persistence that survives the session and the investigation.
- Control that holds: the boundary denies every mutating IAM action, plus SSO, Identity Store and Organizations. Agents don’t manage identity. Humans do, through Terraform and review.
5. Defense evasion and cost
A hijacked or confused agent can turn off the things that would catch it (CloudTrail, GuardDuty, Security Hub, the detection rule itself) or simply spin up expensive resources.
- Vector:
cloudtrail:StopLogging,guardduty:DeleteDetector,events:DisableRule, large instance types in a forgotten region. - Impact: blind spots, and a bill.
- Control that holds: deny tampering with logging and with the agent detection pipeline, deny every region you don’t use, and keep budget alerts.
Attribution: the control everyone skips
When something goes wrong, the first question is who did this, the engineer or the agent? If the agent uses the engineer’s SSO session, CloudTrail can’t tell you.
The fix is cheap: the agent assumes a dedicated role with a session name that identifies it, for example agent-kiro-matheus. Every event then carries:
arn:aws:sts::111122223333:assumed-role/ai-agent-operator/agent-kiro-matheus
That one string lets you search, alert and revoke only agent sessions. Part 2 enforces this in the trust policy (sts:RoleSessionName must start with agent-).
The control stack, in order of importance
- Dedicated, short-lived role per agent session. Never the human’s session.
- Permission boundary. No IAM, no defense evasion, no irreversible deletes, no secrets, approved regions only.
- Least-privilege identity policy.
ViewOnlyAccessby default, operator permissions only when the task needs them. - Attribution. Session name
agent-*, enforced by the trust policy. - Detection and response. Alert on every write from an agent session, and be able to revoke all agent sessions in one step.
- Client-side settings.
deniedServices,READ_OPERATIONS_ONLY,REQUIRE_MUTATION_CONSENT. Useful, never sufficient.
Common Issues
“But I approve every command”
Problem: approval fatigue. After the twentieth prompt you approve without reading, and autoAllowReadonly plus broad allowlists remove the prompts anyway.
Solution: approvals are UX. Put the limits in IAM, where they don’t depend on your attention.
“The MCP server is read-only”
Problem: READ_OPERATIONS_ONLY=true is enforced by the server, on its own tool calls. The same agent may also have a shell.
Solution: give the MCP server a read-only profile (AWS_API_MCP_PROFILE_NAME=agent-readonly), so the limit lives in IAM.
What’s next
In part 2 I build the two agent roles (read-only and operator), the permission boundary and the trust policy in Terraform, and show the guardrail denying an IAM change. The Terraform module and the policies will be published as an open-source repository together with part 2.