Skip to content

Domain 5: Security and forensics

17 minute read
Content level: Advanced
0

This article describes how to build agent infrastructure that holds up under investigation, covering the telemetry and immutable storage that make an agent's actions reconstructable months later, the behavioral baselines that reveal misuse at the application layer, the layered defenses that stop a manipulated prompt from becoming a permitted action, and the credential practices that keep one compromised agent from reaching another team's systems.

When agents take actions on your behalf, you must address security considerations that are beyond traditional application security. If malicious actors compromise or misuse an agent through prompt injection, credential theft, or malicious intent, then you need to understand what happened, what path the agent took, and what actions it performed.

Forensic traceability

Design agent infrastructure for forensic investigation from the start so that you can trace every agent action. This includes the inputs that triggered the action, the reasoning that the agent applied, the outputs that it produced, and their downstream effects. You need this when issues occur. Your security team can reconstruct events, and your compliance department can use this data to support your audit requirements. To support both, audit trails must capture the following request data:

  • Prompt data: The full prompt and context sent to the agent.

  • Response data: The complete output, including tool invocations.

  • Metadata: Timestamps, user identity, session information, and model version.

  • Tool interactions: Every external system that the agent contacted and the data that it exchanged.

For agents that you host on Amazon Bedrock AgentCore Runtime, turn on AgentCore Observability and instrument your code with the AWS Distro for OpenTelemetry (ADOT) SDK. AgentCore uses a tracing model of sessions, traces, and spans. Each span captures the duration, inputs, and outcomes of a discrete operation such as an agent invocation, tool call, or model request. AgentCore automatically generates runtime metrics and a basic invocation span that records the agent Amazon Resource Name (ARN), endpoint, session ID, and latency. To receive this span data, turn on tracing on your agent resource in the AgentCore console. For deeper data on tool invocations, reasoning steps, and external calls, emit custom spans with ADOT. With Observability, AgentCore also produces application logs that contain the full request and response payloads with correlation fields (trace_id, span_id, and session_id) that link logs to their traces. All telemetry flows to Amazon CloudWatch, which you can then view in the Generative AI Observability dashboard and Transaction Search.

To capture prompts and responses, turn on Amazon Bedrock model invocation logging. This Amazon Bedrock setting, which defaults to off, records the full request data, response data, and metadata for every Converse and InvokeModel call in your account. Model invocation logging can also deliver logs to CloudWatch Logs and Amazon Simple Storage Service (Amazon S3). You can get an immutable record of what your agent asked the model and what it returned. This record is useful for auditing decisions, incident investigation, and prompt injection detection.

AWS DevOps Agent provides forensic traceability through a different mechanism. The agent maintains detailed journals that log every reasoning step and action during investigations. These logs are accessible through the ListJournalRecords API and show reasoning steps, actions that the agent took, and data sources that it consulted. The operator web app surfaces this as an investigation timeline that categorizes activity into planning, data fetching, observations, findings, and root cause determinations. This is part of AWS DevOps and doesn’t require instrumentation. Journals are service-managed, read-only, and immutable. Because APIs can’t modify or delete records, they can’t alter a record after you complete an investigation. AWS CloudTrail captures all AWS DevOps Agent activities within the hosting account, provides an infrastructure-level audit trail alongside the application-level journals. Compared to custom agents, this managed approach reduces the effort to achieve traceability.

Secure this forensic data deliberately. If someone uses an agent to leak data, then your forensics team must preserve evidence for potential legal action. An audit trail that isn’t verifiable and structurally intact might not be valid in legal proceedings. Store audit data in immutable storage: Amazon S3 with Object Lock for long-term retention, and CloudWatch Logs with retention policies for operational use. Implement controls that prevent log tampering, establish chain-of-custody procedures, and test your forensic processes before you need them.

Be equally mindful of what ends up in those logs. When you inject data into agent prompts, such as database names, customer records, internal systems of record, or tool responses, they flow through to your traces, application logs, and model invocation logs. Your infrastructure then persists sensitive information that an agent retrieves during an investigation, so make sure that injected data aligns with your organization's logging and retention policies. Amazon Bedrock Guardrails can help with this alignment. Sensitive information filters detect personally identifiable information (PII) in prompts and responses. These filters either block the request or mask the data with type identifiers (for example, {NAME} or {EMAIL}). Masking lets operational agents function while keeping PII out of the model and your logs. You can also define custom patterns with regular expressions and guardrails. Beyond guardrails, filter sensitive fields before injection. Encrypt log destinations, restrict access to log groups, and set retention periods that match your data classification.

Threat detection and anomaly monitoring

