Skip to main content
Experimental Feature - WASM Policy EngineThis SDK is specifically for writing WASM policies using Chainloop’s experimental WASM policy engine. The WASM policy engine is NOT the default policy engine in Chainloop.
  • Default engine: Rego-based (recommended for most users)
  • WASM engine: Experimental alternative for Go/JavaScript policies
  • Status: Experimental preview - APIs may change in future releases
For the default Rego-based policy engine, see Writing Custom Policies.

Prerequisites

The Chainloop Go SDK for WASM policies is built on top of the Extism Go PDK, which provides the WebAssembly plugin interface. Required tools:
TinyGo compiles Go code to WebAssembly with minimal binary size.
For dependency management and module support.
Dependencies:
  • github.com/chainloop-dev/chainloop/labs/wasm-policy-sdk/go - Chainloop WASM Policy SDK
  • github.com/extism/go-pdk - Extism Plugin Development Kit (auto-installed)
The Extism Go PDK provides the low-level WASM interface, while Chainloop’s WASM Policy SDK provides high-level policy-specific functions for material validation.

Project Setup

Create go.mod

Create policy.yaml

Complete Example

Here’s a complete policy that validates SBOM components:

API Quick Reference

The Go SDK provides functions for:
  • Execution: Run() - Entry point wrapper
  • Material Extraction: GetMaterialJSON(), GetMaterialString(), GetMaterialBytes()
  • Arguments: GetArgs(), GetArgString(), GetArgStringDefault()
  • Results: Success(), Fail(), Skip(), OutputResult(), AddViolation(), HasViolations()
  • Logging: LogInfo(), LogDebug(), LogWarn(), LogError()
  • HTTP Requests: HTTPGet(), HTTPGetJSON(), HTTPPost(), HTTPPostJSON()
  • Artifact Discovery: Discover(), DiscoverByDigest()

Building

Basic Build

Build Flags

  • -target=wasi - WebAssembly System Interface target
  • -o policy.wasm - Output file name

Typical File Sizes

  • Simple policy: ~770KB
  • SBOM policy: ~770KB
  • HTTP policy: ~793KB

Testing

Create Test Script

test.sh:
Make executable:

TinyGo Compatibility

TinyGo has some limitations compared to standard Go: Supported:
  • ✅ Flat structs with simple types
  • ✅ Slices and maps with string keys
  • ✅ json.Unmarshal for parsing
  • ✅ String manipulation
  • ✅ Basic math operations
Limited/Unsupported:
  • ⚠️ Generics (limited support)
  • ❌ Reflection (limited)
  • ❌ Goroutines (limited)

Best Practices

  1. Keep types simple - Use flat structs with concrete types
  2. Validate early - Check input format before complex logic
  3. Return specific violations - Include field names and values in messages
  4. Use skip for non-applicable cases - Don’t fail policies for wrong material types
  5. Test with real data - Use actual SBOMs/attestations from your projects
  6. Log validation progress - Use logging for debugging
  7. Handle errors gracefully - Always check error returns

Next Steps

Examples

See complete policy examples and common patterns

JavaScript SDK

Learn about the JavaScript SDK alternative