Skip to content

CallPact ACL demo

Shows how apcore Access Control Lists (ACL) gate calls to CallPact's CliModule-wrapped commands — the same orders.delete (admins only) / orders.list (public read) contract used across the apcore framework integrations (see axum-apcore/examples/acl_demo).

What it shows

Call Roles Result
orders.delete (none — anonymous) denied
orders.delete user denied
orders.delete admin ACL allows the request. Core denies execution without approval.
orders.list (any) allowed (read is public)

How it works

  1. build_demo_executor() registers two CallPact CliModules with explicit IDs — orders.delete (destructive: true, requires_approval: true) and orders.list (readonly: true) — via the exact pipeline callpact scan produces: build a ScannedModule, write it as a .binding.yaml with YamlOutput, then load it back through callpact::module::build_executor with acl.yaml attached — the same function callpact serve --acl and callpact a2a --acl call under the hood.
  2. Each call is made with an explicit apcore::Context built from an Identity carrying zero, one, or the admin role (ctx_with_roles), directly against Executor::call(...).
  3. The SDK returns ACLDenied for a denied role and ApprovalDenied when an admitted destructive call has no approval handler.

acl.yaml (first-match-wins, default_effect: deny):

  • admins (roles: [admin]) may call any module;
  • anyone (including anonymous) may call orders.list;
  • everything else falls through to deny.

orders.delete is also marked requires_approval: true. ACL and approval are independent gates: this demo builds the executor with enable_approval: false. APCore 0.34.1 blocks an admin's call at the approval gate after the ACL admits it. callpact serve --enable-approval provides an interactive approval path with a compatible MCP client. The callpact a2a command has no interactive elicitation transport, so it does not expose an --enable-approval flag; A2A approval is a library-only integration using an ApprovalStore.

Run it

cargo run --example acl_demo
=== orders.delete (admins only) ===
  admin     -> DENIED (ApprovalDenied)
  user      -> DENIED (ACLDenied)
  anonymous -> DENIED (ACLDenied)

=== orders.list (public read) ===
  admin     -> ALLOWED
  user      -> ALLOWED
  anonymous -> ALLOWED

Or run the equivalent assertion as a test:

cargo test --example acl_demo

This is not the only boundary

The ACL decides who may call which module. It cannot decide what one call may touch — apcore rules match on callers and targets (module ids), and every registered condition key is a fact about the principal, never about an argument. So an ACL can say "cli.rm is allowed" or "denied", and nothing in between.

The path guard covers that second axis, and unlike this demo's rules it is on by default on every surface with no flag to enable it. See examples/path_guard for the same treatment of that layer.

Why this calls Executor::call directly instead of curling a server

apcore's ACL engine is transport-agnostic — it evaluates whatever Context::identity.roles the caller passes in, regardless of whether that call came from a library, an MCP tool invocation, or an A2A task. This demo exercises that engine directly (like axum-apcore/examples/acl_demo's own test does), which is also exactly what embedding CallPact as a library looks like (see examples/programmatic.rs).

The CLI also supports token/JWT transport authentication. Token mode shares one principal; JWT supplies subjects and roles to the executor. To apply this role policy over MCP/A2A, configure JWT credentials and role-based ACL conditions; callers matches the module call chain rather than JWT subjects. The library example supplies its context directly and does not configure that transport. See authenticated caller identities.