Traditional security monitoring focuses on infrastructure and network patterns. Agent security requires monitoring at the application layer to understand what agents are doing and whether that behavior is expected.

Establish behavioral baselines for your agents, including which tools each agent typically invokes, normal request volumes, expected data sources, typical response times, and token consumption. Deviations might indicate compromise or misuse. If an agent suddenly accesses unfamiliar data sources or invokes tools at unusual hours, then you must investigate.

For AgentCore-hosted agents, the Amazon Bedrock-AgentCore CloudWatch namespace provides runtime metrics, including invocations, throttles, system and user errors, latency, and session counts. AgentCore Policy logs every enforcement decision (both permitted and denied) and keeps a deterministic record of the actions that agents tried and whether they were allowed. Combine these with OpenTelemetry traces from AgentCore Observability to correlate anomalous behavior with specific tool invocations and reasoning paths. Use CloudWatch anomaly detection alarms to establish dynamic baselines instead of static thresholds. Anomaly detection models adapt to your agent's normal patterns. Then, an alarm on invocation count or error rate alerts you to activity spikes, unexpected error patterns, or abnormal token consumption. These alerts can indicate misuse, prompt injection, or a misconfigured agent.

For AWS DevOps Agent, threat detection relies on the agent's built-in journal and CloudTrail rather than custom metrics and traces. The journal is immutable, and CloudTrail captures all AWS DevOps Agent API calls with the caller identity, source IP address, and timestamps. AWS DevOps Agent tools are predominantly read-only, with limited exceptions for creating tickets and support cases. Because of this, the threat surface is narrower than custom agents that take write actions. Monitor CloudTrail for anomalous patterns such as unusual investigation frequencies, access from unexpected IP addresses, or attempts to connect new secondary accounts or Model Context Protocol (MCP) servers.

To integrate journal data into broader security monitoring, use the ListJournalRecords API to retrieve the agent's reasoning steps and actions programmatically. For example, build a scheduled AWS Lambda function that calls the API, formats the records, and forwards them to CloudWatch Logs for analysis with Logs Insights or to your SIEM. AWS DevOps Agent also supports vended logs delivered to CloudWatch Logs, Amazon S3, or Amazon Data Firehose. These logs cover operational events such as inbound event triggers, outbound communication failures, and topology operations. Review journal records periodically to confirm that investigations access only expected data sources and that the agent's reasoning aligns with your Agent Space configuration and AWS Identity and Access Management (IAM) roles.

Integrate alerts with your security operations center (SOC) workflows. Examine anomalies in agent outputs and actions regularly. These anomalies can include unexpected data access or patterns that automated baselines miss. When you conduct this regular review, you improve both quality and security.

Prompt injection defense

Prompt injection attacks are a significant threat to agent security. They occur when malicious users craft inputs to manipulate agent behavior, bypass safety controls, or extract sensitive information. Because many of the attack patterns apply directly to operational agents, review the OWASP Top 10 for Large Language Model Applications as a framework for identifying and mitigating these risks.

