Skip to content

Add builtin functions for OCI artifacts discovery#3169

Open
st3penta wants to merge 2 commits intoconforma:mainfrom
st3penta:EC-1655
Open

Add builtin functions for OCI artifacts discovery#3169
st3penta wants to merge 2 commits intoconforma:mainfrom
st3penta:EC-1655

Conversation

@st3penta
Copy link
Contributor

Add two new rego builtins for discovering artifacts attached to OCI images:

  • ec.oci.image_tag_refs() - discovers artifacts using legacy cosign tag conventions (.sig, .att, .sbom suffixes)
  • ec.oci.image_referrers() - discovers artifacts via the OCI Referrers API

Both builtins enable policy rules to list all the signatures, attestations, and SBOMs that are attached to a container image.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e6396fa-6c27-49b9-a174-7157a5691f0e

📥 Commits

Reviewing files that changed from the base of the PR and between ad7ad47 and f75a723.

⛔ Files ignored due to path filters (1)
  • features/__snapshots__/validate_image.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • acceptance/examples/image_referrers.rego
  • acceptance/image/image.go
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/ec_oci_image_referrers.adoc
  • docs/modules/ROOT/pages/rego_builtins.adoc
  • docs/modules/ROOT/partials/rego_nav.adoc
  • features/validate_image.feature
  • internal/rego/oci/oci.go
  • internal/rego/oci/oci_test.go
 __________________________________________________________________________________________
< Recursion is the root of computation since it trades description for time. - Alan Perlis >
 ------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

Tip

You can get early access to new features in CodeRabbit.

Enable the early_access setting to enable early access features such as new models, tools, and more.

📝 Walkthrough

Walkthrough

Adds OCI artifact discovery (legacy tag-based and OCI Referrers API) with two new OPA builtins, example Rego policies, acceptance tests, referrers-aware image signing/attestation helpers, documentation pages, and a registry image update to exercise the Referrers API.

Changes

