-
Notifications
You must be signed in to change notification settings - Fork 22
feat(opa-proto): support proto-format plan bundles (opa build --format=proto) #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sspaink
merged 11 commits into
open-policy-agent:main
from
sspaink:worktree-proto-plan-bundles
Jul 30, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f1b546e
feat(opa-proto): support proto-format plan bundles (opa build --forma…
sspaink 5096a1c
ci: pin actions and disable credential persistence in verify-proto-ve…
sspaink ee144d4
refactor(opa-services): simplify tar entry handling per review
sspaink e143708
refactor(opa-evaluator): resolve proto decoder eagerly per review
sspaink 0eb2491
test(opa-proto): consolidate similar cases into parameterized tests
sspaink 59fc8a8
chore(cli): drop redundant opa-proto dependency comment per review
sspaink 1b10ca0
test(opa-proto): add proto decoder coverage across the compliance suite
sspaink 8ba70b3
ci: run opa-proto tests on pull requests
sspaink 639abd9
test(opa-proto): reference parameterized labels in assertion messages
sspaink 2ddb847
ci: align pinned action SHAs in the proto jobs with main
sspaink 404514c
chore(opa-proto): drop the temporary-OPA-pin workarounds
sspaink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
86 changes: 86 additions & 0 deletions
86
opa-evaluator/src/main/java/io/github/open_policy_agent/opa/bundle/BundleFormat.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package io.github.open_policy_agent.opa.bundle; | ||
|
|
||
| /** | ||
| * Constants and validation for the two on-disk bundle wire formats. | ||
| * | ||
| * <p>OPA's {@code opa build} emits plan bundles in either JSON (the default) or protobuf form. The | ||
| * two forms use distinct filenames for the plan and manifest: | ||
| * | ||
| * <table border="1"> | ||
| * <caption>Format-specific filenames</caption> | ||
| * <tr><th>Artifact</th><th>JSON</th><th>Proto</th></tr> | ||
| * <tr><td>Plan</td><td>{@code plan.json}</td><td>{@code plan.pb}</td></tr> | ||
| * <tr><td>Manifest</td><td>{@code .manifest}</td><td>{@code .manifest.pb}</td></tr> | ||
| * </table> | ||
| * | ||
| * <p>Data files ({@code data.json}) are JSON in both forms; only the plan and manifest change. | ||
| * | ||
| * <p>OPA rejects bundles whose plan and manifest formats disagree (e.g. {@code plan.pb} paired with | ||
| * a JSON {@code .manifest}). {@link BundleLoader} implementations call {@link #validate} to enforce | ||
| * the same rule and to reject bundles that ambiguously contain both formats of the same artifact. | ||
| */ | ||
| public final class BundleFormat { | ||
|
|
||
| /** Filename of a JSON-format IR plan. */ | ||
| public static final String PLAN_JSON = "plan.json"; | ||
|
|
||
| /** Filename of a protobuf-format IR plan. */ | ||
| public static final String PLAN_PROTO = "plan.pb"; | ||
|
|
||
| /** Filename of a JSON-format bundle manifest. */ | ||
| public static final String MANIFEST_JSON = ".manifest"; | ||
|
|
||
| /** Filename of a protobuf-format bundle manifest. */ | ||
| public static final String MANIFEST_PROTO = ".manifest.pb"; | ||
|
|
||
| private BundleFormat() {} | ||
|
|
||
| /** | ||
| * Reject bundles that mix the two wire formats. | ||
| * | ||
| * <p>Fails if a bundle contains both formats of the same artifact (e.g. both {@code plan.json} and | ||
| * {@code plan.pb}), or if a plan and a manifest are present in disagreeing formats (e.g. a proto | ||
| * plan with a JSON manifest), matching OPA's own auto-detection semantics. A bundle carrying only | ||
| * a plan or only a manifest is always accepted. | ||
| * | ||
| * @param hasPlanJson whether a {@code plan.json} is present | ||
| * @param hasPlanProto whether a {@code plan.pb} is present | ||
| * @param hasManifestJson whether a {@code .manifest} is present | ||
| * @param hasManifestProto whether a {@code .manifest.pb} is present | ||
| * @throws IllegalArgumentException if the bundle mixes formats | ||
| */ | ||
| public static void validate( | ||
| boolean hasPlanJson, | ||
| boolean hasPlanProto, | ||
| boolean hasManifestJson, | ||
| boolean hasManifestProto) { | ||
| if (hasPlanJson && hasPlanProto) { | ||
| throw new IllegalArgumentException( | ||
| "Bundle contains both " + PLAN_JSON + " and " + PLAN_PROTO + "; plan format is ambiguous"); | ||
| } | ||
| if (hasManifestJson && hasManifestProto) { | ||
| throw new IllegalArgumentException( | ||
| "Bundle contains both " | ||
| + MANIFEST_JSON | ||
| + " and " | ||
| + MANIFEST_PROTO | ||
| + "; manifest format is ambiguous"); | ||
| } | ||
| if (hasPlanProto && hasManifestJson) { | ||
| throw new IllegalArgumentException( | ||
| "Bundle mixes plan and manifest formats: proto plan (" | ||
| + PLAN_PROTO | ||
| + ") with JSON manifest (" | ||
| + MANIFEST_JSON | ||
| + ")"); | ||
| } | ||
| if (hasPlanJson && hasManifestProto) { | ||
| throw new IllegalArgumentException( | ||
| "Bundle mixes plan and manifest formats: JSON plan (" | ||
| + PLAN_JSON | ||
| + ") with proto manifest (" | ||
| + MANIFEST_PROTO | ||
| + ")"); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we generating and running protobuf variants of all the compliance test cases too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like no. This is left for a future task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right there isn't a protobuf variant, but there should be! I hadn't thought about it. This
verify-proto-vendorjob here just checks the vendored proto schemas match the go.mod pinned OPA version. Probably better if it happens in this PR, will work on adding a proto variant.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protobuf variant test added! Does have the negative side effect of having to regenerate all of the compliance tests to match the latest OPA so the file diff is crazy.