Skip to content

Commit 975bfa0

Browse files
authored
Minor version upgrading OPA/Rego compatibility with new language features, (#208)
crypto/JWT support, and build system improvements. **New Features** - OPA Rego compatibility upgraded from v1.8.0 to v1.14.1. - Added template string interpolation support (`$"Hello {name}!"` and `` $`raw {expr}` ``), including the `internal.template_string` built-in. - Added `array.flatten` built-in. - Added `crypto.*` built-in family: hashing (MD5, SHA1, SHA256), HMAC (MD5, SHA1, SHA256, SHA512), X.509 certificate parsing and verification, RSA key parsing, and key pair parsing. `crypto.x509.parse_and_verify_certificates_with_options` is not yet implemented (no OPA conformance tests exist for it). - Added `io.jwt.*` built-in family: `decode`, `decode_verify`, `encode_sign`, `encode_sign_raw`, and signature verification for HS256/384/512, RS256/384/512, PS256/384/512, ES256/384/512, and EdDSA. EdDSA is only available with the OpenSSL backend. - Added pluggable crypto backend architecture controlled by the `REGOCPP_CRYPTO_BACKEND` CMake option: - `mbedtls` (default) — Mbed TLS v3.6.2, built from source via FetchContent with zero system dependencies on any platform. - `openssl3` — OpenSSL 3.0+ (requires system install). - `bcrypt` — Windows CNG (Windows only, no external dependencies). - `""` — Crypto disabled; crypto/JWT builtins return an error at runtime. - Added Windows CMake presets (`debug-windows`, `release-windows`, `debug-windows-opa`, `release-windows-opa`) using the `bcrypt` backend. - Wrapper builds (Python, Rust, .NET) now pass the crypto backend through to CMake. Python and .NET use `bcrypt` on Windows and `mbedtls` elsewhere; Rust uses `mbedtls` on all platforms. **Bug Fixes** - Fixed `numbers.range_step` behavior to match current OPA expectations. - Fixed `strings.count` with empty substring to return `len(s)+1` instead of looping indefinitely, matching OPA semantics. - Fixed `split` with empty delimiter to split into individual characters, matching OPA semantics. - Fixed JSON object key deduplication to use last-wins semantics, matching Go `json.Unmarshal` and OPA behavior. - Fixed `sprintf` `%v` format to render sets using Rego display syntax (`{1, 2, 3}` / `set()`) instead of internal angle-bracket representation. - Fixed `to_json`/`to_key` rendering of `true`, `false`, and `null` for synthetically constructed AST nodes with empty locations. **Migration Notes** - JSON objects with duplicate keys now keep only the last value for each key ("last-wins" semantics), matching Go `json.Unmarshal` and OPA behavior. Previously, duplicate keys were preserved in the AST. If your data documents or inputs contain duplicate keys and you relied on earlier values being visible, those values will now be silently dropped. - `crypto.x509.parse_and_verify_certificates` follows OPA's convention: the last certificate in the PEM bundle is treated as the leaf (workload) certificate; all others are treated as CA or intermediate certificates. Revocation checking (CRL/OCSP) is not performed, matching OPA behavior. **Build & Infrastructure** - Upgraded Trieste dependency (switched regex engine from RE2 to TRegex). Validated against full OPA conformance test suite including regex patterns. - Removed RE2 from link targets across all build configurations and wrappers. - CI: Windows PR gate job now uses `release-windows-opa` preset. - Added test infrastructure for marking tests as `unsupported` (used for EdDSA tests on non-OpenSSL backends). Signed-off-by: Matthew A Johnson <matjoh@microsoft.com> Signed-off-by: Matthew Johnson <matjoh@microsoft.com>
1 parent a10e095 commit 975bfa0

65 files changed

Lines changed: 12055 additions & 117 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 367 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
name: bump-version
3+
description: 'Bump the rego-cpp version number for a new release. Use when: preparing a release, updating version strings after a tag, or when instructed to bump the version. Updates all version files across the main library and wrapper packages to keep them in sync.'
4+
---
5+
6+
# Bumping the Version
7+
8+
Update all version strings across the rego-cpp project for a new release.
9+
10+
## When to Use
11+
12+
- Preparing a new release (major, minor, or patch)
13+
- After discovering wrapper versions are out of sync with the main VERSION file
14+
- When instructed to bump versions
15+
16+
## Files to Update
17+
18+
Every release requires updating version strings in **all** of the following
19+
locations. Missing any one of them creates a version mismatch between the
20+
library and its wrapper packages.
21+
22+
| File | Field / Pattern | Example |
23+
|------|----------------|---------|
24+
| `VERSION` | Entire file contents | `1.3.0` |
25+
| `wrappers/python/setup.py` | `VERSION = "X.Y.Z"` | `VERSION = "1.3.0"` |
26+
| `wrappers/rust/regorust/Cargo.toml` | `version = "X.Y.Z"` | `version = "1.3.0"` |
27+
| `wrappers/dotnet/Rego/Rego.csproj` | `<Version>X.Y.Z</Version>` | `<Version>1.3.0</Version>` |
28+
29+
## Procedure
30+
31+
1. Read the current version from the `VERSION` file at the repo root.
32+
2. Determine the new version (from user instruction or by incrementing).
33+
3. Update all four files listed above.
34+
4. Verify no other files reference the old version:
35+
```bash
36+
grep -rn '"OLD_VERSION"' wrappers/ VERSION
37+
```
38+
5. Update the CHANGELOG with the new version header if not already present.
39+
40+
## Common Mistakes
41+
42+
- **Forgetting wrapper versions**: The wrapper packages (Python, Rust, .NET)
43+
each have their own version string that must match the main `VERSION` file.
44+
These are easy to miss because they live in different directories and formats.
45+
- **Cargo.lock stale**: After updating `Cargo.toml`, run `cargo update` in the
46+
Rust wrapper directory if a lockfile exists, or CI may fail.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
name: code-review
3+
description: 'Perform a multi-perspective code review of rego-cpp changes. Use when: reviewing a release, auditing a branch diff, evaluating a PR, or performing a pre-merge code review. Launches four parallel review subagents (Security, Performance, Usability, Conservative), verifies key findings, synthesises a unified report with severity-ranked findings, and produces actionable remediation recommendations.'
4+
---
5+
6+
# Multi-Perspective Code Review
7+
8+
Perform a structured code review by examining changes from four independent
9+
perspectives, cross-checking findings against source code, and producing a
10+
unified report with actionable recommendations.
11+
12+
## When to Use
13+
14+
- Before tagging a release
15+
- Reviewing a large branch diff or PR
16+
- Auditing a new subsystem (crypto, parsing, VM changes)
17+
- When a single-perspective review would miss cross-cutting concerns
18+
19+
## Background
20+
21+
A single reviewer tends toward their own bias — a security expert over-flags
22+
performance patterns, a performance expert under-flags input validation. This
23+
skill runs four parallel reviews, each with a strict lens, then synthesises
24+
findings where multiple perspectives converge or provide unique insight.
25+
26+
## Perspectives
27+
28+
| Perspective | Lens | Skill file |
29+
|-------------|------|------------|
30+
| **Security** | Defence in depth, memory safety, bounded resources, error handling, adversarial inputs, C API boundaries, fuzz coverage | [plan-security](../plan-security/SKILL.md) |
31+
| **Performance** | Allocation minimisation, cache-friendly access, pass count, hot-path awareness, algorithmic complexity | [plan-speed](../plan-speed/SKILL.md) |
32+
| **Usability** | Correctness, clarity, naming, WF precision, error message quality, one-concept-per-pass, API ergonomics | [plan-usability](../plan-usability/SKILL.md) |
33+
| **Conservative** | Smallest diff, backwards compatibility, API stability, reuse, no speculative generality, blast radius | [plan-conservative](../plan-conservative/SKILL.md) |
34+
35+
## Procedure
36+
37+
### Step 1: Identify the Diff
38+
39+
Determine the commit range or branch diff to review.
40+
41+
```bash
42+
# Example: changes since last release tag
43+
git diff --stat v1.2.0..HEAD
44+
```
45+
46+
Group changed files by subsystem (parser, builtins, VM, C API, build system,
47+
wrappers) to assign review focus areas.
48+
49+
### Step 2: Launch Four Review Subagents
50+
51+
Spawn four Explore subagents **in parallel**, one per perspective. Each
52+
subagent receives:
53+
54+
1. The same list of changed files and feature summary
55+
2. The perspective-specific review lens (from the table above)
56+
3. Specific files to examine based on the subsystem grouping
57+
4. Instructions to classify findings by severity and provide file/line references
58+
59+
**Prompt template for each subagent:**
60+
61+
> You are performing a {PERSPECTIVE}-focused code review of rego-cpp.
62+
> The changes add: {FEATURE_SUMMARY}.
63+
>
64+
> Your review lens: **{LENS_DESCRIPTION}**
65+
>
66+
> THOROUGHNESS: thorough
67+
>
68+
> Please examine these files and report findings:
69+
> {FILE_LIST_WITH_SPECIFIC_QUESTIONS}
70+
>
71+
> For each finding, classify severity as {SEVERITY_SCALE} and provide the
72+
> file path and approximate line numbers. Return a structured report.
73+
74+
Severity scales per perspective:
75+
- **Security**: CRITICAL / HIGH / MEDIUM / LOW / INFO
76+
- **Performance**: HIGH / MEDIUM / LOW impact
77+
- **Usability**: CONCERN / SUGGESTION / POSITIVE
78+
- **Conservative**: BREAKING / HIGH-RISK / MEDIUM-RISK / LOW-RISK / OK
79+
80+
### Step 3: Verify Key Findings
81+
82+
After collecting all four reports, identify the highest-severity findings and
83+
**spot-check them against source code**. Launch a verification subagent:
84+
85+
> For each claim below, read the relevant code and report whether the claim
86+
> is CONFIRMED, PARTIALLY CONFIRMED, or REFUTED. Provide exact code evidence.
87+
> {LIST_OF_CLAIMS_TO_VERIFY}
88+
89+
This step prevents false positives from propagating into the final report.
90+
Mark any unverifiable claims as such.
91+
92+
### Step 4: Synthesise the Report
93+
94+
Produce a unified report with these sections:
95+
96+
#### Convergence
97+
Where two or more perspectives agree on the same finding. High convergence
98+
indicates high confidence.
99+
100+
#### Findings by Severity
101+
A single table combining all verified findings, normalised to a unified
102+
severity scale:
103+
104+
| Unified Severity | Mapping |
105+
|-----------------|---------|
106+
| CRITICAL / HIGH | Security CRITICAL/HIGH, Performance HIGH, Usability CONCERN (correctness bug), Conservative BREAKING |
107+
| MEDIUM | Security MEDIUM, Performance MEDIUM, Usability CONCERN (non-correctness), Conservative HIGH-RISK |
108+
| LOW | Security LOW, Performance LOW, Usability SUGGESTION, Conservative MEDIUM-RISK |
109+
110+
Each finding gets: number, description, originating perspective(s), verification
111+
status, file path and line references.
112+
113+
#### Positive Highlights
114+
Things the code does well, called out by any perspective. This provides
115+
balanced feedback and reinforces good patterns.
116+
117+
#### Recommendations
118+
Ordered by priority. Split into:
119+
- **Before release**: correctness bugs, UB, security issues
120+
- **After release**: performance optimisation, tech debt, hardening
121+
122+
#### Trade-offs
123+
Where perspectives conflict (e.g., security wants more validation, performance
124+
wants less overhead), state the conflict and the recommended resolution.
125+
126+
### Step 5: Calibrate Against Existing Test Coverage
127+
128+
Before finalising recommendations, check whether existing test suites
129+
(OPA conformance tests, regocpp.yaml, fuzzer) already cover the flagged
130+
scenarios. The OPA test suite is comprehensive — findings about "missing
131+
test coverage" must be verified against:
132+
133+
```bash
134+
# List OPA test suites
135+
ls build/opa/v1/test/cases/testdata/v1/
136+
137+
# Check specific suite coverage
138+
grep 'note:' build/opa/v1/test/cases/testdata/v1/{suite}/*.yaml
139+
```
140+
141+
Drop or downgrade recommendations that duplicate existing OPA coverage.
142+
143+
## Output Format
144+
145+
The final report should be a structured markdown document (presented in chat,
146+
not saved to a file unless requested) with the sections described in Step 4.
147+
148+
## Reference
149+
150+
- [Example remediation plan from v1.3.0 review](./references/v1.3.0-remediation-plan.md)
151+
a concrete example of findings and the resulting fix plan.

0 commit comments

Comments
 (0)