Add AI tools example with SPIFFE identity and in-process OPA/WASM authorization - #269
Merged
Merged
Conversation
…horization A Camel LangChain4j agent whose tools are authorized before they run by an Open Policy Agent policy evaluated in-process as WebAssembly (the camel-opa wasm client), with SPIFFE (camel-spiffe) authenticating the calling workload. It shows prompt-injection containment: a caller talked into asking the model for a refund is denied by the guard, so the refund never happens.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A new
ai-tools-spiffe-opaexample (category AI): a Camel LangChain4j agent whose tools are authorized before they run by an Open Policy Agent policy evaluated in-process as WebAssembly (thecamel-opawasm client), with SPIFFE (camel-spiffe) authenticating the calling workload.The point is prompt-injection containment: a low-trust caller is talked into asking the model for a refund; the model tries the
refundOrdertool, but the in-process guard denies it because that caller is not permitted, so no refund happens. A trusted caller is allowed to refund within a cap.How it works
ai-toolcomponent and driven bylangchain4j-agentagainst a local Ollama model.opa/tools.rego, compiled to a WebAssembly bundle, in-process.evaluationMode=wasmmeans there is no OPA server and no network hop in the middle of the model's reasoning; the runtime is pure-Java (Chicory).Testing
OpaWasmToolGuardTestexercises the real WebAssembly policy allowing/denying each case, fully offline (no LLM, no SPIRE). Runs withmvn verify.opa/tools_test.regohas Rego unit tests (opa test).LlmToolCallingSmokeTest(disabled unlessOLLAMA_SMOKE=true) drives the whole loop against a real Ollama model.docker compose up(SPIRE + assistant + two callers, Ollama on the host): the public chatbot's prompt-injected refund is denied, the support console's refund is allowed.Notes
src/main/resources/opa/tools-bundle.tar.gz) is checked in so the build and tests need no OPA toolchain;build-policy.shrebuilds it fromopa/tools.regousing the OPA container image. A RAT exclusion for**/src/main/resources/opa/*.tar.gzis added to the parent pom.ai-tools-spiffe-opa/README.adocfor how to run it (including a local Ollama with a tool-capable model).