Dev.to AI ๐Ÿค– Ai ๐Ÿ‘ 0 ๐Ÿ“– 12 min read

How to Audit What an AI Agent Did to Your Infrastructure (2026): What to Record and How to Reconstruct a Change

To audit what an AI agent did to your infrastructure, give every agent its own identity tied to a named person, send every change through an API that writes an audit record, and keep those records longer than the default

To audit what an AI agent did to your infrastructure, give every agent its own identity tied to a named person, send every change through an API that writes an audit record, and keep those records longer than the default. On Control Plane, every action goes through one API, whether it comes from the Console, the CLI, Terraform, or an AI assistant connected through Control Planeโ€™s MCP server, and it lands in one tamper-proof audit trail that the assistant can query for you.

Disclosure: Control Plane publishes this guide.

TL;DR

An agentโ€™s change can be reconstructed when six fields were recorded at the moment it happened.

  • Six fields. Who asked, which agent acted, what changed, when, under what authority, and the result.
  • Shared keys erase the โ€œwhoโ€. When several agents use one key or one service account, every action carries the same identity.
  • Cloud logs record the call. They show the API request and the identity that made it. The prompt is not part of the API call, and the person behind the agent appears only when the identity carries it, such as an AWS source identity.
  • Defaults vary by layer. AWS CloudTrail Event history and the Azure Activity Log each keep 90 days of events, and a self-managed Kubernetes API server writes no audit events until an audit policy file is set.
  • Where Control Plane fits. One API, one audit trail for every interface, OAuth sign-in for assistants, a read-only mode, and an audit query the assistant can run.

How do I audit what an AI agent did to my infrastructure?

You audit an agentโ€™s change by starting from the resource and the time, finding the audit record for that change, and following the identity in it back to a person.

  1. Start from the resource and the time. Name the resource that changed and the window in which it changed.
  2. Find the audit record. Search the audit log of the layer that owns the resource for write actions on it in that window.
  3. Read the identity. The record names a user, a role session, or a service account. Note the session name and any source identity.
  4. Tie the agent session to a person. Match the session name, source identity, or sign-in event to the identity providerโ€™s sign-in log or the agentโ€™s session log, which names the person who started it. This step fails when agents share credentials.
  5. Read the request and the result. Where the layer records them, the request parameters show what the agent asked for, and the result shows whether it succeeded. Then list every other call the same session made, including denied calls where the layer records them, to learn the full scope of the run.
  6. Compare with the plan or the commit. A saved Terraform plan or a Git commit shows what the change was meant to be. A change with no matching plan or commit was made outside the pipeline.

Two related guides cover the controls around these steps. One compares which platforms let AI agents provision and manage cloud infrastructure safely, and the other explains how to operate cloud infrastructure through MCP.

What should an audit record of an agent action contain?

An audit record of an agent action should contain six fields.

Field Question it answers Where it usually breaks with agents
Who asked Which person started or approved the work? The agent uses a shared key, so no person is attached
Which agent Which agent and which session acted? Several agents use one service account
What changed Which resource, which action, which parameters? Only the tool name is logged, without its arguments
When At what time did it happen? Each layer stamps its own time. CloudTrail records when the request was completed, and the Kubernetes audit log records when the request reached the API server
Under what authority Which role or policy allowed it? The record names a broad role, so it shows the action was allowed and cannot show the task was approved
Result Did it succeed, and what came back? Calls that fail before they reach the API appear only in the agentโ€™s own logs, and the agentโ€™s summary can differ from the APIโ€™s response

NIST SP 800-53 control AU-3 asks that an audit record establish what type of event occurred, when, where, the source, the outcome, and the identity of any individuals, subjects, or objects associated with the event. The six fields apply that list to agent actions, split identity into the person and the agent, and add the authority behind the action. Cloud records carry the where and the source as a region and a source IP address.

Where is an AI agentโ€™s action recorded?

An agentโ€™s action is recorded in several layers, and each layer keeps a different part of the six fields.

