Secure AI agents with Policy in Amazon Bedrock AgentCore
TL;DR: AI agents accelerate automation but widen the attack surface for data leaks and unauthorized actions. Enforce deterministic access controls outside the agent by evaluating Cedar policies at the AgentCore Gateway. That gives identity-aware, auditable, runtime enforcement — useful for protecting PHI, financial flows, and other sensitive operations while retaining agent automation.
Why agent security matters
AI agents combine large language model (LLM) reasoning with real-world tool use: they call APIs, read databases, and take actions on behalf of users. That autonomy is powerful for AI automation, but it also creates new risks. Examples worth keeping on the radar:
- Prompt injection causes an agent to leak sensitive data or reveal credentials.
- An agent books or cancels transactions without proper authorization.
- An LLM hallucinates parameters that trigger operations on the wrong resource (e.g., wrong patient record).
“An agent’s autonomy is its strength and its security risk — it can call tools, access data, and act on its own reasoning, so boundaries matter.”
Treating security as scattered checks inside prompts or application code makes audits and enforcement brittle. A more pragmatic architecture is to externalize authorization: enforce policies at the gateway that mediates every agent-to-tool request.
What AgentCore + Cedar solves
Amazon Bedrock AgentCore introduces an external, runtime-enforced policy layer evaluated by the AgentCore Gateway (the runtime gatekeeper that intercepts agent tool calls). Cedar is the declarative policy language used to express who can do what on which resources under which conditions.
Key properties of Cedar and policy enforcement:
- Default deny: Nothing runs unless explicitly allowed.
- Forbid wins: Explicit deny rules override permits for hard-stop protections.
- Safe to analyze: Cedar is loop-free, side-effect free, and designed for fast, auditable evaluation.
- Context-aware: Rules can reference identity claims, request metadata, time windows, and other runtime facts.
“Move the policy outside the agent: enforce rules at the gateway so outcomes don’t depend on how the agent reasons or is prompted.”
How it works (textual flow)
Simple runtime flow to visualize:
Agent (reasons & constructs tool call) → AgentCore Gateway (policy engine evaluates Cedar rules) → either Tool execution or Denied (logged & auditable).
Because the policy check happens before any tool executes, no amount of clever prompting or an LLM hallucination can bypass the authorization boundary.
Concrete healthcare example: protecting PHI
Imagine an appointment-scheduling agent for a clinic. Tools available to the agent include getPatient, searchImmunization, getSlots, and bookAppointment. The risks: disclosure of patient records to other users, unauthorized bookings, or after-hours changes.
Three practical policy patterns protect the system:
- Identity-aware reads: Allow getPatient only when the requested patient_id matches the authenticated user’s identity claim.
- Separation of read vs write: Permit fhir:read broadly for clinicians but restrict appointment:write to scoped roles or require additional approval.
- Business-rule forbids: Block slot queries or bookings outside approved hours.
Short pseudo-Cedar examples (conceptual):
# Allow read only when principal.userId == resource.patient_id permit(principal, action::"getPatient", resource) when principal.userId == resource.patient_id; # Forbid slot queries outside business hours (09:00–21:00 UTC) forbid(principal, action::"getSlots", resource) when request.time < "09:00:00Z" || request.time > "21:00:00Z"; # Allow bookAppointment only for principals with appointment:write scope permit(principal, action::"bookAppointment", resource) when principal.scopes contains "appointment:write";
These rules are intentionally explicit. Forbid rules give a hard-stop for high-risk operations; identity and scope checks enforce least privilege. Built-in policy analysis flags rules that are too permissive or block needed functionality before you flip enforcement on.
Safe rollout: observe, validate, enforce
Recommended rollout path to avoid accidental breakage:
- Attach a policy engine to the AgentCore Gateway in LOG_ONLY mode to collect what would have been denied or allowed.
- Review denied calls for false positives and refine policies. Focus first on high-risk paths (writes, PHI access, financial transactions).
- Harden forbid rules for irreversible or highly sensitive actions, then switch those specific checks to enforce mode.
- Move to full enforcement once policy coverage and behavior are stable.
Operational checklist for teams
- Create a policy engine in your AWS account and enable AgentCore Policy in the region where your agents run.
- Define policy ownership and a change-review process (who can author, approve, and deploy policies).
- Map enterprise identity provider claims (Okta/Azure AD/SAML) into AgentCore principals and tags; document claim names and lifecycles.
- Run in LOG_ONLY for 1–2 weeks, then analyze denied vs allowed calls and adjust.
- Instrument metrics and alerts (see next section) and establish an audit log retention policy for compliance.
- Provide rollback plans and automated tests for policy changes to prevent accidental lockout.
Key metrics to monitor
- Denied vs allowed calls (daily): shows policy impact and tuning needs.
- Requests per second and policy-check latency (p50/p95): to detect performance issues.
- Number of policy changes and rollback events: governance health indicator.
- Unusual denied patterns (e.g., sudden spike in denied writes): possible agent compromise or misconfiguration.
Scaling, latency, and cost trade-offs
Runtime policy checks add work to every agent-to-tool call. Consider:
- Latency: Measure added ms at p50/p95 during load tests. Cache non-sensitive policy decisions where safe, but avoid caching that weakens hard-stop forbids.
- Throughput: Test Gateways under expected peak traffic. Policy engines are designed for fast evaluation, but multi-tenant spikes need capacity planning.
- Cost: Evaluate per-request pricing vs. risk reduction. Preventing a single data breach or unauthorized transaction often offsets evaluation costs.
Governance, audit, and compliance
Externalized policies make audits simpler: every denied or allowed call is logged at the Gateway and tied to the deterministic Cedar evaluation. That gives security teams a reproducible trail for regulators. Practical tips:
- Define retention windows for decision logs aligned with compliance needs.
- Store policy versions and change approvals in your governance system (pull requests, signed approvals).
- Use policy analysis to produce attestations showing a rule’s intent and risk profile for auditors.
Limitations and mitigations
- Policy complexity: Large, tangled policies increase the risk of false positives. Mitigate with modular policy design, inheritance, and targeted unit tests.
- Cross-agent workflows: When actions depend on other agents’ state, design explicit cross-agent contracts or introduce human-in-the-loop approvals.
- Multi-region consistency: Replicate policies or use centralized management to avoid drift across regions.
- LLM-induced valid calls: LLMs can still construct syntactically valid calls that pass policy; rely on scopes, parameter validation, and runtime anomaly detection in concert with Cedar checks.
Action plan for executives and engineering leads
- Executives: Sponsor a two-week LOG_ONLY pilot for 1–2 high-risk agents (e.g., PHI access or payments) and appoint a policy owner responsible for approvals and audits.
- Engineering leads: Implement the AgentCore Gateway with a policy engine, map identity claims, and run a thorough test plan that includes latency and throughput tests.
- Security teams: Build policy review checklists, define forbid rules for irreversible actions, and integrate decision logs into SIEM and audit processes.
Where to get started
- Try the amazon-bedrock-agentcore-samples GitHub repo (look for the healthcare appointment agent folder) to see end-to-end examples, sample policies, and deployment scripts.
- Review Cedar policy language documentation and AgentCore Gateway docs to align policy authoring with your identity model and risk profile.
- Start small: protect one class of sensitive operations (e.g., appointment writes or payment transactions) and expand coverage iteratively.
Externalizing authorization into Cedar policies evaluated at the AgentCore Gateway creates a predictable, auditable security boundary for AI agents. It’s not a silver bullet — governance, scale, and identity mapping still require careful design — but it turns agent autonomy from a compliance headache into a controllable business capability. Run a LOG_ONLY pilot, tighten forbid rules around high-risk actions, and you’ll have a practical path to safe AI automation.