Skip to content

Commit 61ec982

Browse files
authored
Merge pull request #1699 from dheerajodha/fix-image-manifests-mocks
Fix test failures from parallel image manifest fetching
2 parents b1f08f1 + 59bdc60 commit 61ec982

File tree

7 files changed

+138
-26
lines changed

7 files changed

+138
-26
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Produce a warning when a task that will be required in the future is not current
1616
* Rule type: [rule-type-indicator warning]#WARNING#
1717
* WARNING message: `%s is missing and will be required on %s`
1818
* Code: `required_tasks.missing_future_required_task`
19-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L55[Source, window="_blank"]
19+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L60[Source, window="_blank"]
2020

2121
[#required_tasks__missing_required_task]
2222
=== link:#required_tasks__missing_required_task[Missing required task]
@@ -26,7 +26,7 @@ Ensure that the set of required tasks is included in the Pipeline definition.
2626
* Rule type: [rule-type-indicator failure]#FAILURE#
2727
* FAILURE message: `%s is missing or outdated`
2828
* Code: `required_tasks.missing_required_task`
29-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L92[Source, window="_blank"]
29+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L97[Source, window="_blank"]
3030

3131
[#required_tasks__tasks_found]
3232
=== link:#required_tasks__tasks_found[Pipeline contains tasks]
@@ -36,7 +36,7 @@ Confirm at least one task is present in the pipeline definition.
3636
* Rule type: [rule-type-indicator failure]#FAILURE#
3737
* FAILURE message: `No tasks found in pipeline`
3838
* Code: `required_tasks.tasks_found`
39-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L79[Source, window="_blank"]
39+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L84[Source, window="_blank"]
4040

4141
[#required_tasks__required_tasks_list_present]
4242
=== link:#required_tasks__required_tasks_list_present[Required task list is present in rule data]
@@ -46,7 +46,7 @@ Confirm the `required-tasks` rule data was provided, since it's required by the
4646
* Rule type: [rule-type-indicator failure]#FAILURE#
4747
* FAILURE message: `The required tasks list is missing from the rule data`
4848
* Code: `required_tasks.required_tasks_list_present`
49-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L111[Source, window="_blank"]
49+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L116[Source, window="_blank"]
5050

5151
[#required_tasks__required_tasks_found]
5252
=== link:#required_tasks__required_tasks_found[Required tasks found in pipeline definition]
@@ -56,4 +56,4 @@ Produce a warning if a list of current or future required tasks does not exist i
5656
* Rule type: [rule-type-indicator warning]#WARNING#
5757
* WARNING message: `Required tasks do not exist for pipeline %q`
5858
* Code: `required_tasks.required_tasks_found`
59-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L36[Source, window="_blank"]
59+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/required_tasks/required_tasks.rego#L41[Source, window="_blank"]

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Confirm the `trusted_tasks` rule data was provided, since it's required by the p
1616
* Rule type: [rule-type-indicator failure]#FAILURE#
1717
* FAILURE message: `Missing required trusted_tasks data`
1818
* Code: `task_bundle.missing_required_data`
19-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L118[Source, window="_blank"]
19+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L123[Source, window="_blank"]
2020

2121
[#task_bundle__untrusted_task_bundle]
2222
=== link:#task_bundle__untrusted_task_bundle[Task bundle is not trusted]
@@ -26,7 +26,7 @@ For each Task in the Pipeline definition, check if the Tekton Bundle used is a t
2626
* Rule type: [rule-type-indicator failure]#FAILURE#
2727
* FAILURE message: `Pipeline task '%s' uses an untrusted task bundle '%s'`
2828
* Code: `task_bundle.untrusted_task_bundle`
29-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L103[Source, window="_blank"]
29+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L108[Source, window="_blank"]
3030

3131
[#task_bundle__out_of_date_task_bundle]
3232
=== link:#task_bundle__out_of_date_task_bundle[Task bundle is out of date]
@@ -36,7 +36,7 @@ For each Task in the Pipeline definition, check if the Tekton Bundle used is the
3636
* Rule type: [rule-type-indicator warning]#WARNING#
3737
* WARNING message: `Pipeline task '%s' uses an out of date task bundle '%s', new version of the Task must be used before %s`
3838
* Code: `task_bundle.out_of_date_task_bundle`
39-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L54[Source, window="_blank"]
39+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L59[Source, window="_blank"]
4040

4141
[#task_bundle__empty_task_bundle_reference]
4242
=== link:#task_bundle__empty_task_bundle_reference[Task bundle reference is empty]
@@ -46,7 +46,7 @@ Check that a valid task bundle reference is being used.
4646
* Rule type: [rule-type-indicator failure]#FAILURE#
4747
* FAILURE message: `Pipeline task '%s' uses an empty bundle image reference`
4848
* Code: `task_bundle.empty_task_bundle_reference`
49-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L90[Source, window="_blank"]
49+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L95[Source, window="_blank"]
5050

5151
[#task_bundle__disallowed_task_reference]
5252
=== link:#task_bundle__disallowed_task_reference[Task bundle was not used or is not defined]
@@ -56,7 +56,7 @@ Check for the existence of a task bundle. This rule will fail if the task is not
5656
* Rule type: [rule-type-indicator failure]#FAILURE#
5757
* FAILURE message: `Pipeline task '%s' does not contain a bundle reference`
5858
* Code: `task_bundle.disallowed_task_reference`
59-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L76[Source, window="_blank"]
59+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L81[Source, window="_blank"]
6060

6161
[#task_bundle__unpinned_task_bundle]
6262
=== link:#task_bundle__unpinned_task_bundle[Unpinned task bundle reference]
@@ -66,4 +66,4 @@ Check if the Tekton Bundle used for the Tasks in the Pipeline definition is pinn
6666
* Rule type: [rule-type-indicator warning]#WARNING#
6767
* WARNING message: `Pipeline task '%s' uses an unpinned task bundle reference '%s'`
6868
* Code: `task_bundle.unpinned_task_bundle`
69-
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L40[Source, window="_blank"]
69+
* https://github.com/conforma/policy/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L45[Source, window="_blank"]

policy/lib/tekton/trusted_test.rego

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,16 @@ test_is_trusted_task_with_rules if {
236236
{"name": "name", "value": "task-something"},
237237
{"name": "kind", "value": "task"},
238238
]}}}
239+
240+
# regal ignore:line-length
239241
allowed_task_manifests := _mock_bundle_manifests(
240-
"quay.io/konflux-ci/tekton-catalog/task-something:0.4@sha256:digest",
242+
"quay.io/konflux-ci/tekton-catalog/task-something:0.4@sha256:d19e5700000000000000000000000000000000000000000000000000d19e5700", # regal ignore:line-length
241243
"0.4",
242244
)
243245

244246
# regal ignore:line-length
245247
tekton.is_trusted_task(allowed_task, allowed_task_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
248+
with ec.oci.image_manifests as _mock_image_manifests
246249

247250
# Task that matches deny rule should not be trusted (deny takes precedence)
248251
denied_task := {"spec": {"taskRef": {"resolver": "bundles", "params": [
@@ -251,13 +254,16 @@ test_is_trusted_task_with_rules if {
251254
{"name": "name", "value": "task-buildah"},
252255
{"name": "kind", "value": "task"},
253256
]}}}
257+
258+
# regal ignore:line-length
254259
denied_task_manifests := _mock_bundle_manifests(
255-
"quay.io/konflux-ci/tekton-catalog/task-buildah:0.3@sha256:digest",
260+
"quay.io/konflux-ci/tekton-catalog/task-buildah:0.3@sha256:digest", # regal ignore:line-length
256261
"0.3",
257262
)
258263

259264
# regal ignore:line-length
260265
not tekton.is_trusted_task(denied_task, denied_task_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
266+
with ec.oci.image_manifests as _mock_image_manifests
261267

262268
# Task that matches allow pattern (registry.local) should be trusted
263269
# Note: The key format is oci://registry.local/trusty:1.0 (with tag), so pattern oci://registry.local/* matches
@@ -267,10 +273,13 @@ test_is_trusted_task_with_rules if {
267273
{"name": "name", "value": "trusty"},
268274
{"name": "kind", "value": "task"},
269275
]}}}
276+
277+
# regal ignore:line-length
270278
registry_local_manifests := _mock_bundle_manifests("registry.local/trusty:1.0@sha256:digest", "1.0")
271279

272280
# regal ignore:line-length
273281
tekton.is_trusted_task(registry_local_task, registry_local_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
282+
with ec.oci.image_manifests as _mock_image_manifests
274283

275284
# Task that doesn't match any allow rule should not be trusted
276285
# Note: This task uses a different path (untrusted) that doesn't match the pattern
@@ -280,10 +289,13 @@ test_is_trusted_task_with_rules if {
280289
{"name": "name", "value": "untrusted"},
281290
{"name": "kind", "value": "task"},
282291
]}}}
292+
293+
# regal ignore:line-length
283294
not_allowed_manifests := _mock_bundle_manifests("other-registry.io/untrusted:1.0@sha256:digest", "1.0")
284295

285296
# regal ignore:line-length
286297
not tekton.is_trusted_task(not_allowed_task, not_allowed_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
298+
with ec.oci.image_manifests as _mock_image_manifests
287299

288300
# Tasks satisfying at least one deny rule version constraints should be denied
289301
deny_constrained_task_denied_version := {"spec": {"taskRef": {"resolver": "bundles", "params": [
@@ -298,42 +310,52 @@ test_is_trusted_task_with_rules if {
298310

299311
# regal ignore:line-length
300312
not tekton.is_trusted_task(deny_constrained_task_denied_version, deny_constrained_denied_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
313+
with ec.oci.image_manifests as _mock_image_manifests
301314

302315
# Task not satisfying any deny rule version constraints should not be denied
303316
deny_constrained_task_valid_version := {"spec": {"taskRef": {"resolver": "bundles", "params": [
304317
# regal ignore:line-length
305-
{"name": "bundle", "value": "quay.io/konflux-ci/tekton-catalog/deny-task-constrained:1.2.3@sha256:d19e5700000000000000000000000000000000000000000000000000d19e5700"},
318+
{"name": "bundle", "value": "quay.io/konflux-ci/tekton-catalog/deny-task-constrained:1.2.3@sha256:digest"},
306319
{"name": "name", "value": "constrained"},
307320
{"name": "kind", "value": "task"},
308321
]}}}
309322

310323
# regal ignore:line-length
311324
deny_constrained_valid_manifests := _mock_bundle_manifests("quay.io/konflux-ci/tekton-catalog/deny-task-constrained:1.2.3@sha256:digest", "1.2.3")
312-
tekton.is_trusted_task(deny_constrained_task_valid_version, deny_constrained_valid_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules # regal ignore:line-length
325+
326+
# regal ignore:line-length
327+
tekton.is_trusted_task(deny_constrained_task_valid_version, deny_constrained_valid_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
328+
with ec.oci.image_manifests as _mock_image_manifests
313329

314330
# Tasks satisfying all the allow-rule version constraints should be allowed
315331
allow_constrained_task_valid_version := {"spec": {"taskRef": {"resolver": "bundles", "params": [
316332
# regal ignore:line-length
317-
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.5@sha256:d19e5700000000000000000000000000000000000000000000000000d19e5700"},
333+
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.5@sha256:digest"},
318334
{"name": "name", "value": "constrained"},
319335
{"name": "kind", "value": "task"},
320336
]}}}
321337

322338
# regal ignore:line-length
323339
allow_constrained_valid_manifests := _mock_bundle_manifests("quay.io/konflux-ci/another-catalog/allow-task-constrained:1.5@sha256:digest", "1.5")
324-
tekton.is_trusted_task(allow_constrained_task_valid_version, allow_constrained_valid_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules # regal ignore:line-length
340+
341+
# regal ignore:line-length
342+
tekton.is_trusted_task(allow_constrained_task_valid_version, allow_constrained_valid_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
343+
with ec.oci.image_manifests as _mock_image_manifests
325344

326345
# Tasks *NOT* satisfying all the allow-rule version constraints should be denied
327346
allow_constrained_task_denied_version := {"spec": {"taskRef": {"resolver": "bundles", "params": [
328347
# regal ignore:line-length
329-
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:d19e5700000000000000000000000000000000000000000000000000d19e5700"},
348+
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:digest"},
330349
{"name": "name", "value": "constrained"},
331350
{"name": "kind", "value": "task"},
332351
]}}}
333352

334353
# regal ignore:line-length
335354
allow_constrained_denied_manifests := _mock_bundle_manifests("quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:digest", "1.2.3")
336-
not tekton.is_trusted_task(allow_constrained_task_denied_version, allow_constrained_denied_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules # regal ignore:line-length
355+
356+
# regal ignore:line-length
357+
not tekton.is_trusted_task(allow_constrained_task_denied_version, allow_constrained_denied_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
358+
with ec.oci.image_manifests as _mock_image_manifests
337359

338360
# Task with mismatching versions between ref and manifest annotations.
339361
# Only the manifest annotation is taken into consideration
@@ -347,21 +369,27 @@ test_is_trusted_task_with_rules if {
347369
# Manifest has 1.2.3 even though ref has 1.5 - manifest version is used
348370
# regal ignore:line-length
349371
mismatch_manifests_1 := _mock_bundle_manifests("quay.io/konflux-ci/another-catalog/allow-task-constrained:1.5@sha256:digest", "1.2.3")
350-
not tekton.is_trusted_task(allow_constrained_task_denied_version_mismatching_1, mismatch_manifests_1) with data.rule_data.trusted_task_rules as trusted_task_rules # regal ignore:line-length
372+
373+
# regal ignore:line-length
374+
not tekton.is_trusted_task(allow_constrained_task_denied_version_mismatching_1, mismatch_manifests_1) with data.rule_data.trusted_task_rules as trusted_task_rules
375+
with ec.oci.image_manifests as _mock_image_manifests
351376

352377
# Task with mismatching versions between ref and manifest annotations.
353378
# Only the manifest annotation is taken into consideration
354379
allow_constrained_task_denied_version_mismatching_2 := {"spec": {"taskRef": {"resolver": "bundles", "params": [
355380
# regal ignore:line-length
356-
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:d19e5700000000000000000000000000000000000000000000000000d19e5700"},
381+
{"name": "bundle", "value": "quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:digest"},
357382
{"name": "name", "value": "constrained"},
358383
{"name": "kind", "value": "task"},
359384
]}}}
360385

361386
# Manifest has 1.5 even though ref has 1.2.3 - manifest version is used
362387
# regal ignore:line-length
363388
mismatch_manifests_2 := _mock_bundle_manifests("quay.io/konflux-ci/another-catalog/allow-task-constrained:1.2.3@sha256:digest", "1.5")
364-
tekton.is_trusted_task(allow_constrained_task_denied_version_mismatching_2, mismatch_manifests_2) with data.rule_data.trusted_task_rules as trusted_task_rules # regal ignore:line-length
389+
390+
# regal ignore:line-length
391+
tekton.is_trusted_task(allow_constrained_task_denied_version_mismatching_2, mismatch_manifests_2) with data.rule_data.trusted_task_rules as trusted_task_rules
392+
with ec.oci.image_manifests as _mock_image_manifests
365393
}
366394

367395
test_trusted_task_records if {
@@ -570,6 +598,7 @@ test_denying_pattern if {
570598
# Should return a list with the pattern that denied it
571599
# regal ignore:line-length
572600
patterns := tekton.denying_pattern(denied_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
601+
with ec.oci.image_manifests as _mock_image_manifests
573602
lib.assert_equal(["oci://quay.io/konflux-ci/tekton-catalog/task-buildah*"], patterns)
574603

575604
# Task that doesn't match any deny rule should return empty list
@@ -582,6 +611,7 @@ test_denying_pattern if {
582611

583612
# regal ignore:line-length
584613
patterns_empty := tekton.denying_pattern(non_matching_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
614+
with ec.oci.image_manifests as _mock_image_manifests
585615
lib.assert_equal([], patterns_empty)
586616
}
587617

@@ -646,6 +676,7 @@ test_denial_reason if {
646676

647677
# regal ignore:line-length
648678
reason_deny := tekton.denial_reason(denied_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
679+
with ec.oci.image_manifests as _mock_image_manifests
649680
lib.assert_equal("deny_rule", reason_deny.type)
650681
lib.assert_equal(["oci://quay.io/konflux-ci/tekton-catalog/task-buildah*"], reason_deny.pattern)
651682
lib.assert_equal(["This version is deprecated"], reason_deny.messages)
@@ -660,6 +691,7 @@ test_denial_reason if {
660691

661692
# regal ignore:line-length
662693
reason_not_allowed := tekton.denial_reason(not_allowed_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
694+
with ec.oci.image_manifests as _mock_image_manifests
663695
lib.assert_equal("not_allowed", reason_not_allowed.type)
664696
lib.assert_equal([], reason_not_allowed.pattern)
665697
lib.assert_equal([], reason_not_allowed.messages)
@@ -674,11 +706,13 @@ test_denial_reason if {
674706

675707
# regal ignore:line-length
676708
not tekton.denial_reason(allowed_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
709+
with ec.oci.image_manifests as _mock_image_manifests
677710

678711
# Task in legacy trusted_tasks but doesn't match allow rules should return "not_allowed"
679712
# (denial_reason only works with trusted_task_rules, not legacy)
680713
# regal ignore:line-length
681714
reason_legacy := tekton.denial_reason(trusted_bundle_task, _empty_bundle_manifests) with data.rule_data.trusted_task_rules as trusted_task_rules
715+
with ec.oci.image_manifests as _mock_image_manifests
682716
with data.trusted_tasks as trusted_tasks
683717
lib.assert_equal("not_allowed", reason_legacy.type)
684718
lib.assert_equal([], reason_legacy.pattern)
@@ -1116,3 +1150,20 @@ test_result_satisfies_operator if {
11161150
not tekton._result_satisfies_operator(0, "<2")
11171151
tekton._result_satisfies_operator(-1, "<2")
11181152
}
1153+
1154+
# Mock function for ec.oci.image_manifests
1155+
_mock_image_manifests(refs) := {ref: {} | some ref in refs}
1156+
1157+
# Mock function for ec.oci.image_manifest (singular)
1158+
_mock_image_manifest(_) := {}
1159+
1160+
test_mock_image_manifests if {
1161+
result := _mock_image_manifests({"ref1", "ref2"})
1162+
expected := {"ref1": {}, "ref2": {}}
1163+
lib.assert_equal(expected, result)
1164+
}
1165+
1166+
test_mock_image_manifest if {
1167+
result := _mock_image_manifest("any-ref")
1168+
lib.assert_equal({}, result)
1169+
}

policy/pipeline/required_tasks/required_tasks.rego

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ _all_bundle_refs contains bundle if {
2929
# We need to fetch each image to get the version annotation. Doing this separately for each bundle
3030
# is too slow.
3131
# This returns a map of bundle_ref -> manifest
32-
_manifests := ec.oci.image_manifests(_all_bundle_refs)
32+
default _manifests := {}
33+
34+
_manifests := ec.oci.image_manifests(_all_bundle_refs) if {
35+
count(_all_bundle_refs) > 0
36+
count(input.spec.tasks) > 0
37+
}
3338

3439
# =============================================================================
3540

0 commit comments

Comments
 (0)