Skip to content

feat: initial APL Rust implementation.#60

Merged
araujof merged 23 commits into
devfrom
feat/apl_rust
Jun 5, 2026
Merged

feat: initial APL Rust implementation.#60
araujof merged 23 commits into
devfrom
feat/apl_rust

Conversation

@terylt

@terylt terylt commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

feat/apl_rust — APL policy engine, identity stack, and pluggable IAM for CPEX Rust

This branch turns the Phase-1a CPEX Rust core into a full policy-driven, identity-aware plugin runtime — a Rust port of the Python apl-plugins design, with the conditional-effects work (when/do/parallel/taint) and the typed-hook plumbing the original lacked.

Closes: #23

Scope: 24 commits, 240+ files, ~70k LOC. Tests: 746 across the workspace, 0 fail.


What's new — at a glance

Layer Crate(s) What it does
Policy language apl-core YAML → IR compiler + async evaluator. Predicates, field pipelines (mask, redact, omit, hash), conditional effects (when:/do:), sequential:/parallel:, content effects, PDP calls, taints, delegation.
CMF bridge apl-cmf Maps cpex-core::Extensions → APL's flat AttributeBag (role.*, perm.*, delegation.*, args.*, result.*, session.*) so predicates can read typed identity without knowing the shape of the underlying extension.
CPEX↔APL boundary apl-cpex The string-typed PluginInvoker / DelegationInvoker trait implementations that bridge APL's evaluator into typed CPEX hook dispatch (invoke_named::<CmfHook>, ::<TokenDelegateHook>). Owns the request-scoped CmfPluginInvoker, the route dispatch plan cache, the session store, and the synthetic AplRouteHandler plugin that wraps APL eval into a normal cpex-core plugin.
Concurrency primitive cpex-orchestration Shared run_branches helper — JoinSet + abort_on_deny + per-branch timeout. Used by both cpex-core::executor::run_concurrent_phase and apl-core::dispatch_parallel.

Identity & delegation

A first-class identity story, distinct from "auth happens upstream":

  • SubjectExtension / WorkloadIdentity in cpex-core::extensions::security model end-user, calling agent, and our gateway as separate typed identities — the basis for predicates like require(role.hr), perm.view_ssn, and the new identity-derived session id.
  • DelegationExtension + the TokenDelegateHook hook type carry an arbitrary chain of acting subjects with attenuated grants. Surfaces in APL as delegation.depth, delegation.chain[*], delegation.granted_permissions.
  • apl-identity-jwt — JWT identity resolver with configurable claim mapping. Reads sub / act.sub / aud / roles / permissions into the structured extensions; raw claims preserved in subject.claims for tier-1 session resolution.
  • apl-delegator-oauth — RFC 8693 token exchange. The mint-on-demand path: APL writes delegate(workday-oauth, audience: workday-api, permissions: [...]), the delegator hits the IdP, and the outbound request carries a freshly-minted audience-scoped token — never the user's original IdP JWT.
  • apl-delegator-biscuit — Biscuit-based delegation as an alternative to OAuth token-exchange. Reference implementation for IETF draft-prakash-aip-00 (Agent Identity Protocol) "Chained Mode."
  • 5-tier SessionResolver (apl-cpex/src/session_resolver.rs) — agent.session_id → JWT session_id claim → X-CPEX-Session-Id header → sha256(sub:caller:gateway)[:16] → none. Ported from Python apl-plugins, with the agent-tier added so plugins can inject pre-resolved session ids without inventing a new API.

PDP integration

APL can defer decisions to an external policy engine via a pdp(...) step. Two backends ship:

  • apl-pdp-cedar-direct — In-process Cedar evaluation against an embedded policy store. Fast (no network) for tightly-coupled use cases.
  • apl-cedarling — Cedarling-mediated (Janssen) Cedar evaluation. Adds signed policy stores, multi-issuer JWT validation, and (with Lock Server) centralized policy management. Pluggable via the PdpDialect enum so both can coexist on the same route.

