Skip to content

Commit 50da51d

Browse files
committed
Make 'inaccessible_parent_*' rules logic clearer
This commit adds the helper function 'labels._has_parent', that checks if a parent image is specified in the base image annotations. This helper function is used to make the 'labels.inaccessible_parent_manifest' and 'labels.inaccessible_parent_config' clearer: these rules will only be evaluated if a parent is actually specified, otherwise they will be skipped. This prevents a bug that called builtin oci functions with invalid parameters (that caused an obscure error, like the one in the linked support ticket). Note: we considered adding a rule that checks that the parent image annotations are always specified in the base image, but it turns out this is not always the case: bundle image manifests are usually built 'FROM scratch', meaning that they will have empty parent annotations. Also common image manifests might have the same 'FROM scratch' build. Ref: https://issues.redhat.com/browse/EC-1402 Ref: https://issues.redhat.com/browse/KFLUXSPRT-4327
1 parent a14e679 commit 50da51d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

antora/docs/modules/ROOT/pages/packages/release_labels.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The parent image config is not accessible.
6666
* Rule type: [rule-type-indicator failure]#FAILURE#
6767
* FAILURE message: `Image config of the image %q, parent of image %q is inaccessible`
6868
* Code: `labels.inaccessible_parent_config`
69-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/release/labels/labels.rego#L199[Source, window="_blank"]
69+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/release/labels/labels.rego#L200[Source, window="_blank"]
7070

7171
[#labels__inaccessible_parent_manifest]
7272
=== link:#labels__inaccessible_parent_manifest[Inaccessible parent image manifest]

policy/release/labels/labels.rego

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ deny contains result if {
192192
# - redhat
193193
#
194194
deny contains result if {
195+
_has_parent
195196
is_null(_parent.manifest)
196197
result := lib.result_helper(rego.metadata.chain(), [_parent.ref, input.image.ref])
197198
}
@@ -210,6 +211,7 @@ deny contains result if {
210211
# - redhat
211212
#
212213
deny contains result if {
214+
_has_parent
213215
parent_ref := image.parse(_parent.ref)
214216
is_null(_config(parent_ref.repo, _parent.manifest))
215217
result := lib.result_helper(rego.metadata.chain(), [_parent.ref, input.image.ref])
@@ -235,11 +237,24 @@ _image_labels := labels if {
235237
}
236238
}
237239

240+
_has_parent if {
241+
image_manifest := ec.oci.image_manifest(input.image.ref)
242+
243+
raw_name := image_manifest.annotations["org.opencontainers.image.base.name"]
244+
raw_name != ""
245+
246+
digest := image_manifest.annotations["org.opencontainers.image.base.digest"]
247+
digest != ""
248+
}
249+
238250
_parent := {"ref": ref, "manifest": manifest, "config": config} if {
239251
image_manifest := ec.oci.image_manifest(input.image.ref)
240252

241253
raw_name := image_manifest.annotations["org.opencontainers.image.base.name"]
254+
raw_name != ""
255+
242256
digest := image_manifest.annotations["org.opencontainers.image.base.digest"]
257+
digest != ""
243258

244259
# Sometimes the name annotation is a ref including a digest, likely the
245260
# digest of the image index. Make sure that digest gets removed.

policy/release/labels/labels_test.rego

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ test_parent_image_manifest_inaccessible if {
403403
ref := _test_ref_patches(array.concat(
404404
_add_annotations({
405405
"org.opencontainers.image.base.name": "fail",
406-
"org.opencontainers.image.base.digest": "",
406+
"org.opencontainers.image.base.digest": "fake_digest",
407407
}),
408408
[_config(_add_labels({
409409
"name": "test-image",
@@ -415,7 +415,7 @@ test_parent_image_manifest_inaccessible if {
415415

416416
expected := {{
417417
"code": "labels.inaccessible_parent_manifest",
418-
"msg": sprintf(`Manifest of the image "fail@", parent of image %q is inaccessible`, [ref]),
418+
"msg": sprintf(`Manifest of the image "fail@fake_digest", parent of image %q is inaccessible`, [ref]),
419419
}}
420420

421421
lib.assert_equal_results(labels.deny, expected) with input.image.ref as ref

0 commit comments

Comments
 (0)