Common prompt injection patterns include the following:

  • Direct injection (malicious instructions in user input, such as "ignore previous instructions and...")

  • Indirect injection (malicious content in data sources that the agent retrieves, such as poisoned knowledge bases)

  • Jailbreaking (bypassing safety guardrails through creative prompting)

  • Prompt leakage (extracting system prompts or internal instructions)

  • Data exfiltration (extracting sensitive information from the agent's context)

Effective defense requires multiple layers. Content-level and action-level controls differ. Content filtering catches malicious prompts, but an injection might bypass the filter. When this occurs, action-level controls prevent the agent from acting outside its permitted boundaries. Any agentic service that you evaluate must provide both control levels.

Guardrails provides content-level safeguards that work with AgentCore-hosted agents and any foundation model, including models hosted outside Amazon Bedrock. Call the ApplyGuardrail API to evaluate inputs and outputs independently of model invocation so that the same policies apply wherever your agent runs. Guardrails offer content filters for prompt attacks (jailbreaks, injections, and prompt leakage), denied topics, sensitive information detection and masking, contextual grounding checks, and automated reasoning checks that validate responses against rules that you define.

AgentCore Policy provides action-level defense at the tool boundary. Policies written in Cedar (or authored in natural language and converted to Cedar) define which tools an agent can invoke and under what conditions, including constraints on user identity and tool input parameters. Enforcement happens at the AgentCore Gateway boundary, outside the agent's code, so prompt manipulation can’t bypass it. This enforcement denies all actions by default, and only explicitly permitted actions proceed.

Beyond these managed controls, implement defense in depth. Validate and sanitize user inputs before they reach the agent, separate system prompts from user inputs, and apply the least privilege principle so that agents access only what they need. Monitor for injection attempts, such as users repeatedly trying variations of system-level commands, attempts to access information outside the normal scope, or requests that reference internal system details.

AWS DevOps Agent handles prompt injection defense differently. AWS controls the agent's system prompts and orchestration logic, not you. The agent has multiple built-in safeguards, including read-only tools, and account boundary restrictions enforced through IAM roles assigned to each Agent Space. The agent also has foundation models with AI Safety Level 3 (ASL-3) protections and classifiers that detect and block injection attempts. Because the journal is immutable, a successful injection can’t hide its actions from the audit trail.

Your responsibility centers on controlling what data the agent consumes. AWS DevOps Agent ingests logs, resource tags, and other operational data during investigations. Malicious content that’s embedded in those sources could manipulate agent behavior. To prevent this, make sure that trusted users have access to the systems that produce that data (log pipelines, resource tags, ticket systems). Also, apply least privilege to those systems. Review any custom MCP servers carefully because they introduce tools outside the native read-only boundary and might lack the same controls.

Security architecture

Security for agentic workloads operates across three layers: Infrastructure, application, and user. Any service that you evaluate must provide controls at each layer. The infrastructure layer governs what agents can reach, the application layer governs what agents can do, and the user layer governs who can invoke agents.

At the infrastructure layer, AgentCore and AWS DevOps Agent take different approaches to access control. For AgentCore-hosted agents, IAM policies control who can create, invoke, and manage runtimes and endpoints. AgentCore Runtime isolates concurrent invocations, and virtual private cloud (VPC) security group integration provides network-level control. Follow the principle of least privilege. Scope IAM policies to specific runtimes, endpoints, and actions that each principal requires, and avoid wildcards. For AWS DevOps Agent, Agent Spaces govern access. Each Agent Space uses IAM roles that define which AWS accounts, services, and resources that the agent can reach. Scope these explicitly by service, resource, and AWS Region. Even though AWS DevOps Agent is read-only by design, unscoped read-only access still poses a risk if the agent can view resources outside its boundary. In both cases, encrypt data in transit and at rest, and require API authentication for all endpoints.

At the application layer, apply the controls from the Prompt injection defense section in this article. These include Cedar-based AgentCore Policy at the Gateway boundary, Guardrails for content filtering and PII masking, and rate limiting with schema-level restrictions on tool inputs and outputs. For AWS DevOps Agent, also allowlist tools and use read-only MCP server credentials.

In addition, shared tools such as logging and monitoring integrations can expose data from multiple teams. Scope their credentials so that each agent or Agent Space accesses only the data within its boundary.

At the user layer, IAM controls who can invoke agents. For AgentCore, IAM policies control which principals can call InvokeAgentRuntime. You can also add user-level authentication by configuring JWT authorizers on your agent endpoints and validating requests at runtime with bearer tokens, JWTs, scopes, and custom claims. For AWS DevOps Agent, IAM actions such as aidevops:SendMessage and aidevops:CreateChat control who can interact with the agent, while aidevops:ListJournalRecords controls who can review investigations. Implement session-based access control, log every action, and require authentication for sensitive operations.

Credential management and blast radius

Consider the blast radius of credential exposure, particularly for system-specific agents and MCP servers. When domain specialists build agents for dedicated systems, such as a load balancer agent, a proxy monitoring agent, or infrastructure agents that access CloudWatch logs, those agents must use isolated credentials scoped to only those systems. Limit permissions to only what the agent needs because any code in an agent’s execution environment can potentially access the credentials available there.

For agents that use Amazon Bedrock AgentCore Identity, a purpose-built identity service handles credential management. It provides a centralized agent identity directory, a token vault that securely stores OAuth 2.0 tokens, API keys, and client and resource credential providers that manage authentication with external services. The token vault encrypts stored credentials with AWS Key Management Service (AWS KMS), including support for customer managed keys. Agents never access long-term secrets directly. AgentCore Identity vends short-lived credentials based on workload identity. It integrates with existing identity providers, with built-in support for Google, GitHub, Salesforce, Slack, Atlassian (Jira), and any OAuth2-compatible providers. It also supports machine-to-machine and user-federation OAuth 2.0 flows. You can scope provider access by workload identity through IAM policies and revoke access centrally without updating individual agents.

Centralized monitoring platforms such as Application Performance Monitoring (APM) services follow a different pattern. They aggregate data from several applications and teams for an MCP server that requires broad access. For these cases, create multiple gateway targets that point to the same MCP server, each with credential provider configurations scoped to specific teams or applications. Combined with IAM policies that control which workload identities reach which targets, each agent receives only the data appropriate to its boundary. Authentication credentials provide system access, and IAM policy enforcement provides data isolation.

AWS DevOps Agent manages credentials through a layered model that’s tied to Agent Spaces. For AWS resources, each Agent Space uses dedicated IAM roles. A primary role for the account where the Agent Space is created, and secondary roles for connected accounts. Use least privilege to scope these roles. For third-party integrations and custom MCP servers, AWS DevOps Agent registers credentials at the account level, so they’re stored once and shared across all Agent Spaces in that account. Each Agent Space connects to selected registered servers and allowlists specific tools, so tool access is scoped per Agent Space, but credentials are not. An account-level Datadog API key with organization-wide read access grants access to any Agent Space that connects to it. To mitigate this, scope credentials at the source with API keys or OAuth scopes restricted to the relevant data. You don't manage credentials in agent code or Lambda functions. The service handles storage, rotation where supported, and injection into the runtime. For AWS DevOps Agent's full security model, see AWS DevOps Agent security.

Regardless of which service you use, rotate credentials regularly, monitor for misuse through CloudTrail and CloudWatch, and create alerts for failed authentication attempts or unusual access patterns. Build a credential revocation runbook in advance for cases where there’s a compromised agent, a leaked credential, or an employee with access to agent configurations leaves. In the runbook, include which credentials to revoke, where they’re stored, who has authority to revoke them, how to verify revocation, and how to confirm that dependent agents have stopped accessing affected systems.

Agent credential identification

Treat agent credentials with the same rigor as service accounts. An agent that authenticates to your monitoring platform, queries your databases, or creates tickets in your ITSM system is functionally a service account acting for your organization.

Adopt a naming convention that makes agent credentials immediately recognizable. A suffix such as _agent or a prefix like svc-agent- on IAM roles, API keys, and OAuth client registrations helps security teams identify agent credentials during audits, incident investigations, and access reviews. When payments_triage_agent appears in CloudTrail or your identity provider's logs, it’s clear that this is an agent credential, not a human user or a traditional service account.

Every agent credential must have a documented owner. The person who created the agent, scoped the IAM role, and registered the OAuth client or API key. A human decided what the agent can access and is accountable for its lifecycle. Record this ownership in your agent registry or the Configuration Management Database (CMDB) alongside the agent's purpose, the systems that it accesses, and the justification for its permissions. When that person changes roles or leaves, ownership must transfer explicitly, as for any other service account.

Apply your existing service account governance to agent credentials. Conduct periodic access reviews to confirm that permissions remain appropriate, create automated alerts when credentials go unused for extended periods (a sign of an orphaned agent), and complete mandatory recertification on a regular cadence. If your organization has a privileged access management program, then include agent credentials in its scope. Agent credentials can be as risky as or even riskier than human ones because they act at machine speed without oversight.

Encryption in transit

Make sure that all data transmitted between agents, MCP servers, and backend systems has encryption in transit through TLS 1.2 at minimum (TLS 1.3 recommended) and follows AWS Well-Architected Framework guidance. Configure security groups to allow only HTTPS traffic to agent endpoints and MCP servers.

For agents that run on AgentCore, encryption in transit is automatic. For AWS DevOps Agent, all data has encryption in transit, both within the agent's private network and to external networks. This encryption covers logs, metrics, knowledge items, ticket metadata, and other operational data. Native integrations with third-party tools (GitHub, Dynatrace, Splunk, and ServiceNow) use each vendor's secure authentication over HTTPS. If you connect custom MCP servers, then make sure that they enforce TLS with valid certificates because they become part of the agent's data path. For custom implementations on Amazon Elastic Kubernetes Service (Amazon EKS), Amazon Elastic Compute Cloud (Amazon EC2,) or Amazon API Gateway, configure HTTP clients to use TLS and validate certificates and use AWS Certificate Manager to manage the certificate lifecycle.

Custom MCP servers connected as external targets through AgentCore Gateway become part of your attack surface. Make sure that they enforce TLS with valid certificates from trusted authorities. Accept only HTTPS connections and implement API authentication, rate limiting, and request logging.

←Back to Main Article | | Previous: Cost management | Next: Organizational readiness: part 1 →

About the Author

Brian Simpson-Adkins

Brian Simpson-Adkins is a Principal Technical Account Manager (TAM) in AWS Global Financial Services. He has over 20 years of experience in architecture, operations, and automation. Based in Australia, he partners with customers worldwide, and helps them resolve operational challenges through data-driven insights.