Skip to content

Commit f85ff32

Browse files
authored
Let generic-worker verify run-task/fetch-content integrity (#666)
The decision task knows the contents of these scripts so it can pass their checksums to downstream tasks.
1 parent e9fb9b9 commit f85ff32

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/taskgraph/transforms/run/run_task.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"""
77

88
import dataclasses
9+
import hashlib
910
import os
11+
from pathlib import Path
1012

1113
from voluptuous import Any, Optional, Required
1214

@@ -25,6 +27,9 @@
2527
"powershell": ["powershell.exe", "-ExecutionPolicy", "Bypass"],
2628
}
2729

30+
RUN_TASK_PATH = Path(__file__).parent.parent.parent / "run-task" / "run-task"
31+
FETCH_CONTENT_PATH = Path(__file__).parent.parent.parent / "run-task" / "fetch-content"
32+
2833
run_task_schema = Schema(
2934
{
3035
Required("using"): "run-task",
@@ -169,10 +174,14 @@ def generic_worker_run_task(config, task, taskdesc):
169174
common_setup(config, task, taskdesc, command)
170175

171176
worker.setdefault("mounts", [])
177+
run_task_sha256 = hashlib.sha256(RUN_TASK_PATH.read_bytes()).hexdigest()
178+
fetch_content_sha256 = hashlib.sha256(FETCH_CONTENT_PATH.read_bytes()).hexdigest()
172179
worker["mounts"].append(
173180
{
174181
"content": {
175-
"url": script_url(config, "run-task"),
182+
"taskId": {"task-reference": "<decision>"},
183+
"artifact": "public/run-task",
184+
"sha256": run_task_sha256,
176185
},
177186
"file": "./run-task",
178187
}
@@ -181,7 +190,9 @@ def generic_worker_run_task(config, task, taskdesc):
181190
worker["mounts"].append(
182191
{
183192
"content": {
184-
"url": script_url(config, "fetch-content"),
193+
"taskId": {"task-reference": "<decision>"},
194+
"artifact": "public/fetch-content",
195+
"sha256": fetch_content_sha256,
185196
},
186197
"file": "./fetch-content",
187198
}

test/test_transforms_run_run_task.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def assert_generic_worker(task):
121121
{"cache-name": "checkouts", "directory": "build"},
122122
{
123123
"content": {
124-
"url": "https://tc-tests.localhost/api/queue/v1/task/<TASK_ID>/artifacts/public/run-task"
124+
"artifact": "public/run-task",
125+
"sha256": "581ca6876fac84fa2dd8e8c2c18677d790890e9675229fd34c912c937ae19fae",
126+
"taskId": {"task-reference": "<decision>"},
125127
},
126128
"file": "./run-task",
127129
},

0 commit comments

Comments
 (0)