| name | opa-toolchain |
| description | This skill should be used when the user asks about "opa cli", "opa eval", "opa build", "opa check", "opa fmt", "regal lint", "opa bundle", "opa bench", "opa run", or mentions OPA tooling, CI/CD pipeline integration for OPA, or Rego linting. Provides OPA CLI and ecosystem tooling reference. |
OPA Toolchain
Reference for the OPA CLI, Regal linter, and ecosystem tooling. Covers the complete policy development lifecycle from authoring through deployment.
OPA CLI Reference
Core Commands
| Command | Purpose | Common Flags |
|---|
opa eval | Evaluate a Rego query | -d, -i, --format, --explain, --partial |
opa test | Run unit tests | -v, --coverage, --threshold, --run, --bench |
opa check | Validate syntax | --strict, --schema, -b |
opa fmt | Format Rego files | -w (write), --rego-v1 (migrate) |
opa build | Create bundles | -b, -o, --optimize, --target |
opa run | REPL or server | --server, --addr, -b |
opa bench | Benchmark queries | --benchmem, -d, -i |
opa inspect | Analyze bundles | (bundle path) |
opa sign | Sign bundles | --signing-key, --signing-alg |
opa exec | Batch evaluate | -b, --decision |
opa deps | Show dependencies | -d |
opa parse | Show AST | --format json |
Evaluation
opa eval -d policy.rego -i input.json "data.authz.allow"
opa eval -d policy.rego -i input.json "data.authz.allow" --format pretty
opa eval -d policy.rego -i input.json "data.authz.allow" --explain=notes
opa eval -d policy.rego -i input.json "data.authz.allow" --explain=full
opa eval -d policy.rego -i input.json "data.authz.allow" --profile
opa eval -d policy.rego --partial -i input.json "data.authz.allow"
opa eval -b bundle/ -i input.json "data.authz.allow"
Syntax Checking
opa check policy.rego
opa check --strict policy.rego
opa check --schema schema/ policy.rego
opa check ./policies/
opa check -b bundle/
Formatting
opa fmt policy.rego
opa fmt -w policy.rego
opa fmt -w ./policies/
opa fmt --rego-v1 -w policy.rego
opa fmt -l ./policies/
Bundle Management
Bundles package policies and data for distribution.
Build
opa build -b ./policies/ -o bundle.tar.gz
opa build -b ./policies/ -o bundle.tar.gz --optimize=1
opa build -b ./policies/ --entrypoint authz/allow -o bundle.tar.gz
opa build -b ./policies/ --target wasm --entrypoint authz/allow -o policy.wasm
Sign and Verify
openssl genrsa -out key.pem 2048
openssl rsa -in key.pem -pubout -out pubkey.pem
opa sign --signing-key key.pem --bundle bundle.tar.gz
Inspect
opa inspect bundle.tar.gz
Bundle Structure
bundle.tar.gz
├── data.json # Static data
├── policies/
│ ├── authz.rego
│ └── helpers.rego
├── .manifest # Bundle metadata
└── .signatures.json # Cryptographic signatures
Regal Linter
Regal is the official Rego linter with 60+ rules.
Installation
brew install styrainc/packages/regal
go install github.com/styrainc/regal@latest
- uses: styrainc/setup-regal@v2
Usage
regal lint ./policies/
regal lint policy.rego
regal lint --format json ./policies/
regal fix ./policies/
Configuration
Create .regal/config.yaml:
rules:
style:
opa-fmt:
level: error
prefer-some-in-iteration:
level: error
use-assignment-operator:
level: error
bugs:
constant-condition:
level: error
unused-return-value:
level: error
testing:
test-outside-test-package:
level: warning
imports:
prefer-package-imports:
level: warning
custom:
naming-convention:
level: warning
conventions:
- pattern: "^[a-z_][a-z0-9_]*$"
targets:
- rule
- function
Key Rule Categories
| Category | Focus |
|---|
bugs | Logic errors, constant conditions, unused values |
style | Formatting, naming, operator usage |
imports | Import organization, redundancy |
testing | Test file conventions, coverage |
performance | Inefficient patterns |
custom | User-defined naming and style rules |
Regal Language Server
Regal provides LSP support for IDE integration:
| Feature | Description |
|---|
| Diagnostics | Real-time linting warnings/errors |
| Completion | Rule names, built-ins, packages |
| Hover | Documentation for built-in functions |
| Go to definition | Navigate to rule/function definitions |
| Code actions | Quick fixes for linting issues |
| Formatting | opa fmt integration |
Benchmarking
opa bench -d policy.rego -i input.json "data.authz.allow"
opa bench -d policy.rego -i input.json "data.authz.allow" --benchmem
Environment Variables
OPA CLI commands support env var overrides:
export OPA_EVAL_STRICT=true
export OPA_CHECK_STRICT=true
export OPA_FMT_REGO_V1=true
CI/CD Pipeline Integration
- name: Setup OPA
uses: open-policy-agent/setup-opa@v2
with:
version: latest
- name: Setup Regal
uses: styrainc/setup-regal@v2
- name: Check Syntax
run: opa check --strict ./policies/
- name: Lint
run: regal lint ./policies/
- name: Test with Coverage
run: opa test ./policies/ -v --coverage --threshold 80
- name: Build Bundle
run: opa build -b ./policies/ -o bundle.tar.gz
Additional Resources
Reference Files
references/opa-server.md - OPA server mode, REST API, management APIs (bundles, decision logs, status)
references/ci-cd-patterns.md - Detailed CI/CD integration patterns for GitHub Actions, GitLab CI, Jenkins, ArgoCD