CPEX Tutorial#

A self-paced tutorial. You build a policy enforcement point in front of an agent’s tools, one capability at a time, and watch policy decide every outcome. Every module is a runnable program you can edit, break, and re-run.

By the end you can put CPEX in front of your own tools, write APL for them, extend it with a custom plugin, and test your policy.

What you’ll build#

The running example is the scenario from the Overview: one agent, three backends (HR records, source repos, outbound email), and three callers whose requests get different treatment. The docs describe that scenario. Here you build it, finishing with a capstone that reconstructs it end to end.

One idea repeats in every module: the application never changes. Only the policy changes.

Before you start#

  • Rust 1.96 or newer, and Cargo.
  • A container runtime with compose (Rancher Desktop, Podman, or Docker Desktop). You need it from module 2 on, where a real Keycloak resolves tokens. Modules 0 and 1 need only Rust.
  • The code lives in examples/tutorial. Run a module with cargo run -p cpex-tutorial --example m01_hello.

Budget about 3 to 4 hours total, 15 to 25 minutes per module.

Modules#

#ModuleYou’ll learnIdP?
0Setup & orientationWhat CPEX is; verify your setupno
1Hello, enforcementStand up an enforcement point; a route with require(); allow vs. denyno
2Who’s calling? (Identity)Resolve real JWTs from Keycloak into roles and permissionsyes
3Shaping dataresult: field pipelines that redact and mask per permissionyes
4Effects & sequencingOrdered effects, halt-on-deny, custom deny codes, auditingyes
5Delegating decisions (PDP)Hand a decision to CEL or Cedar; CPEX enforces the verdictyes
6Scoped credentials (Delegation)Mint a downstream-scoped token via RFC 8693 exchangeyes
7Information flow (Tainting)Carry session state across requests; block write-downyes
8Human in the loopSuspend an operation for human approval, then resumeyes
9Write your own pluginBuild a custom plugin with the SDK; reference it from policyno
10Testing your policyTable-driven allow/deny tests that run in CIno
CCapstone: the three-backend agentAssemble every control into the full Overview scenarioyes

Start at module 0.

How each module is structured#

Every module page follows the same shape. Goal states what you can do after it in one sentence. The problem shows a concrete failure. Build it shows the policy change. Run it gives the command and expected output. Try it lists guided edits, each with the outcome to expect. Checkpoint is a short self-check. Go deeper links to the reference.