Layer What it records Kept by default What it does not tell you
Control Plane audit trail Every platform action from every interface, with an event time, a request id, a context, a subject (the user that acted), an action, a resource, and a result On by default for every interface. Control Planeโ€™s pre-provisioned cpln audit context, its built-in scope for platform audit events, captures all Control Plane platform activity Events inside your own application are added by the workload, which writes them to a Control Plane audit context
AWS CloudTrail Management events with userIdentity, eventTime, eventName, requestParameters, responseElements, sourceIPAddress, and userAgent Event history keeps 90 days of management events; a trail or event data store keeps an ongoing record Data events, which are not logged by default
Azure Activity Log Management operations with caller, claims, authorization, and correlationId 90 days; longer retention needs a diagnostic setting Data plane operations performed within a resource, which resource logs capture and which are not collected by default
Google Cloud Audit Logs Admin Activity entries with principalEmail and serviceAccountDelegationInfo Admin Activity logs are always written and kept 400 days Data Access events, which are disabled by default except for BigQuery
Kubernetes audit log Requests to the API server with user, impersonatedUser, verb, objectRef, and sourceIPs No audit events on a self-managed API server until an audit policy file is set; on a managed service, audit logging is configured through the provider Request bodies, unless the policy level is Request or RequestResponse
MCP client and server logs tools/call requests with a tool name and arguments, where the client or server logs them Depends on the client and the server A standard record format. The tools page of the specification says clients should log tool usage for audit purposes and sets no format or fields for that log
Git and Terraform plan The intended change, as a commit with its author, committer, timestamps, and message, and as a saved plan that previews the changes As long as the repository and the saved plan are kept Who ran the change. A plan is a preview, and a commitโ€™s author and committer come from the clientโ€™s own configuration. A signature ties the commit to a key
OpenTelemetry traces Agent and tool-call spans such as invoke_agent and execute_tool, with attributes such as gen_ai.tool.name and gen_ai.agent.name Depends on your tracing backend A stable schema. The agent and tool-call conventions are marked Development

The cloud or platform audit log is the record of what changed, and the agent-side logs explain why. Join them by putting the agentโ€™s session id into the role session name, where the cloud has one, and by comparing timestamps in UTC.

Why canโ€™t you tell which agent made a change?

You cannot tell which agent made a change when the agentโ€™s identity is shared, self-reported, or lost along a chain of roles.

Shared credentials. One access key or one service account used by several agents produces identical audit records. The log is complete and still cannot separate one agent from another, or an agent from the engineer who owns the key.

Self-reported labels. A user agent string is set by the caller. Kubernetes documents its userAgent audit field as not to be trusted, and the same caution applies to any label the client chooses for itself.

Role chaining. An agent that assumes one role and then another can lose the original identity along the way. On AWS, a source identity identifies the original user identity making the request, cannot be changed once set, and persists across role chaining. An assumed-role session also carries a role session name in CloudTrail.

The fix. Give each agent its own identity, name each session after the person and the agent session, set a source identity where the platform has one, and make a person sign in before an agent can act. The caller chooses the session name and the source identity when it assumes the role, so on AWS require both in the roleโ€™s trust policy with the sts:RoleSessionName and sts:SourceIdentity condition keys, and allow sts:SetSourceIdentity in that policy. The Model Context Protocol specification says there should always be a human in the loop with the ability to deny tool invocations. Its authorization specification, which is optional and applies to HTTP-based transports, is based on OAuth 2.1, with the MCP client acting on behalf of a resource owner.

What should you set up before an agent touches production?

Seven controls make an agentโ€™s actions auditable before it changes anything.

  1. One identity per agent. No shared keys and no shared service accounts.
  2. Least privilege with a read-only mode. Start agents with read access that excludes secret values, and grant write access per task with credentials that expire. Enforce the limit in the identityโ€™s policy as well as in the agentโ€™s tool list.
  3. All changes through one audited API. Close the paths that bypass it, such as shared console logins and long-lived keys on the machines where agents run.
  4. Retention longer than the default, out of the agent โ€™s reach. Export cloud audit logs to storage in a separate account that no agent identity can write to or delete from, and keep them as long as your policy requires.
  5. Data-plane logging where it matters. Turn on data events or data access logs for the stores that hold customer data or secrets. An agent with read access can copy data without writing a management event.
  6. Approval before destructive actions. A person approves deletions and permission changes, and the approval is recorded outside the agent, in a pull request review or a change ticket.
  7. A reconstruction test. Pick one agent change each month and rebuild all six fields from the logs alone.

How Control Plane fits

