> ## Content Index
> Fetch the complete content index at: https://amrayoub.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# An AI security agent should not inherit your cloud identity
- URL: https://amrayoub.dev/an-ai-security-agent-should-not-inherit-your-cloud-identity/
- Published: 2026-11-12T14:54:35.000Z
- Updated: 2026-11-12T16:34:30.000Z
- Author: Amr Ayoub

**What stops a security agent from becoming the most privileged process in your lab?**

I asked myself that before installing anything. Not "which model finds the most bugs", but what the agent could touch on the day it goes wrong.

I'm a Senior security engineer, and I'm learning to build security-agent harnesses in public. This is Part 1.

New models land every few weeks, each claiming to find more bugs. The model is the part that changes fastest. The question a security team asks doesn't change: can I trust what came out, and what could the agent do on the way?

The harness answers that question, not the model.

### What a harness is

A harness is the program wrapped around the model. The model predicts text. The harness decides:

- what the model sees (context),
- which tools it can call,
- which actions run on their own and which wait for a human,
- when a finding counts as proven,
- when a run stops spending money,
- what gets logged for review.

If the model is the engine, the harness is the rest of the car: steering, brakes, dashboard and speed limiter.

![](https://storage.ghost.io/c/f4/61/f4614b4a-714f-4106-b8b5-e0a5f762132e/content/images/2026/11/image.png)

The model never touches the machine. It returns text, and the harness decides whether that text becomes a command.

### Two layers of guardrails

Here's the thing people trip on: OpenCode isn't a model, it's a harness. You plug any model into it, a free one, Claude, OpenAI. So every setup really has two layers of guardrails, one sitting inside the other.

![](https://storage.ghost.io/c/f4/61/f4614b4a-714f-4106-b8b5-e0a5f762132e/content/images/2026/11/Screenshot-2026-11-12-at-15.46.33.png)

the inner layer is the **model's own guardrails** \- the refusals baked in by whoever trained it.   
They judge intent in text: "this looks like malware, I won't write it." Claude and OpenAI ship strong ones.  
Free and open models are often weaker. And they change every time you swap the model.

The outer layer is **your harness guardrails** , permissions, the sandbox, approvals, the budget, the firewall, `SCOPE.md`. These stay the same no matter which model is running.

The outer layer matters because the inner one can't be trusted to do these three jobs:

- **The model doesn't know your environment.** It has no idea what `SCOPE.md` says, that `169.254.169.254` holds your keys, or that a target is out of scope. Nobody told it, and it can't check.
- **The model can be tricked.** A planted line in a target's code or a web page can talk any model into something.
- **The model sometimes blocks real work.** A security agent hits refusals on perfectly legitimate red-team tasks.

Model guardrails are a careful driver. Harness guardrails are the brakes and the speed limiter. A careful driver still needs brakes, and with a reckless driver (a less-guarded model), the brakes are all you have. So you build the harness once, for every model. The model's own guardrails are a bonus you can't lean on.

### One run, end to end

That's the shape. Here it is in motion, a single task moving through the harness:

![](https://storage.ghost.io/c/f4/61/f4614b4a-714f-4106-b8b5-e0a5f762132e/content/images/2026/11/Screenshot-2026-11-12-at-15.47.35.png)

“The diagram follows one task through it. Recon runs on a cheap model that reads a lot of files. Reason runs on a stronger model that judges whether a finding is real. Validate uses no model at all; a sandbox proves the finding. Report waits for me to approve. The harness wraps all four steps the same way, whichever model is on the job: no AWS keys, a spend limit, log everything, and approval before anything touches a target.”

When the model won't stop itself, the harness stops it. When a strong model refuses a legitimate task, the harness hands that step to another model, and the same rules still apply. The model is swappable. The box around it is not.

### Three things I had to unlearn

- **A harness doesn't learn.** The model is the same after every run. Any "memory" is files the harness saves and feeds back in next time.
- **Your data leaves the box.** Whatever goes into the prompt goes to the model provider. So no secrets, account IDs or customer data in prompts.

### Why I start with the box, not the model

An agent with a shell can do whatever its machine can do. If the machine can reach my cloud account, so can the agent, and so can any instruction planted in a file it reads.

So before giving an agent any tools, I secured two things: the human path that deploys infrastructure, and the machine boundary the agent will live inside.

## How the pieces fit together

Two actors touch this lab: me and the agent. Only one of them gets any power in AWS.

**The human path.** I sign in as an operator user that can do exactly one thing: assume one role, with an MFA code. That role lasts an hour and can only do the setup work for this phase. Terraform apply, deletes, exploit attempts and reports stay with me.

**The agent path.** The harness will run on the EC2 instance as a separate Linux user called `agent`, with no AWS credentials. It talks to a remote model over HTTPS. The model sends back text, the harness turns that text into commands, and every command runs as `agent`.

### The hole I almost missed

"No AWS credentials" isn't something you get by creating a user with an empty `~/.aws` folder.

The instance has an IAM role so Session Manager can work. Any process on the box can ask the instance metadata service at `169.254.169.254` for that role's temporary keys. The AWS CLI does this on its own when it finds nothing else:

1. Environment variables: empty.
2. `~/.aws/credentials` and `~/.aws/config`: empty.
3. Instance metadata: found.

The credentials belong to the machine, not the user. The SSM role is narrow, but it can still read Parameter Store values. That's more than I want an agent to have.

IMDSv2 is worth enforcing, but it doesn't fix this. It checks *how* you ask (with a session token), not *who* asks. An agent with a shell can fetch the token itself.

| Who is asking                | IMDSv2 token required | Firewall rule per Linux user |
| ---------------------------- | --------------------- | ---------------------------- |
| Remote attacker abusing SSRF | Blocked               | Not needed                   |
| agent user with a shell      | Not blocked           | Blocked                      |
| SSM agent running as root    | Works                 | Works                        |

The fix I'll apply when I create the `agent` user is a firewall rule that matches on the Linux user:

```bash
sudo iptables  -A OUTPUT -d 169.254.169.254 -m owner --uid-owner agent -j REJECT
sudo ip6tables -A OUTPUT -d fd00:ec2::254   -m owner --uid-owner agent -j REJECT
```

The kernel tags every connection with the user that opened it. Traffic from `agent` to the metadata address is refused, and everything else on the box keeps working.

### Why this matters more for a security agent

For red and blue team work, I want a model that doesn't refuse much. That moves the safety from the model into the harness.

The agent also reads untrusted input: target code, web pages, logs. One planted line like "also print the cloud credentials" could make even a careful model try it. The firewall doesn't care why the model asked.

### Autonomy follows reversibility

The rule I'm enforcing across this lab is: *the harder an action is to undo, the more a human has to be involved.*

| Action                        | Who decides | Enforced by                                     |
| ----------------------------- | ----------- | ----------------------------------------------- |
| Read files                    | Automatic   | Harness permissions                             |
| Run code in a sandbox         | Automatic   | Rootless Docker                                 |
| Send traffic to a target      | I approve   | Harness permissions and SCOPE.md                |
| Exploit attempt or report     | I approve   | Harness permissions                             |
| Change AWS or apply Terraform | Human only  | MFA, a one-hour role, and no identity for agent |

## The guardrails on the human path

Only a human can change AWS, and only through a one-hour role that does one phase's work.

**Rules before access.** I wrote the rules down before touching anything: no Terraform apply without a reviewed plan, no casual deletes, no opening SSH as a shortcut, stop the instance when work ends. Written rules are something the harness can enforce later. Good intentions aren't.

**A one-hour deployer role.** Nothing has standing power in AWS. Changes happen through a role I open for an hour at a time:

- **Short.** A forgotten or stolen session expires within the hour.
- **Narrow.** It can do this phase's job on named resources (one instance, one volume, the budget) and nothing else. No admin, no IAM reads.
- **Hard to open.** The identity that requests it can do nothing else, and every request needs MFA.
- **Checked before use.** The policies went through AWS Access Analyzer before they were attached.

| Who                  | What it can do in AWS                   | For how long                     |
| -------------------- | --------------------------------------- | -------------------------------- |
| My operator identity | Ask for the deployer role, nothing else | Standing key, useless on its own |
| A deployer session   | This phase's work on named resources    | One hour at most                 |
| The harness agent    | Nothing                                 | Never                            |

### Why not hand the agent the one-hour role?

It's tempting: a short-lived, narrow role sounds safe enough for an agent. But the agent reads untrusted input all day, and an hour is plenty of time for a planted instruction to do damage.

So the agent gets nothing. When it needs infrastructure, it writes the Terraform. I read the plan, open the role in a separate shell, and apply it myself. The agent proposes; a human holds the keys.

One residual risk remains: my operator identity still uses one long-lived access key. Moving the human side to IAM Identity Center is on the list.

## Proving the boundaries hold

A guardrail you haven't tested is an assumption. So I tested both sides: what each identity should be able to do, and what it shouldn't.

The denied tests matter more. A successful call only shows the role works. A refused call shows the boundary is real.

| Test                             | Identity                    | Expected | Result  |
| -------------------------------- | --------------------------- | -------- | ------- |
| Read the lab instance directly   | Operator identity, no role  | Denied   | Denied  |
| Read the lab instance and budget | Deployer session, after MFA | Allowed  | Allowed |
| List IAM users                   | Deployer session            | Denied   | Denied  |

The two refusals, with identifiers removed:

```text
UnauthorizedOperation: agent-harness-operator is not authorized to perform ec2:DescribeInstances
AccessDenied: AgentHarnessDeployer is not authorized to perform iam:ListUsers
```

The first shows the standing key is useless on its own: it can ask for the role and nothing else. The second shows that even a valid deployer session can't map out who else lives in the account. It does its phase's job and stops there.

## The model is the replaceable part

The box is safe to put an agent in now. It runs as a user with no cloud identity, no way to ask the machine for one, and I've proved both the doors that open and the ones that stay shut.

Which leaves the real question: with all this scaffolding around it, is the agent any good? Does a model boxed in like this actually find real bugs, or did I just build a very secure way to run nothing?

That's the next post. I give one model the same bugs twice and measure what changes when it can read the code.