Plugin ecosystem (proof the framework actually composes)

  • apl-pii-scannercmf.tool_pre_invoke plugin that catches SSN/credit-card/etc. patterns in args. Returns PluginViolation with code pii.detected.
  • apl-audit-loggercmf.tool_pre_invoke audit plugin that logs every dispatch including denied ones. Demonstrates the audit/non-blocking plugin pattern.
  • All plugins use the framework-native PluginError + PluginViolation types, follow the PluginConfig-only constructor convention, and live as their own crates with their own PluginFactory impls.

CPEX core changes

The runtime needed several enhancements to support the APL stack. These landed as standalone, generally-useful improvements:

  • Effect IR consolidation (E4): Step enum collapsed into Effect. policy: is now Vec<Effect> directly. One IR vocabulary, one dispatch path (dispatch_effect), one static validator walk.
  • Effect::Sequential / Effect::Parallel orchestration (E3): Side-effect lists run in-order-with-halt or concurrently-with-abort-on-deny. Built on the new cpex-orchestration::run_branches. Static parallel-purity validator rejects mutation effects inside parallel blocks at config-load.
  • Plugin-mode validation (E3.1): Route-compile-time check that plugins inside parallel: blocks are registered with safe modes (Audit / Concurrent / FireAndForget). Sequential / Transform plugins are rejected — their writes would silently vanish in a discarded branch.
  • Executor concurrent-phase refactor (E3.3): cpex-core::executor::run_concurrent_phase migrated from its custom JoinSet machinery to the shared run_branches. Fixed a latent panic-index attribution bug in the process.
  • Session-scoped taint persistence (TS1): Effect::Taint { scopes: [Session] } now actually labels the session. New CmfPluginInvoker::apply_session_taints drains RouteDecision.taints into security.labels; the existing persist_session diff catches them and writes to the SessionStore. Closes the "policy with side-effects" pitch — writing taint(audit, session) in YAML actually causes the session to be permanently labelled and observable in subsequent requests.

Testing

Tier Count
apl-core unit + IR + parser + evaluator 280+
apl-cmf end-to-end + bridge ~40
apl-cpex invokers + visitor + plan + resolver ~80
cpex-core runtime + executor + hooks 282
cpex-orchestration 7
apl-pdp-cedar-direct, apl-cedarling, apl-pii-scanner, apl-audit-logger, apl-delegator-*, apl-identity-jwt ~50 combined
Total 746 / 0 fail

Migration notes / breaking changes

  • apl-core public API switched from evaluate_steps(&[Step], ...) to evaluate_effects(&[Effect], ...). Step is now a parser-internal pub(crate) type. Callers building Vec<Step> should switch to Vec<Effect> (Effect::When { condition, body, source } replaces Step::Rule(Rule)).
  • Invoker trait refs widened from &dyn PluginInvoker to &Arc<dyn PluginInvoker> (same for DelegationInvoker and PdpResolver) so Effect::Parallel can spawn branches across OS threads. Consumers holding concrete types (e.g. Arc::new(CmfPluginInvoker::for_request(...))) need a one-line upcast: let invoker_dyn: Arc<dyn PluginInvoker> = invoker.clone();.
  • Session ID resolution: CmfPluginInvoker no longer pulls only from extensions.agent.session_id. The 5-tier resolver kicks in. Existing callers that only set agent.session_id still work — it's tier 0, highest priority.

@terylt terylt requested review from araujof and jonpspri as code owners June 3, 2026 15:04
araujof and others added 10 commits June 3, 2026 14:45
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

@araujof araujof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Tested with Praxis and AuthBridge integrations.

@araujof araujof merged commit 8804b35 into dev Jun 5, 2026
12 checks passed
@araujof araujof deleted the feat/apl_rust branch June 5, 2026 20:37
@araujof araujof added the enhancement New feature or request label Jun 5, 2026
@araujof araujof self-assigned this Jun 5, 2026
@araujof araujof added this to CPEX Jun 5, 2026
@github-project-automation github-project-automation Bot moved this to Done in CPEX Jun 5, 2026
@araujof araujof added this to the 0.2.0 milestone Jun 5, 2026
@araujof araujof linked an issue Jun 5, 2026 that may be closed by this pull request
@araujof araujof mentioned this pull request Jun 10, 2026
2 tasks
araujof added a commit that referenced this pull request Jun 10, 2026
* fix: initial revision APL.

