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¶
build_demo_executor()registers two CallPactCliModules with explicit IDs —orders.delete(destructive: true, requires_approval: true) andorders.list(readonly: true) — via the exact pipelinecallpact scanproduces: build aScannedModule, write it as a.binding.yamlwithYamlOutput, then load it back throughcallpact::module::build_executorwithacl.yamlattached — the same functioncallpact serve --aclandcallpact a2a --aclcall under the hood.- Each call is made with an explicit
apcore::Contextbuilt from anIdentitycarrying zero, one, or theadminrole (ctx_with_roles), directly againstExecutor::call(...). - The SDK returns
ACLDeniedfor a denied role andApprovalDeniedwhen 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¶
=== 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:
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.