Control Plane handles Day 2 operations for you, including autoscaling, built-in observability, and security.

Control Plane has a tamper-proof audit trail. Every interface writes to it, because the Console, the CLI, Terraform, Pulumi, the Kubernetes operator, and AI assistants connected through Control Planeโ€™s MCP server all call the same API.

Assistants sign in to Control Planeโ€™s MCP server through OAuth. The user signs in with Google, GitHub, Microsoft, or SAML and selects the Control Plane orgs the assistant may access, and orgs that are not selected are unreachable. The readonly toolset profile of Control Planeโ€™s MCP server has no create, update, delete, or execute tools, and the profile is fixed for the life of the connection. Control Plane policies scope what an assistant can do in an org with least privilege, and a policy binds permissions to users, groups, service accounts, or workload identities.

The assistant can query the audit trail itself through the MCP tool query_audit_events, and Control Planeโ€™s CLI command cpln auditctx audit filters by subject, context, and time range. The subject of an audit event is the user that acted. An audit context is Control Planeโ€™s named scope for audit events, and workloads can write their own events to one, with reading and writing granted as separate permissions. For destructive tools, Control Planeโ€™s MCP server instructs the assistant to state the impact and get your approval first, and the enforced limits are the readonly profile and Control Plane policies. A separate comparison of the best MCP servers for DevOps covers what an assistant can change on other servers.

FAQ

Each answer applies to AI agents and coding assistants that change cloud infrastructure through an API.

How do I audit what an AI agent did to my infrastructure?

Find the audit record for the changed resource and trace the identity in it to a person. That works when each agent has its own identity, every change goes through an audited API, and the records outlast the default retention. On Control Plane, ask the assistant who changed a resource and when, and it queries the audit trail through query_audit_events.

How do I know which person was behind an AI agentโ€™s action?

You know when the agentโ€™s session was started by a signed-in person and the audit record carries that identity. A shared key or a shared service account removes the link, so give each agent its own identity and require a sign-in before it can act.

Does CloudTrail show which AI agent made a change?

Only when each agent uses its own identity, role session name, or source identity. CloudTrail shows the identity that made the call, including the role session name for an assumed role. The userAgent field records the agent through which the request was made, such as the AWS SDKs or the AWS CLI, so it does not name the AI agent.

How long are cloud audit logs kept?

AWS CloudTrail Event history keeps 90 days of management events, the Azure Activity Log keeps 90 days, and Google Cloud keeps Admin Activity audit logs for 400 days. Longer retention on AWS and Azure needs a trail, an event data store, or a diagnostic setting.

Does the Model Context Protocol log tool calls?

The protocol writes no log itself. The specificationโ€™s tools page leaves logging to the client and defines no record format there. What is recorded depends on the client and the server you use, so the durable record is the audit log of the API the tool calls.

Can an AI agent audit its own actions?

Yes for lookup, when the audit trail is written by the platform and the agent can only read it. On Control Plane, the assistant queries the audit trail through query_audit_events, a read tool that stays available in the readonly toolset profile, and the Control Plane API writes the record whichever interface made the change. During an investigation, a person should check the assistantโ€™s summary against the trail directly.

How do I stop an AI agent from deleting infrastructure?

Give the agent an identity with no delete permission, and put deletions behind an approval the agent cannot skip. On Control Plane, the readonly toolset profile has no delete tools, and Control Plane policies decide whether a delete is permitted at all. With write access, the assistant tells you what a deletion removes and what breaks, then waits for your yes.

What is the difference between an audit trail and observability traces?

An audit trail records who changed what, under which authority, and is kept as evidence. Traces record how a request moved through a system, are emitted by the agentโ€™s own process, and are often sampled. Use traces to follow the order of an agentโ€™s model and tool calls, and use the audit trail to prove what it changed.

Do I need separate audit logs for each cloud?

Yes for the clouds themselves, because each provider writes its own log with its own fields and retention. On Control Plane, workloads on AWS, Google Cloud, Azure, and Oracle Cloud Infrastructure are managed through one API, so every change made through it lands in one audit trail.

Talk to the Control Plane team about auditing AI agents on your infrastructure, or sign up free to connect an assistant in read-only mode.

Originally published on the Control Plane blog.

๐Ÿ“ฐ Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.