* feat: apl-cpex bridge crate + plugin-registry-driven hook dispatch

* feat: add support for plugin calling in APL routes.

* feat: add more APL plugin support, unified config

* feat: added cedar direct PDP.

* feat: add identity hook and extensions.

* feat: added token delegation hooks and tests.

* feat: added plugin for jwt token identity, oauth and biscuit delegation, cedarling PDP.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: updated identity and delegation to support keycloak. added delegate() function, and identity sections.

* fix: added some sample plugins, added updates to support cedar.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added session support, serialize and parallel and full effects capabilities.

* feat: add ffi pre-built .a library

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add workflow_dispatch target

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: critical and high issues from review.

* feat: add APL FFI and go bindings

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add musl tools to musl runners

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: potential double free after use bug.

* chore: update Go module paths after repo rename to cpex

* feat: map identity extension into cpex ffi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat: add cpex_invoke_resolved abi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: has_hook_for handling

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: update headers

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>
araujof added a commit that referenced this pull request Jun 10, 2026
* feat: initial Rust Core (cpex-core and cpex-sdk) (#13)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: CPEX Rust config (#38)

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat:  RUST with CMF and extensions. (#44)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat: cgo Go bindings (#45)

* feat: initial revision rust core.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: addressed comments in PR. Updated PluginContext to match spec.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added yaml and routing rule support.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added example code to show how to load manager and plugins.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fixes: updated plugin errors, configs to more match python.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: RUST CMF initial revision.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added invoke named support, added constants, fixed reviewed code.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added owned extensions and did some refactoring.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added cgo and golang bindings, examples and readme.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* address P0/P1/P2 review findings (except #17)

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: address remaining P2/P3 review findings + testing gaps

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* docs: add CPEX Go public API spec

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* docs: renamed document

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat(cpex-rust): CGO review passes 1-11 + lint cleanup + Makefile targets

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: address linting issues, updated makefile to support building examples.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* docs: updated the go spec to reflect recent changes.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* docs: intial rust specification (#50)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: change Plugin handler to async for performance (#49)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* fix: missing cmf-demo main.go file and gitignore fix that missed it (#52)

Co-authored-by: Teryl Taylor <terylt@ibm.com>

* feat: initial APL Rust implementation (#60)

* fix: initial revision APL.

* feat: apl-cpex bridge crate + plugin-registry-driven hook dispatch

* feat: add support for plugin calling in APL routes.

* feat: add more APL plugin support, unified config

* feat: added cedar direct PDP.

* feat: add identity hook and extensions.

* feat: added token delegation hooks and tests.

* feat: added plugin for jwt token identity, oauth and biscuit delegation, cedarling PDP.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* fix: updated identity and delegation to support keycloak. added delegate() function, and identity sections.

* fix: added some sample plugins, added updates to support cedar.

Signed-off-by: Teryl Taylor <terylt@ibm.com>

* feat: added session support, serialize and parallel and full effects capabilities.

* feat: add ffi pre-built .a library

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add workflow_dispatch target

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: critical and high issues from review.

* feat: add APL FFI and go bindings

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: add musl tools to musl runners

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: potential double free after use bug.

* chore: update Go module paths after repo rename to cpex

* feat: map identity extension into cpex ffi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* feat: add cpex_invoke_resolved abi

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: has_hook_for handling

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: update headers

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com>

* fix: session binding

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* chore: updated comments

Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>

* tests: added more session tests for Tier 1 ids.

---------

Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Co-authored-by: terylt <30874627+terylt@users.noreply.github.com>
Co-authored-by: Teryl Taylor <terylt@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE]: APL + Cedarling integration as built-in plugins

2 participants