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, and module 16 additionally needs the SPIRE overlay it describes.
  • The code lives in examples/tutorial. Run a module with cargo run -p cpex-tutorial --example m01_hello.

Budget 15 to 25 minutes per module: about 3 to 4 hours for modules 0 to 10 and the capstone, which are the core path. Modules 11 to 18 are deep dives on organizing policy and on identity and delegation; take them in any order, or skip to the capstone and come back.

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
11Organizing policy (Groups)Factor shared identity/authz into reusable bundles routes joinyes
12Delegation subjectsMint a downstream token as the caller (user) or as the gateway itself (this_workload)yes
13Delegation as a clientScope an agent’s own client token with subject: client (cookbook Recipe 5)yes
14Passthrough (forward, don’t mint)When to forward the caller’s token unchanged instead of exchanging it (cookbook Recipe 4)yes
15Dual-principal (subject + actor)Mint on behalf of a user while naming the acting agent, subject: user, actor: client (cookbook Recipe 6)yes
16Workload identity (SVID)An agent authenticates by SPIFFE SVID; CPEX brokers a scoped token in two legs, subject: caller_workload (cookbook Recipe 2)yes + SPIRE
17Multi-issuer (trust federation)Accept callers from more than one IdP with one resolver, each validated on its own keysyes
18Static attributes (data.*)Feed policy operator-maintained facts from a data file, read per request as data.*yes
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.