Skip to content

Commit 18ffe2a

Browse files
bhearsumahal
authored andcommitted
fix: chain of trust should influence cache digest
Chain of trust being enabled or disabled influences the outcome of a task. Specifically, it controls whether or not chain of trust artifacts will be present on the task. Without this impacting the cache digest, cached tasks will continue to be cached when chain of trust is enabled on them, and if there is a chain of trust verifier downstream, this will cause verification issues. BREAKING CHANGE: worker.chain-of-trust now influences cache digests
1 parent f20ebf1 commit 18ffe2a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/taskgraph/transforms/cached_tasks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ def cache_task(config, tasks):
7777
task["label"], p
7878
)
7979
)
80+
8081
digest_data = cache["digest-data"] + sorted(dependency_digests)
82+
83+
# Chain of trust affects task artifacts therefore it should influence
84+
# cache digest.
85+
if task.get("worker", {}).get("chain-of-trust"):
86+
digest_data.append(str(task["worker"]["chain-of-trust"]))
87+
8188
add_optimization(
8289
config,
8390
task,

test/test_transforms_cached_tasks.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def assert_cache_with_non_cached_dependency(e):
9191
handle_exception(e, exc=Exception)
9292

9393

94+
def assert_chain_of_trust_influences_digest(tasks):
95+
assert len(tasks) == 3
96+
# The first two tasks are chain-of-trust unspecified, and chain-of-trust: False
97+
# which should result in the same digest.
98+
digest_0 = tasks[0]["attributes"]["cached_task"]["digest"]
99+
digest_1 = tasks[1]["attributes"]["cached_task"]["digest"]
100+
assert digest_0 == digest_1
101+
102+
# The third task is chain-of-trust: True, and should have a different digest
103+
digest_2 = tasks[2]["attributes"]["cached_task"]["digest"]
104+
assert digest_0 != digest_2
105+
106+
94107
@pytest.mark.parametrize(
95108
"tasks, kind_config, deps",
96109
(
@@ -177,6 +190,45 @@ def assert_cache_with_non_cached_dependency(e):
177190
{"dep": make_task("dep")},
178191
id="cache_with_non_cached_dependency",
179192
),
193+
pytest.param(
194+
# tasks
195+
[
196+
{
197+
"cache": {
198+
"type": "cached-task.v2",
199+
"name": "cache-foo",
200+
"digest-data": ["abc"],
201+
},
202+
# no explicit chain of trust configuration; should be the
203+
# same as when it is set to False
204+
},
205+
{
206+
"cache": {
207+
"type": "cached-task.v2",
208+
"name": "cache-foo",
209+
"digest-data": ["abc"],
210+
},
211+
"worker": {
212+
"chain-of-trust": False,
213+
},
214+
},
215+
{
216+
"cache": {
217+
"type": "cached-task.v2",
218+
"name": "cache-foo",
219+
"digest-data": ["abc"],
220+
},
221+
"worker": {
222+
"chain-of-trust": True
223+
},
224+
},
225+
],
226+
# kind config
227+
{},
228+
# kind deps
229+
{},
230+
id="chain_of_trust_influences_digest",
231+
),
180232
),
181233
)
182234
def test_transforms(

0 commit comments

Comments
 (0)