Cohort / File(s) Summary
Core OCI Builtins
internal/rego/oci/oci.go, internal/rego/oci/oci_test.go
Adds ociImageTagRefs and ociImageReferrers builtins, registers them in init, implements tag- and referrers-based discovery logic, and adds unit tests covering discovery and error handling.
Rego Policy Examples
acceptance/examples/image_tag_refs.rego, acceptance/examples/image_referrers.rego
New example policies enforcing counts, formats, and expected artifact types for tag-based refs and OCI referrers.
Acceptance Image Helpers & Flows
acceptance/image/image.go
Extends image state with referrer maps, adds helpers for building/signing/uploading bundles and transparency log integration, refactors signature publishing to write via OCI Referrers, and exposes CreateAndPushImageSignatureReferrer & CreateAndPushAttestationReferrer.
Acceptance Tests / Scenarios
features/validate_image.feature
Adds two scenarios: discovery via tag-based refs and discovery via OCI Referrers API (including tag-based artifacts) to validate end-to-end flows.
Stub Registry Update
acceptance/registry/registry.go
Replaces registry image with ghcr.io/project-zot/zot:v2.1.15 to use a registry that supports the OCI Referrers API.
Documentation & Nav
docs/modules/ROOT/pages/ec_oci_image_referrers.adoc, docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc, docs/modules/ROOT/pages/rego_builtins.adoc, docs/modules/ROOT/partials/rego_nav.adoc
Adds docs for ec.oci.image_referrers and ec.oci.image_tag_refs, updates builtins documentation and navigation to include the new functions.
Acceptance Examples / Tests
acceptance/examples/*, acceptance/image/*
New example policies plus image helper changes are wired into acceptance test bindings and steps.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Harness
    participant Image as Image Builder
    participant Rekor as Transparency Log (Rekor)
    participant Registry as OCI Registry (Referrers API)

    rect rgba(200,200,255,0.5)
    Test->>Image: trigger CreateAndPushImageSignatureReferrer(image, key)
    Image->>Image: build signature payload & bundle
    Image->>Rekor: upload transparency bundle
    Rekor-->>Image: return bundle info & log entry
    Image->>Registry: push signature referrer (with bundle annotations)
    Registry-->>Image: acknowledge referrer
    Image-->>Test: record referrer state
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add builtin functions for OCI artifacts discovery' clearly and concisely describes the main change—introducing two new Rego builtins for artifact discovery.
Description check ✅ Passed The description provides relevant context by identifying the two new builtins (ec.oci.image_tag_refs and ec.oci.image_referrers) and explaining their purposes and use cases.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan for PR comments
  • Generate coding plan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Add OCI artifact discovery builtins for tag-based and Referrers API approaches

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add two new OCI artifact discovery builtins: ec.oci.image_tag_refs() and
  ec.oci.image_referrers()
• Support legacy tag-based artifact discovery using cosign conventions (.sig, .att, .sbom suffixes)
• Support modern OCI Referrers API for discovering attached artifacts via manifest subject field
• Refactor signature/attestation creation to support both tag-based and referrer-based approaches
• Update test registry from Docker Registry to Zot for proper OCI Referrers API support
Diagram
flowchart LR
  A["OCI Image Reference"] -->|"ec.oci.image_tag_refs()"| B["Tag-based Artifacts<br/>(.sig, .att, .sbom)"]
  A -->|"ec.oci.image_referrers()"| C["OCI Referrers API<br/>Artifacts"]
  B --> D["Array of References"]
  C --> E["Array of Descriptors<br/>with metadata"]
  F["Signature/Attestation<br/>Creation"] -->|"Legacy Tags"| G["Tag-based Storage"]
  F -->|"OCI Referrers"| H["Referrer-based Storage"]
Loading

Grey Divider

File Changes

1. internal/rego/oci/oci.go ✨ Enhancement +204/-0

Implement two new OCI artifact discovery builtins

internal/rego/oci/oci.go


2. internal/rego/oci/oci_test.go 🧪 Tests +354/-0

Add comprehensive tests for tag-refs and referrers discovery

internal/rego/oci/oci_test.go


3. acceptance/image/image.go ✨ Enhancement +319/-100

Add referrer-based artifact creation and storage support

acceptance/image/image.go


View more (8)
4. acceptance/registry/registry.go ⚙️ Configuration changes +2/-1

Switch registry from Docker Registry to Zot for Referrers API

acceptance/registry/registry.go


5. acceptance/examples/image_tag_refs.rego 📝 Documentation +75/-0

Add example policy for tag-based artifact discovery

acceptance/examples/image_tag_refs.rego


6. acceptance/examples/image_referrers.rego 📝 Documentation +75/-0

Add example policy for OCI Referrers API discovery

acceptance/examples/image_referrers.rego


7. docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc 📝 Documentation +15/-0

Document ec.oci.image_tag_refs builtin function

docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc


8. docs/modules/ROOT/pages/ec_oci_image_referrers.adoc 📝 Documentation +15/-0

Document ec.oci.image_referrers builtin function

docs/modules/ROOT/pages/ec_oci_image_referrers.adoc


9. docs/modules/ROOT/pages/rego_builtins.adoc 📝 Documentation +4/-0

Add new builtins to Rego reference documentation

docs/modules/ROOT/pages/rego_builtins.adoc


10. docs/modules/ROOT/partials/rego_nav.adoc 📝 Documentation +2/-0

Update navigation to include new builtin references

docs/modules/ROOT/partials/rego_nav.adoc


11. features/validate_image.feature 🧪 Tests +50/-0

Add acceptance test scenarios for artifact discovery

features/validate_image.feature


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 10, 2026

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Referrers digest field misnamed 🐞 Bug ✓ Correctness
Description
ec.oci.image_referrers() returns an object field named digest that contains a full
repository@sha256:... reference string, while other OCI descriptor objects in this codebase use
digest for the digest only (sha256:...) and the docs call the field digest without clarifying
it is a full reference. This semantic mismatch will cause policies that treat digest as a digest
to behave incorrectly and makes the new builtin inconsistent with the rest of the OCI builtins.
Code

internal/rego/oci/oci.go[R1484-1491]

+		referrerRef := fmt.Sprintf("%s@%s", ref.Context().Name(), descriptor.Digest.String())
+
+		descriptorTerm := ast.ObjectTerm(
+			ast.Item(ast.StringTerm("mediaType"), ast.StringTerm(string(descriptor.MediaType))),
+			ast.Item(ast.StringTerm("size"), ast.NumberTerm(json.Number(fmt.Sprintf("%d", descriptor.Size)))),
+			ast.Item(ast.StringTerm("digest"), ast.StringTerm(referrerRef)),
+			ast.Item(ast.StringTerm("artifactType"), ast.StringTerm(descriptor.ArtifactType)),
+		)
Evidence
The implementation explicitly constructs referrerRef as repo@digest and stores it in the
digest field. Existing descriptor objects in the same file set digest to d.Digest.String()
(digest only). The docs describe the returned object as having a digest field, and the acceptance
policy example validates that descriptor.digest contains @, proving that callers are being
taught that digest is actually a full reference.

internal/rego/oci/oci.go[1484-1491]
internal/rego/oci/oci.go[1531-1535]
docs/modules/ROOT/pages/ec_oci_image_referrers.adoc[13-15]
acceptance/examples/image_referrers.rego[49-54]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`ec.oci.image_referrers()` currently returns a field named `digest` that contains a full `repository@sha256:...` reference string. Elsewhere in the OCI builtins, `digest` means only the digest (`sha256:...`), and the docs also describe the field as `digest`, creating a semantic mismatch that will mislead policy authors.

### Issue Context
This is a new public rego builtin API; it’s the best time to fix naming/shape before external policies rely on it.

### Fix Focus Areas
- internal/rego/oci/oci.go[1448-1502]
- internal/rego/oci/oci.go[447-479]
- docs/modules/ROOT/pages/ec_oci_image_referrers.adoc[1-15]
- acceptance/examples/image_referrers.rego[41-59]
- internal/rego/oci/oci_test.go[1701-1720]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Unpinned amd64 registry image 🐞 Bug ⛯ Reliability
Description
Acceptance tests now start the stub registry using ghcr.io/project-zot/zot-linux-amd64:latest,
which is both unpinned (:latest) and architecture-specific (linux-amd64). This makes CI/test
runs non-reproducible over time and can break on environments that cannot run amd64 images without
explicit platform configuration.
Code

acceptance/registry/registry.go[R42-47]

// the image we're using to launch the stub image registry
-const registryImage = "docker.io/registry:2.8.1"
+// Using Zot which has proper OCI Referrers API support
+const registryImage = "ghcr.io/project-zot/zot-linux-amd64:latest"

type key int
Evidence
The stub registry container image is changed to an amd64-only image and uses the floating latest
tag. The container request does not specify a platform override or a pinned digest/version, so the
exact registry implementation and behavior can change between runs.

acceptance/registry/registry.go[42-79]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The acceptance stub registry uses `ghcr.io/project-zot/zot-linux-amd64:latest`. A floating tag makes acceptance tests non-reproducible, and the amd64-specific image can fail on non-amd64 hosts without an explicit platform.

### Issue Context
The switch to Zot is reasonable for Referrers API support, but tests should remain deterministic.

### Fix Focus Areas
- acceptance/registry/registry.go[42-79]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Resolved digest discarded 🐞 Bug ➹ Performance
Description
ec.oci.image_tag_refs() calls resolveIfNeeded() (which resolves tag references to a digest via
the OCI client) but discards the resolved digest string and never uses it in subsequent tag
computation. This makes the digest resolution work non-contributory to the returned result and
diverges from the in-repo pattern of using a resolved digest for tag computation.
Code

internal/rego/oci/oci.go[R1377-1393]

+	client := oci.NewClient(bctx.Context)
+
+	// Resolve to digest if needed
+	_, ref, err := resolveIfNeeded(client, refStr)
+	if err != nil {
+		logger.WithError(err).Error("failed to resolve reference")
+		return nil, nil
+	}
+
+	// Use cosign's tag computation functions with remote options
+	remoteOpts := oci.CreateRemoteOptions(bctx.Context)
+
+	var tagRefs []*ast.Term
+
+	// Check for tag-based signature artifact (.sig suffix)
+	if sigTag, err := ociremote.SignatureTag(ref, ociremote.WithRemoteOptions(remoteOpts...)); err == nil {
+		if _, err := client.Head(sigTag); err == nil {
Evidence
The builtin ignores the resolved digest string (_) and proceeds with ref, while the OCI client
already demonstrates the pattern of resolving a digest and passing the digest reference into
cosign’s tag helper (attestation tag). This indicates the resolved digest should be the primary
input for tag computation in order to avoid doing resolution that doesn’t influence output.

internal/rego/oci/oci.go[1377-1393]
internal/utils/oci/client.go[182-189]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`ociImageTagRefs` resolves the input reference to a digest but discards the resolved string, so the digest resolution does not contribute to the computed artifact tag references.

### Issue Context
The in-repo OCI client code resolves to a digest and passes the digest reference into cosign tag helpers.

### Fix Focus Areas
- internal/rego/oci/oci.go[1363-1432]
- internal/rego/oci/oci.go[1556-1576]
- internal/utils/oci/client.go[169-193]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@acceptance/examples/image_referrers.rego`:
- Around line 8-15: The rule deny (deny contains result if) incorrectly requires
refs := ec.oci.image_referrers(input.image.ref) to have exactly two entries
(count(refs) != 2); change it to assert the presence of the specific artifact
types you care about instead of exact count. Replace the count(refs) != 2 check
with existence checks on refs for the signature and attestation descriptors
(e.g., ensure there exists r in refs with r.artifactType ==
"<signature-artifact-type>" and there exists r in refs with r.artifactType ==
"<attestation-artifact-type>" or use filtered lists and count(filtered) >= 1),
keeping the call to ec.oci.image_referrers and the deny rule name unchanged.
Ensure the result message reflects missing artifact types rather than wrong
total count.

In `@acceptance/examples/image_tag_refs.rego`:
- Around line 8-25: The policy uses ec.oci.image_tag_refs(input.image.ref)
directly which includes .sbom tags and causes the count/format rules (the deny
blocks and all_refs_valid_format/valid_suffix checks) to reject images with
legacy SBOMs; update both uses (including the other occurrence around lines
55-75) to first filter the refs to only the suffixes you care about (e.g.,
signatures/attestations) or explicitly allow .sbom: create a filtered list like
filtered_refs := [r | r := refs[_]; not endswith(r, ".sbom")] (or include only
specific suffixes) and then use filtered_refs in the count check and
all_refs_valid_format/valid_suffix checks so .sbom entries no longer cause false
rejections (or document/allow .sbom if desired).

In `@acceptance/image/image.go`:
- Around line 418-419: The code currently saves the subject image digest
(digestRef.String()) into state.ReferrerSignatures and
state.ReferrerImageSignatures, so later readers cannot find the actual referrer
artifact; change the assignments to store the referrer artifact identifier
produced when writing the referrer (e.g., use the referrer reference/descriptor
string such as referrerRef.String() or the referrer descriptor's Digest.String()
or the variable that holds the created referrer descriptor) instead of
digestRef.String(), and make the identical fix for the other occurrence (the
ReferrerAttestations assignment noted in the comment).

In `@acceptance/registry/registry.go`:
- Around line 43-44: The constant registryImage currently uses a mutable,
amd64-specific value; update the registryImage constant to a pinned, multi-arch
Zot release (either a stable release tag like "ghcr.io/project-zot/zot:v0.x.y"
or a specific sha256 digest) and remove the "-linux-amd64" suffix so the image
is cross-platform and reproducible; locate the registryImage constant in this
file and replace its string with the chosen pinned tag or digest and run the
acceptance suite to verify compatibility.

In `@docs/modules/ROOT/pages/ec_oci_image_referrers.adoc`:
- Around line 1-15: The docs for ec.oci.image_referrers are missing usage
examples and a clear return shape; update the page to include an "Example"
section showing a concrete call to
ec.oci.image_referrers("registry.example.com/myimage:v1.0") and illustrate the
returned array of objects with fields artifactType, digest, mediaType, and size
(show two sample entries), and also add a short "Errors / Fallbacks" note
describing behavior when the registry does not support the OCI Referrers API
(e.g., returns empty array or raises an error) and any retry or timeout
semantics so callers know how to handle failures.

In `@docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc`:
- Around line 1-15: Add concrete examples and clarify tag format for
ec.oci.image_tag_refs: update the docs for the function name
ec.oci.image_tag_refs and parameter `ref` to include an "Example" section that
shows calling ec.oci.image_tag_refs("registry.example.com/myimage:v1.0") and the
expected returned `refs` array with concrete tag-based artifact references (e.g.
registry.example.com/myimage:sha256-<digest>.sig, :sha256-<digest>.att,
:sha256-<digest>.sbom), and add one-line descriptions that .sig = signature,
.att = attestation, .sbom = software bill of materials so users understand the
suffix meanings.

In `@internal/rego/oci/oci.go`:
- Around line 1392-1427: The code treats any error from
ociremote.SignatureTag/AttestationTag/SBOMTag and client.Head as "artifact
missing" and continues, which hides auth/transient registry errors; modify the
discovery logic in the ociremote tag-check blocks (symbols:
ociremote.SignatureTag, ociremote.AttestationTag, ociremote.SBOMTag, and
client.Head, and the tagRefs append logic) to distinguish true-not-found cases
from other errors (e.g., inspect and match the registry error or HTTP status),
and on non-not-found/auth/temporary errors return or propagate an error (abort
discovery) instead of appending nothing—only treat NotFound/DoesNotExist as
missing and continue. Ensure the function returns an error when discovery fails
due to registry/auth issues so callers honor the contract that partial discovery
errors are reported.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4b09e1bf-5888-4a2d-b478-c76e2b6033d6

📥 Commits

Reviewing files that changed from the base of the PR and between 36834a2 and 0f686c6.

⛔ Files ignored due to path filters (1)
  • features/__snapshots__/validate_image.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • acceptance/examples/image_referrers.rego
  • acceptance/examples/image_tag_refs.rego
  • acceptance/image/image.go
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/ec_oci_image_referrers.adoc
  • docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc
  • docs/modules/ROOT/pages/rego_builtins.adoc
  • docs/modules/ROOT/partials/rego_nav.adoc
  • features/validate_image.feature
  • internal/rego/oci/oci.go
  • internal/rego/oci/oci_test.go

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/rego/oci/oci_test.go (1)

1250-1270: ⚠️ Potential issue | 🟡 Minor

Missing ociImageReferrersName in registration test.

The TestFunctionsRegistered test verifies that builtins are registered, but only ociImageTagRefsName was added. The new ociImageReferrersName builtin should also be included to ensure both new builtins are properly registered.

🔧 Proposed fix
 func TestFunctionsRegistered(t *testing.T) {
 	names := []string{
 		ociBlobName,
 		ociBlobFilesName,
 		ociDescriptorName,
 		ociImageFilesName,
 		ociImageManifestName,
 		ociImageManifestsBatchName,
 		ociImageIndexName,
 		ociImageTagRefsName,
+		ociImageReferrersName,
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/rego/oci/oci_test.go` around lines 1250 - 1270, The test
TestFunctionsRegistered is missing the new builtin identifier
ociImageReferrersName in its names list; update the names slice inside
TestFunctionsRegistered to include ociImageReferrersName alongside
ociImageTagRefsName so the loop checks registration of the new builtin (ensure
you modify the names slice where ociBlobName, ociBlobFilesName, ...,
ociImageTagRefsName are declared in internal/rego/oci/oci_test.go).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@internal/rego/oci/oci_test.go`:
- Around line 1250-1270: The test TestFunctionsRegistered is missing the new
builtin identifier ociImageReferrersName in its names list; update the names
slice inside TestFunctionsRegistered to include ociImageReferrersName alongside
ociImageTagRefsName so the loop checks registration of the new builtin (ensure
you modify the names slice where ociBlobName, ociBlobFilesName, ...,
ociImageTagRefsName are declared in internal/rego/oci/oci_test.go).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ef6fbc3-86ea-493f-bea5-a97d8c357c95

📥 Commits

Reviewing files that changed from the base of the PR and between 0f686c6 and b960026.

⛔ Files ignored due to path filters (1)
  • features/__snapshots__/validate_image.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • acceptance/examples/image_referrers.rego
  • acceptance/examples/image_tag_refs.rego
  • acceptance/image/image.go
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/ec_oci_image_referrers.adoc
  • docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc
  • docs/modules/ROOT/pages/rego_builtins.adoc
  • docs/modules/ROOT/partials/rego_nav.adoc
  • features/validate_image.feature
  • internal/rego/oci/oci.go
  • internal/rego/oci/oci_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/modules/ROOT/pages/ec_oci_image_tag_refs.adoc
  • features/validate_image.feature
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/rego_builtins.adoc

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/rego/oci/oci_test.go (1)

1615-1647: Assert real artifactType values in this suite.

These fixtures are plain random.Image() manifests, and Lines 1769-1780 only verify that artifactType exists. A regression that returns artifactType: "" for every descriptor would still pass here even though acceptance/examples/image_referrers.rego depends on the exact signature and attestation types. Set explicit artifact types on the referrer fixtures and assert the returned values.

Also applies to: 1768-1780

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/rego/oci/oci_test.go` around lines 1615 - 1647, The test currently
creates random referrer images (sigImgWithSubject, attImgWithSubject via
mutate.Subject and imgDescriptor) but never sets or asserts explicit OCI
artifactType, which can mask regressions; update the referrer fixtures by
setting the descriptor's artifactType (e.g., use mutate.Annotations or construct
a new descriptor with ArtifactType "application/vnd.cncf.sig" for signatures and
"application/vnd.cncf.attestation" for attestations, or use the appropriate
helper to set the ArtifactType on sigImgWithSubject and attImgWithSubject before
writing), then after pushing (after remote.Write using
sigDigestRef/attDigestRef) add require.Equal checks asserting the returned
descriptor artifactType equals the expected signature and attestation MIME types
so the test fails if artifactType is empty or incorrect.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/rego/oci/oci.go`:
- Around line 1408-1451: The ociImageTagRefs helper is incorrectly returning
hard errors when client.Head() fails for tag-based artifacts (see the sigTag,
attTag, and sbomTag handling blocks that call client.Head), which violates the
builtins contract to degrade to “no value” on failure; change each branch that
currently does "return nil, fmt.Errorf(...)" to instead log the error
(preserving the existing logger.WithFields(...).Error call) and continue
execution without returning, so the function skips that tag and allows policy
evaluation to proceed (keep the existing isNotFoundError handling and only avoid
returning on other client.Head errors).

---

Nitpick comments:
In `@internal/rego/oci/oci_test.go`:
- Around line 1615-1647: The test currently creates random referrer images
(sigImgWithSubject, attImgWithSubject via mutate.Subject and imgDescriptor) but
never sets or asserts explicit OCI artifactType, which can mask regressions;
update the referrer fixtures by setting the descriptor's artifactType (e.g., use
mutate.Annotations or construct a new descriptor with ArtifactType
"application/vnd.cncf.sig" for signatures and "application/vnd.cncf.attestation"
for attestations, or use the appropriate helper to set the ArtifactType on
sigImgWithSubject and attImgWithSubject before writing), then after pushing
(after remote.Write using sigDigestRef/attDigestRef) add require.Equal checks
asserting the returned descriptor artifactType equals the expected signature and
attestation MIME types so the test fails if artifactType is empty or incorrect.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26128b6d-4bfe-49cb-909b-fd7a87371a55

📥 Commits

Reviewing files that changed from the base of the PR and between b960026 and 3973a75.

⛔ Files ignored due to path filters (1)
  • features/__snapshots__/validate_image.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • acceptance/examples/image_referrers.rego
  • acceptance/image/image.go
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/ec_oci_image_referrers.adoc
  • docs/modules/ROOT/pages/rego_builtins.adoc
  • docs/modules/ROOT/partials/rego_nav.adoc
  • features/validate_image.feature
  • internal/rego/oci/oci.go
  • internal/rego/oci/oci_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/modules/ROOT/partials/rego_nav.adoc
  • acceptance/registry/registry.go
  • docs/modules/ROOT/pages/rego_builtins.adoc
  • docs/modules/ROOT/pages/ec_oci_image_referrers.adoc

Implement ec.oci.image_tag_refs() builtin to discover artifacts
attached to images using legacy cosign tag conventions
(.sig, .att, .sbom suffixes).

This enables policy rules to locate and validate tag-based signatures,
attestations, and SBOMs alongside the newer OCI Referrers API approach.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Ref: https://issues.redhat.com/browse/EC-1655
Implement ec.oci.image_referrers() builtin to discover artifacts
attached to images via the OCI Referrers API. Returns descriptors with
mediaType, size, digest, and artifactType for all referrers, enabling
policy rules to validate modern OCI artifact associations without
relying on legacy tag-based conventions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Ref: https://issues.redhat.com/browse/EC-1655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant