chore(policy): Bootstrap WASM policy engine#2584
Merged
javirln merged 5 commits intochainloop-dev:mainfrom Nov 28, 2025
Merged
Conversation
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
jiparis
reviewed
Nov 26, 2025
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
jiparis
reviewed
Nov 27, 2025
| if err != nil { | ||
| return nil, fmt.Errorf("failed to inject boilerplate: %w", err) | ||
| // Inject boilerplate only for Rego policies, not WASM | ||
| if engine.DetectPolicyType(script) == engine.PolicyTypeRego { |
Member
There was a problem hiding this comment.
I wonder if the policy type should be a property of spec. I'm ok if we feel comfortable with this magic detection, but this might not stand in the future if we support more engines (jq or something else), since here ware just detecting that this is NOT WASM, but it might be anything else.
jiparis
approved these changes
Nov 28, 2025
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
Member
Author
|
All comments addressed |
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.
Architecture
The WASM engine is implemented using Extism, a universal plugin system that allows running WebAssembly modules safely across different platforms.
Here's a small video hands on:
showcase-wasm.mov
Key Components
Policy Type Detection
File:
pkg/policies/engine/detect.goAutomatically detects policy type by checking for WASM magic bytes (0x00 0x61 0x73 0x6d). Falls back to Rego for text-based policies. Detection happens transparently at runtime.
WASM Engine
File:
pkg/policies/engine/wasm/engine.goImplements the PolicyEngine interface using Extism Go SDK.
Features:
Policy Execution Flow
Material or attestation is passed to PolicyVerifier, which detects the policy type. For WASM policies, the engine creates an Extism plugin, calls the Execute function, and parses JSON output.
Configuration Options
Common Options
Shared with Rego engine:
WASM-Specific Options
WASM Policy Contract
WASM policies must export an Execute function.
Input: Raw material bytes as input parameter, with arguments accessible via Extism config under "args" key.
Output: JSON object with violations array, skipped boolean, skip_reason string, and ignore boolean.
Error Handling
File:
pkg/policies/engine/wasm/errors.goProvides sophisticated error parsing for:
Security Features
Integration Points
Policy Loader
File:
pkg/policies/policies.goAutomatically selects engine based on detected policy type. For WASM policies, creates engine with logger and common options.
Material Verification
File:
pkg/attestation/crafter/crafter.goWASM policies are evaluated alongside Rego policies with the same violation reporting structure, transparent to users.
Current Limitations
Implementation Details
File Structure
Key Methods
NewEngine creates a new WASM engine with specified options and applies common configuration.
Verify is the main execution method that creates an Extism plugin, configures it, calls the Execute function, and parses results.
MatchesParameters and MatchesEvaluation are stub implementations that delegate to WASM policy internals.