Skip to content

Commit ebd561c

Browse files
committed
Ignore missing SBOM for Image Indexes
Currently, Konflux does not create an SBOM for Image Indexes: https://issues.redhat.com/browse/KONFLUX-4330 Until then, do not trigger a violation when an SBOM is not found for such images. Today, it's not possible to determine if the image being validated is an Image Index or an Image Manifest, see enterprise-contract/ec-cli#2121. The Image Index detection is done via Konflux-specific heuristics as a workaround. Fixes enterprise-contract#1210 Resolves: EC-996 Signed-off-by: Luiz Carvalho <[email protected]>
1 parent 302e1f1 commit ebd561c

File tree

7 files changed

+147
-6
lines changed

7 files changed

+147
-6
lines changed

antora/docs/modules/ROOT/pages/release_policy.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Confirm the `allowed_registry_prefixes` rule data was provided, since it's requi
308308
* Rule type: [rule-type-indicator failure]#FAILURE#
309309
* FAILURE message: `%s`
310310
* Code: `base_image_registries.allowed_registries_provided`
311-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L72[Source, window="_blank"]
311+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L77[Source, window="_blank"]
312312

313313
[#base_image_registries__base_image_permitted]
314314
=== link:#base_image_registries__base_image_permitted[Base image comes from permitted registry]
@@ -320,7 +320,7 @@ Verify that the base images used when building a container image come from a kno
320320
* Rule type: [rule-type-indicator failure]#FAILURE#
321321
* FAILURE message: `Base image %q is from a disallowed registry`
322322
* Code: `base_image_registries.base_image_permitted`
323-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L17[Source, window="_blank"]
323+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L18[Source, window="_blank"]
324324

325325
[#base_image_registries__base_image_info_found]
326326
=== link:#base_image_registries__base_image_info_found[Base images provided]
@@ -332,7 +332,7 @@ Verify the expected information was provided about which base images were used d
332332
* Rule type: [rule-type-indicator failure]#FAILURE#
333333
* FAILURE message: `Base images information is missing`
334334
* Code: `base_image_registries.base_image_info_found`
335-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L46[Source, window="_blank"]
335+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/base_image_registries/base_image_registries.rego#L47[Source, window="_blank"]
336336

337337
[#buildah_build_task_package]
338338
== link:#buildah_build_task_package[Buildah build task]
@@ -1066,7 +1066,7 @@ Confirm the `disallowed_packages` and `disallowed_attributes` rule data were pro
10661066
* Rule type: [rule-type-indicator failure]#FAILURE#
10671067
* FAILURE message: `%s`
10681068
* Code: `sbom.disallowed_packages_provided`
1069-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/sbom/sbom.rego#L31[Source, window="_blank"]
1069+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/sbom/sbom.rego#L36[Source, window="_blank"]
10701070

10711071
[#sbom__found]
10721072
=== link:#sbom__found[Found]
@@ -1078,7 +1078,7 @@ Confirm an SBOM attestation exists.
10781078
* Rule type: [rule-type-indicator failure]#FAILURE#
10791079
* FAILURE message: `No SBOM attestations found`
10801080
* Code: `sbom.found`
1081-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/sbom/sbom.rego#L14[Source, window="_blank"]
1081+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/sbom/sbom.rego#L15[Source, window="_blank"]
10821082

10831083
[#sbom_cyclonedx_package]
10841084
== link:#sbom_cyclonedx_package[SBOM CycloneDX]

policy/lib/konflux/konflux.rego

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package lib.konflux
2+
3+
import rego.v1
4+
5+
import data.lib
6+
import data.lib.image
7+
import data.lib.tekton
8+
9+
# Currently, it's not possible to determine if the image being validated is an Image Index or an
10+
# Image Manifest, see https://github.com/enterprise-contract/ec-cli/issues/2121. This function is
11+
# implemented as a workaround. It uses Konflux-specific heuristics to determine if the provided
12+
# image is an Image Index.
13+
is_validating_image_index if {
14+
image_index_digests := {digest |
15+
some attestation in lib.pipelinerun_attestations
16+
some task in tekton.build_tasks(attestation)
17+
18+
# In Konflux, the Task that creates an Image Index emits the IMAGES result which contains
19+
# all of the related Image Manifests.
20+
count(trim_space(tekton.task_result(task, "IMAGES"))) > 0
21+
digest := trim_space(tekton.task_result(task, "IMAGE_DIGEST"))
22+
count(digest) > 0
23+
}
24+
25+
image.parse(input.image.ref).digest in image_index_digests
26+
}

policy/lib/konflux/konflux_test.rego

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package lib.konflux_test
2+
3+
import rego.v1
4+
5+
import data.lib
6+
import data.lib.konflux
7+
8+
test_is_image_index if {
9+
konflux.is_validating_image_index with input.attestations as [_attestation]
10+
with input.image.ref as "registry.local/ham@sha256:fff"
11+
}
12+
13+
test_is_image_index_unknown_digest if {
14+
not konflux.is_validating_image_index with input.attestations as [_attestation]
15+
with input.image.ref as "registry.local/ham@sha256:bbb"
16+
}
17+
18+
test_is_image_index_empty_images if {
19+
att := json.patch(
20+
_attestation,
21+
[{"op": "add", "path": "/statement/predicate/buildConfig/tasks/0/results/0/value", "value": ""}],
22+
)
23+
not konflux.is_validating_image_index with input.attestations as [att]
24+
with input.image.ref as "registry.local/ham@sha256:fff"
25+
}
26+
27+
_attestation := {"statement": {"predicate": {
28+
"buildType": lib.tekton_pipeline_run,
29+
"buildConfig": {"tasks": [{"results": [
30+
{
31+
"name": "IMAGES",
32+
"type": "string",
33+
"value": "registry.local/spam@sha256:abc, registry.local/bacon@sha256:bcd",
34+
},
35+
{
36+
"name": "IMAGE_URL",
37+
"type": "string",
38+
"value": "registry.local/eggs:latest",
39+
},
40+
{
41+
"name": "IMAGE_DIGEST",
42+
"type": "string",
43+
"value": "sha256:fff",
44+
},
45+
]}]},
46+
}}}

policy/release/base_image_registries/base_image_registries.rego

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import rego.v1
1212
import data.lib
1313
import data.lib.image
1414
import data.lib.json as j
15+
import data.lib.konflux
1516
import data.lib.sbom
1617

1718
# METADATA
@@ -61,6 +62,10 @@ deny contains result if {
6162
# - attestation_type.known_attestation_type
6263
#
6364
deny contains result if {
65+
# TODO: Workaround until Konflux produces SBOMs for Image Indexes:
66+
# https://issues.redhat.com/browse/KONFLUX-4330
67+
not konflux.is_validating_image_index
68+
6469
# Some images are built "from scratch" and not have any base images, e.g. UBI.
6570
# This check distinguishes such images by simply ensuring that at least one SBOM
6671
# is attached to the image.

policy/release/base_image_registries/base_image_registries_test.rego

+34-1
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,47 @@ test_sbom_base_image_selection if {
209209
lib.assert_empty(base_image_registries.deny) with lib.sbom.cyclonedx_sboms as sboms
210210
}
211211

212-
test_missing_result if {
212+
test_base_image_not_found if {
213213
expected := {{
214214
"code": "base_image_registries.base_image_info_found",
215215
"msg": "Base images information is missing",
216216
}}
217217
lib.assert_equal_results(base_image_registries.deny, expected)
218218
}
219219

220+
test_base_image_not_found_image_index if {
221+
att := {"statement": {"predicate": {
222+
"buildType": lib.tekton_pipeline_run,
223+
"buildConfig": {"tasks": [{"results": [
224+
{
225+
"name": "IMAGES",
226+
"type": "string",
227+
"value": "registry.local/spam@sha256:abc, registry.local/bacon@sha256:bcd",
228+
},
229+
{
230+
"name": "IMAGE_URL",
231+
"type": "string",
232+
"value": "registry.local/eggs:latest",
233+
},
234+
{
235+
"name": "IMAGE_DIGEST",
236+
"type": "string",
237+
"value": "sha256:fff",
238+
},
239+
]}]},
240+
}}}
241+
242+
lib.assert_empty(base_image_registries.deny) with input.attestations as [att]
243+
with input.image.ref as "registry.local/ham@sha256:fff"
244+
245+
expected := {{
246+
"code": "base_image_registries.base_image_info_found",
247+
"msg": "Base images information is missing",
248+
}}
249+
lib.assert_equal_results(base_image_registries.deny, expected) with input.attestations as [att]
250+
with input.image.ref as "registry.local/ham@sha256:aaa"
251+
}
252+
220253
test_allowed_registries_provided if {
221254
expected := {{
222255
"code": "base_image_registries.allowed_registries_provided",

policy/release/sbom/sbom.rego

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package sbom
1010
import rego.v1
1111

1212
import data.lib
13+
import data.lib.konflux
1314

1415
# METADATA
1516
# title: Found
@@ -24,6 +25,10 @@ import data.lib
2425
# - redhat
2526
#
2627
deny contains result if {
28+
# TODO: Workaround until Konflux produces SBOMs for Image Indexes:
29+
# https://issues.redhat.com/browse/KONFLUX-4330
30+
not konflux.is_validating_image_index
31+
2732
count(_sboms) == 0
2833
result := lib.result_helper(rego.metadata.chain(), [])
2934
}

policy/release/sbom/sbom_test.rego

+26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ test_not_found if {
1111
with input.image.ref as "registry.local/spam@sha256:123"
1212
}
1313

14+
test_not_found_image_index if {
15+
att := {"statement": {"predicate": {
16+
"buildType": lib.tekton_pipeline_run,
17+
"buildConfig": {"tasks": [{"results": [
18+
{
19+
"name": "IMAGES",
20+
"type": "string",
21+
"value": "registry.local/spam@sha256:abc, registry.local/bacon@sha256:bcd",
22+
},
23+
{
24+
"name": "IMAGE_URL",
25+
"type": "string",
26+
"value": "registry.local/eggs:latest",
27+
},
28+
{
29+
"name": "IMAGE_DIGEST",
30+
"type": "string",
31+
"value": "sha256:fff",
32+
},
33+
]}]},
34+
}}}
35+
36+
lib.assert_empty(sbom.deny) with input.attestations as [att]
37+
with input.image.ref as "registry.local/ham@sha256:fff"
38+
}
39+
1440
test_rule_data_validation if {
1541
d := {
1642
"disallowed_packages": [

0 commit comments

Comments
 (0)