Skip to content

Commit 855b1d8

Browse files
authored
Merge pull request #1228 from zregvart/issue/EC-944
2 parents 4bfe04a + 7176fde commit 855b1d8

File tree

11 files changed

+193
-63
lines changed

11 files changed

+193
-63
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Confirm the `trusted_tasks` rule data was provided, since it's required by the p
1919
* Rule type: [rule-type-indicator failure]#FAILURE#
2020
* FAILURE message: `Missing required trusted_tasks data`
2121
* Code: `task_bundle.missing_required_data`
22-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L92[Source, window="_blank"]
22+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L94[Source, window="_blank"]
2323
2424
[#task_bundle__untrusted_task_bundle]
2525
=== link:#task_bundle__untrusted_task_bundle[Task bundle is not trusted]
@@ -29,15 +29,15 @@ For each Task in the Pipeline definition, check if the Tekton Bundle used is a t
2929
* Rule type: [rule-type-indicator failure]#FAILURE#
3030
* FAILURE message: `Pipeline task '%s' uses an untrusted task bundle '%s'`
3131
* Code: `task_bundle.untrusted_task_bundle`
32-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L77[Source, window="_blank"]
32+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L79[Source, window="_blank"]
3333
3434
[#task_bundle__out_of_date_task_bundle]
3535
=== link:#task_bundle__out_of_date_task_bundle[Task bundle is out of date]
3636
3737
For each Task in the Pipeline definition, check if the Tekton Bundle used is the most recent.
3838
3939
* Rule type: [rule-type-indicator warning]#WARNING#
40-
* WARNING message: `Pipeline task '%s' uses an out of date task bundle '%s'`
40+
* WARNING message: `Pipeline task '%s' uses an out of date task bundle '%s', new version of the Task must be used before %s`
4141
* Code: `task_bundle.out_of_date_task_bundle`
4242
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L34[Source, window="_blank"]
4343
@@ -49,7 +49,7 @@ Check that a valid task bundle reference is being used.
4949
* Rule type: [rule-type-indicator failure]#FAILURE#
5050
* FAILURE message: `Pipeline task '%s' uses an empty bundle image reference`
5151
* Code: `task_bundle.empty_task_bundle_reference`
52-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L64[Source, window="_blank"]
52+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L66[Source, window="_blank"]
5353
5454
[#task_bundle__disallowed_task_reference]
5555
=== link:#task_bundle__disallowed_task_reference[Task bundle was not used or is not defined]
@@ -59,7 +59,7 @@ Check for the existence of a task bundle. This rule will fail if the task is not
5959
* Rule type: [rule-type-indicator failure]#FAILURE#
6060
* FAILURE message: `Pipeline task '%s' does not contain a bundle reference`
6161
* Code: `task_bundle.disallowed_task_reference`
62-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L50[Source, window="_blank"]
62+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/pipeline/task_bundle/task_bundle.rego#L52[Source, window="_blank"]
6363
6464
[#task_bundle__unpinned_task_bundle]
6565
=== link:#task_bundle__unpinned_task_bundle[Unpinned task bundle reference]

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ Confirm the `trusted_tasks` rule data was provided, since it's required by the p
16021602
* Rule type: [rule-type-indicator failure]#FAILURE#
16031603
* FAILURE message: `Missing required trusted_tasks data`
16041604
* Code: `attestation_task_bundle.trusted_bundles_provided`
1605-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L113[Source, window="_blank"]
1605+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L114[Source, window="_blank"]
16061606

16071607
[#attestation_task_bundle__task_ref_bundles_not_empty]
16081608
=== link:#attestation_task_bundle__task_ref_bundles_not_empty[Task bundle references not empty]
@@ -1614,7 +1614,7 @@ Check that a valid task bundle reference is being used.
16141614
* Rule type: [rule-type-indicator failure]#FAILURE#
16151615
* FAILURE message: `Pipeline task '%s' uses an empty bundle image reference`
16161616
* Code: `attestation_task_bundle.task_ref_bundles_not_empty`
1617-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L75[Source, window="_blank"]
1617+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L76[Source, window="_blank"]
16181618

16191619
[#attestation_task_bundle__task_ref_bundles_pinned]
16201620
=== link:#attestation_task_bundle__task_ref_bundles_pinned[Task bundle references pinned to digest]
@@ -1638,7 +1638,7 @@ For each Task in the SLSA Provenance attestation, check if the Tekton Bundle use
16381638
* Rule type: [rule-type-indicator failure]#FAILURE#
16391639
* FAILURE message: `Pipeline task '%s' uses an untrusted task bundle '%s'`
16401640
* Code: `attestation_task_bundle.task_ref_bundles_trusted`
1641-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L92[Source, window="_blank"]
1641+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L93[Source, window="_blank"]
16421642

16431643
[#attestation_task_bundle__task_ref_bundles_current]
16441644
=== link:#attestation_task_bundle__task_ref_bundles_current[Task bundles are latest versions]
@@ -1648,7 +1648,7 @@ For each Task in the SLSA Provenance attestation, check if the Tekton Bundle use
16481648
*Solution*: A task bundle used is not the most recent. The most recent task bundles are defined in the data source of your policy config.
16491649

16501650
* Rule type: [rule-type-indicator warning]#WARNING#
1651-
* WARNING message: `Pipeline task '%s' uses an out of date task bundle '%s'`
1651+
* WARNING message: `Pipeline task '%s' uses an out of date task bundle '%s', new version of the Task must be used before %s`
16521652
* Code: `attestation_task_bundle.task_ref_bundles_current`
16531653
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L38[Source, window="_blank"]
16541654

@@ -1660,7 +1660,7 @@ Check for the existence of a task bundle. This rule will fail if the task is not
16601660
* Rule type: [rule-type-indicator failure]#FAILURE#
16611661
* FAILURE message: `Pipeline task '%s' does not contain a bundle reference`
16621662
* Code: `attestation_task_bundle.tasks_defined_in_bundle`
1663-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L59[Source, window="_blank"]
1663+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/attestation_task_bundle/attestation_task_bundle.rego#L60[Source, window="_blank"]
16641664

16651665
[#tasks_package]
16661666
== link:#tasks_package[Tasks]
@@ -1933,7 +1933,7 @@ Confirm the expected `trusted_tasks` data keys have been provided in the expecte
19331933
* Rule type: [rule-type-indicator failure]#FAILURE#
19341934
* FAILURE message: `%s`
19351935
* Code: `trusted_task.data_format`
1936-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L184[Source, window="_blank"]
1936+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L187[Source, window="_blank"]
19371937

19381938
[#trusted_task__pinned]
19391939
=== link:#trusted_task__pinned[Task references are pinned]
@@ -1959,7 +1959,7 @@ Confirm the `trusted_tasks` rule data was provided, since it's required by the p
19591959
* FAILURE message: `Missing required trusted_tasks data`
19601960
* Code: `trusted_task.data`
19611961
* Effective from: `2024-05-07T00:00:00Z`
1962-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L134[Source, window="_blank"]
1962+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L137[Source, window="_blank"]
19631963

19641964
[#trusted_task__trusted]
19651965
=== link:#trusted_task__trusted[Tasks are trusted]
@@ -1972,7 +1972,7 @@ Check the trust of the Tekton Tasks used in the build Pipeline. There are two mo
19721972
* FAILURE message: `%s`
19731973
* Code: `trusted_task.trusted`
19741974
* Effective from: `2024-05-07T00:00:00Z`
1975-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L71[Source, window="_blank"]
1975+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L74[Source, window="_blank"]
19761976

19771977
[#trusted_task__current]
19781978
=== link:#trusted_task__current[Tasks using the latest versions]
@@ -1982,7 +1982,7 @@ Check if all Tekton Tasks use the latest known Task reference.
19821982
*Solution*: Update the Task reference to a newer version.
19831983

19841984
* Rule type: [rule-type-indicator warning]#WARNING#
1985-
* WARNING message: `Pipeline task %q uses an out of date task reference, %s`
1985+
* WARNING message: `Pipeline task %q uses an out of date task reference, %s. A new version of the task must be used before %s`
19861986
* Code: `trusted_task.current`
19871987
* Effective from: `2024-05-07T00:00:00Z`
19881988
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L49[Source, window="_blank"]
@@ -1997,7 +1997,7 @@ All input trusted artifacts must be produced on the pipeline. If they are not th
19971997
* Rule type: [rule-type-indicator failure]#FAILURE#
19981998
* FAILURE message: `Code tampering detected, input %q for task %q was not produced by the pipeline as attested.`
19991999
* Code: `trusted_task.valid_trusted_artifact_inputs`
2000-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L97[Source, window="_blank"]
2000+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L100[Source, window="_blank"]
20012001

20022002
[#trusted_task__trusted_parameters]
20032003
=== link:#trusted_task__trusted_parameters[Trusted parameters]
@@ -2010,7 +2010,7 @@ Confirm certain parameters provided to each builder Task have come from trusted
20102010
* FAILURE message: `The %q parameter of the %q PipelineTask includes an untrusted digest: %s`
20112011
* Code: `trusted_task.trusted_parameters`
20122012
* Effective from: `2021-07-04T00:00:00Z`
2013-
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L153[Source, window="_blank"]
2013+
* https://github.com/enterprise-contract/ec-policies/blob/{page-origin-refhash}/policy/release/trusted_task/trusted_task.rego#L156[Source, window="_blank"]
20142014

20152015
[#rpm_ostree_task_package]
20162016
== link:#rpm_ostree_task_package[rpm-ostree Task]

policy/lib/rule_data.rego

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ rule_data_defaults := {
9797
# using the ruleData key. Make this default to an empty dict so we can conveniently
9898
# merge it with with `data.trusted_tasks`
9999
"trusted_tasks": {},
100+
# Number of days before a version of the Task expires that warnings are reported
101+
"task_expiry_warning_days": 0,
100102
}
101103

102104
# Returns the "first found" of the following:

policy/lib/tekton/trusted.rego

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ missing_trusted_tasks_data if {
2121
count(_trusted_tasks) == 0
2222
}
2323

24-
# Returns a subset of tasks that use a trusted Task reference, but an updated Task reference exists.
25-
out_of_date_task_refs(tasks) := {task |
26-
some task in tasks
27-
is_trusted_task(task)
28-
_newer_record_exists(task)
24+
default task_expiry_warnings_after := 0
25+
26+
task_expiry_warnings_after := grace if {
27+
grace_period_days := lib_rule_data("task_expiry_warning_days")
28+
grace_period_days > 0
29+
grace := time.add_date(
30+
time_lib.effective_current_time_ns, 0, 0,
31+
grace_period_days,
32+
)
33+
}
34+
35+
# Returns the epoch time in nanoseconds of the time when the Task expires, or
36+
# nothing if Task is not set to expire currently.
37+
expiry_of(task) := expires if {
38+
expires := _task_expires_on(task)
39+
40+
# only report if the task is expiring within task_expiry_warning_days days
41+
expires > task_expiry_warnings_after
2942
}
3043

3144
# Returns a subset of tasks that do not use a trusted Task reference.
@@ -47,19 +60,16 @@ is_trusted_task(task) if {
4760
record.ref == ref.pinned_ref
4861
}
4962

50-
# Returns true if a newer record exists with a different digest.
51-
_newer_record_exists(task) if {
63+
# Returns the date in epoch nanoseconds when the task expires, or nothing if it
64+
# hasn't expired yet.
65+
_task_expires_on(task) := expires if {
5266
ref := task_ref(task)
5367
records := _trusted_tasks[ref.key]
5468

55-
newest_record := time_lib.newest(records)
56-
newest_record.ref != ref.pinned_ref
57-
58-
# newest record could have the same effective_on as the record for the given
59-
# task, in that case we can't claim that the newer record exists
6069
some record in records
6170
record.ref == ref.pinned_ref
62-
newest_record.effective_on != record.effective_on
71+
72+
expires = time.parse_rfc3339_ns(record.expires_on)
6373
}
6474

6575
# _trusted_tasks provides a safe way to access the list of trusted tasks. It prevents a policy rule
@@ -126,3 +136,17 @@ data_errors contains error if {
126136
"severity": "failure",
127137
}
128138
}
139+
140+
data_errors contains error if {
141+
some error in j.validate_schema(
142+
{"task_expiry_warning_days": lib_rule_data("task_expiry_warning_days")},
143+
{
144+
"$schema": "http://json-schema.org/draft-07/schema#",
145+
"type": "object",
146+
"properties": {"task_expiry_warning_days": {
147+
"type": "integer",
148+
"minimum": 0,
149+
}},
150+
},
151+
)
152+
}

0 commit comments

Comments
 (0)