Skip to content

Commit 4057a6f

Browse files
committed
Close Docker Config projection and bind observed lifecycle defaults
1 parent 3dffe66 commit 4057a6f

4 files changed

Lines changed: 287 additions & 24 deletions

File tree

‎scripts/ci/activity_acceptance_runtime.py‎

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import ipaddress
66
import re
7+
from pathlib import Path
78

89
OWNER = "dev.durable-workflow.fixture-owner"
910
RUN = "dev.durable-workflow.fixture-run"
@@ -81,39 +82,139 @@ def verify_network(record, identity, nonce):
8182
def expected_command(image, role, bootstrap):
8283
if role == "consumer":
8384
return ["/usr/local/bin/python3"], ["-I", "-B", "-c", bootstrap], "/"
84-
return image["Config"]["Entrypoint"], image["Config"]["Cmd"], image["Config"]["WorkingDir"]
85+
return image["Config"].get("Entrypoint"), image["Config"].get("Cmd"), image["Config"].get("WorkingDir", "")
8586

8687

87-
def verify_container(record, identity, nonce, image, network, child_digest, role, bootstrap=""):
88-
require_owner(record, identity, nonce, role)
89-
config, host = record["Config"], record["HostConfig"]
88+
def bind_local_image(index_record, platform_record, index_digest, child_digest, config_digest):
89+
if platform_record["Architecture"] != "amd64" or platform_record["Os"] != "linux":
90+
raise ValueError("local platform image differs")
91+
for record in (index_record, platform_record):
92+
if not any(value.rsplit("@", 1)[-1] == index_digest for value in record["RepoDigests"]):
93+
raise ValueError("local image lacks the selected immutable index")
94+
descriptor = platform_record.get("Descriptor")
95+
if index_record["Id"] == config_digest and platform_record["Id"] == config_digest:
96+
store = "classic"
97+
elif index_record["Id"] == index_digest and platform_record["Id"] == child_digest:
98+
store = "containerd"
99+
else:
100+
raise ValueError("local image IDs do not bind the selected manifest/config")
101+
if (store == "containerd" or descriptor is not None) and (
102+
descriptor is None
103+
or descriptor.get("digest") != child_digest
104+
or descriptor.get("platform") != {"architecture": "amd64", "os": "linux"}
105+
):
106+
raise ValueError("local platform descriptor differs")
107+
return {
108+
**platform_record,
109+
"CreateReference": index_record["Id"],
110+
"PlatformConfigDigest": config_digest,
111+
"ImageStore": store,
112+
}
113+
114+
115+
def verify_config(config, identity, nonce, image, role, bootstrap):
90116
environment = {key: value for key, value in (item.split("=", 1) for item in image["Config"]["Env"])}
91117
if role == "runtime":
92118
environment.update(ENVIRONMENT)
93119
received = {key: value for key, value in (item.split("=", 1) for item in config["Env"])}
94120
if len(received) != len(config["Env"]) or received != environment:
95121
raise ValueError("container environment differs")
96-
entrypoint, command, working_directory = expected_command(image, role, bootstrap)
122+
entrypoint, command, directory = expected_command(image, role, bootstrap)
123+
labels = {**(image["Config"].get("Labels") or {}), OWNER: "sdk-python", RUN: nonce, ROLE: role}
97124
expected = {
98-
"Image": image["Id"],
125+
"Hostname": identity[:12],
126+
"Domainname": "",
127+
"Image": image.get("CreateReference", image["Id"]),
99128
"User": "1000:1000",
100129
"Entrypoint": entrypoint,
101130
"Cmd": command,
102-
"WorkingDir": working_directory,
131+
"WorkingDir": directory,
103132
"Tty": False,
104133
"OpenStdin": role == "consumer",
134+
"StdinOnce": role == "consumer",
135+
"AttachStdin": role == "consumer",
136+
"AttachStdout": True,
137+
"AttachStderr": True,
138+
"Labels": labels,
139+
"Volumes": image["Config"].get("Volumes"),
140+
"ExposedPorts": image["Config"].get("ExposedPorts"),
141+
"Healthcheck": image["Config"].get("Healthcheck"),
142+
"StopSignal": image["Config"].get("StopSignal", ""),
143+
"StopTimeout": image["Config"].get("StopTimeout"),
144+
"Shell": image["Config"].get("Shell"),
145+
"OnBuild": image["Config"].get("OnBuild"),
146+
"ArgsEscaped": image["Config"].get("ArgsEscaped", False),
147+
"NetworkDisabled": False,
148+
"MacAddress": "",
105149
}
106-
if record["Image"] != image["Id"] or any(config.get(key) != value for key, value in expected.items()):
107-
raise ValueError("container image or command differs")
150+
if set(config) - (set(expected) | {"Env"}):
151+
raise ValueError("container has an unreviewed Config field")
152+
optional = {
153+
"ExposedPorts": None,
154+
"Healthcheck": None,
155+
"StopSignal": "",
156+
"StopTimeout": None,
157+
"Shell": None,
158+
"OnBuild": None,
159+
"ArgsEscaped": False,
160+
"NetworkDisabled": False,
161+
"MacAddress": "",
162+
}
163+
if (set(expected) - set(optional)) - set(config):
164+
raise ValueError("container Config lacks a required observation")
165+
for key, value in expected.items():
166+
received_value = config.get(key, optional[key]) if key in optional else config[key]
167+
if received_value != value:
168+
raise ValueError("container Config differs from the closed image/role projection")
169+
170+
171+
def verify_container(record, identity, nonce, image, network, child_digest, role, bootstrap="", *, cidfile=""):
172+
require_owner(record, identity, nonce, role)
173+
verify_config(record["Config"], identity, nonce, image, role, bootstrap)
174+
if record["Image"] != image.get("CreateReference", image["Id"]):
175+
raise ValueError("container image identity differs")
108176
descriptor = record.get("ImageManifestDescriptor")
109177
if descriptor is not None and descriptor.get("digest") != child_digest:
110178
raise ValueError("container platform child differs")
111-
verify_host(host, role, network)
179+
if image.get("ImageStore") == "containerd" and (
180+
descriptor is None or descriptor.get("platform") != {"os": "linux", "architecture": "amd64"}
181+
):
182+
raise ValueError("containerd platform descriptor is missing or different")
183+
verify_host(record["HostConfig"], role, network, cidfile=cidfile)
112184
if any(mount["Type"] != "tmpfs" or mount["Destination"] not in TMPFS[role] for mount in record["Mounts"]):
113185
raise ValueError("container has an undeclared mount")
114186

115187

116-
def verify_host(host, role, network):
188+
MASKED_PATHS = {
189+
"/proc/acpi",
190+
"/proc/asound",
191+
"/proc/interrupts",
192+
"/proc/kcore",
193+
"/proc/keys",
194+
"/proc/latency_stats",
195+
"/proc/sched_debug",
196+
"/proc/scsi",
197+
"/proc/timer_list",
198+
"/proc/timer_stats",
199+
"/sys/devices/virtual/powercap",
200+
"/sys/firmware",
201+
}
202+
READONLY_PATHS = {"/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"}
203+
204+
205+
def expected_masked_paths():
206+
# The fixed local daemon also masks the kernel's CPU thermal-throttle paths.
207+
return MASKED_PATHS | {str(path) for path in Path("/sys/devices/system/cpu").glob("cpu[0-9]*/thermal_throttle")}
208+
209+
210+
def verify_protected_paths(host):
211+
for field, expected in (("MaskedPaths", expected_masked_paths()), ("ReadonlyPaths", READONLY_PATHS)):
212+
actual = host.get(field)
213+
if not isinstance(actual, list) or len(actual) != len(set(actual)) or set(actual) != expected:
214+
raise ValueError("container protected system paths differ")
215+
216+
217+
def verify_host(host, role, network, *, cidfile=""):
117218
expected = {
118219
"NetworkMode": network,
119220
"ReadonlyRootfs": True,
@@ -128,7 +229,8 @@ def verify_host(host, role, network):
128229
"Tmpfs": TMPFS[role],
129230
"PublishAllPorts": False,
130231
"AutoRemove": False,
131-
"OomKillDisable": False,
232+
"ContainerIDFile": cidfile,
233+
"ConsoleSize": [0, 0],
132234
"MemorySwappiness": None,
133235
"ShmSize": 67_108_864,
134236
"Runtime": "runc",
@@ -139,7 +241,12 @@ def verify_host(host, role, network):
139241
}
140242
if any(host.get(key) != value for key, value in expected.items()):
141243
raise ValueError("container resource/network/security configuration differs")
244+
if "OomKillDisable" not in host or (host["OomKillDisable"] is not False and host["OomKillDisable"] is not None):
245+
raise ValueError("container disables the OOM killer or lacks its lifecycle value")
246+
verify_protected_paths(host)
142247
zero_fields = (
248+
"IOMaximumIOps",
249+
"IOMaximumBandwidth",
143250
"CpuShares",
144251
"CpuPeriod",
145252
"CpuQuota",
@@ -156,6 +263,7 @@ def verify_host(host, role, network):
156263
if any(host.get(key, 0) != 0 for key in zero_fields):
157264
raise ValueError("container has an undeclared resource override")
158265
forbidden = (
266+
"Annotations",
159267
"Binds",
160268
"VolumesFrom",
161269
"Devices",
@@ -188,6 +296,9 @@ def verify_host(host, role, network):
188296
"BlkioDeviceReadIOps",
189297
"BlkioDeviceWriteIOps",
190298
)
299+
known = set(expected) | set(zero_fields) | set(forbidden) | {"OomKillDisable", "MaskedPaths", "ReadonlyPaths"}
300+
if set(host) - known:
301+
raise ValueError("container has an unreviewed HostConfig field")
191302
if any(host.get(key) for key in forbidden):
192303
raise ValueError("container has an undeclared host resource")
193304

@@ -225,6 +336,8 @@ def create_arguments(image, network, nonce, cidfile, role, bootstrap=""):
225336
"docker",
226337
"create",
227338
"--pull=never",
339+
"--platform",
340+
"linux/amd64",
228341
"--cidfile",
229342
str(cidfile),
230343
"--name",
@@ -278,12 +391,12 @@ def create_arguments(image, network, nonce, cidfile, role, bootstrap=""):
278391
"/",
279392
"--entrypoint",
280393
"/usr/local/bin/python3",
281-
image["Id"],
394+
image.get("CreateReference", image["Id"]),
282395
"-I",
283396
"-B",
284397
"-c",
285398
bootstrap,
286399
]
287400
for key, value in ENVIRONMENT.items():
288401
arguments.extend(["-e", key + "=" + value])
289-
return [*arguments, image["Id"]]
402+
return [*arguments, image.get("CreateReference", image["Id"])]

‎scripts/ci/published-activity-acceptance.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ container has a read-only root, an unprivileged user, all capabilities dropped,
2929
no new privileges, one CPU, 1 GiB RAM with no additional swap and 256 PIDs.
3030
Writable temporary storage stays inside that memory limit.
3131

32+
Config and HostConfig use closed projections. Healthchecks must match the
33+
published image, and protected system paths must match the local daemon's
34+
reviewed defaults, including kernel-exposed thermal-throttle paths. Docker 29's
35+
observed false/null OOM-disable transition is accepted; true still refuses.
36+
Platform-specific inspection binds containerd's index/child identities or a
37+
classic store's config identity to the selected immutable manifest chain.
38+
3239
Central action-policy and lint gates precede execution. The controller has a
3340
six-minute execution bound, followed by independent cleanup of each captured
3441
ID and then the network. Label-bound reconciliation covers uncertain create

‎scripts/ci/published-activity-acceptance.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,20 @@ def verify_published_image(selected, role, files):
185185
for item in index["manifests"]
186186
if item.get("platform") == {"architecture": "amd64", "os": "linux"}
187187
]
188-
observed = json.loads(call("docker", "image", "inspect", image).stdout)[0]
189-
if (
190-
platforms != [child_digest]
191-
or observed["Architecture"] != "amd64"
192-
or observed["Os"] != "linux"
193-
or not any(value.rsplit("@", 1)[-1] == image.rsplit("@", 1)[-1] for value in observed["RepoDigests"])
194-
or observed["Id"] != child["config"]["digest"]
195-
):
196-
raise ValueError("local image differs from the exact published platform child")
188+
if platforms != [child_digest]:
189+
raise ValueError("published index differs from the selected platform child")
190+
local_index = json.loads(call("docker", "image", "inspect", image).stdout)[0]
191+
local_platform = json.loads(call("docker", "image", "inspect", "--platform", "linux/amd64", image).stdout)[0]
192+
observed = runtime.bind_local_image(
193+
local_index, local_platform, image.rsplit("@", 1)[-1], child_digest, child["config"]["digest"]
194+
)
197195
if role == "runtime":
198196
if observed["Config"]["Labels"]["org.opencontainers.image.revision"] != selected["server_source"]:
199197
raise ValueError("runtime source differs")
200198
elif "PYTHON_VERSION=" + selected["python_version"] not in observed["Config"]["Env"]:
201199
raise ValueError("consumer interpreter image differs")
202200
files.write(role + "-image.json", json.dumps(observed, indent=2))
201+
files.write(role + "-local-index.json", json.dumps(local_index, indent=2))
203202
files.write(role + "-index.json", index_text)
204203
files.write(role + "-manifest.json", child_text)
205204
return observed
@@ -273,7 +272,17 @@ def create(self, role, image, child, bootstrap):
273272
def verify(self, role, image, child, bootstrap):
274273
identity = self.identities[role]
275274
record = self.inspect("container", identity)
276-
runtime.verify_container(record, identity, self.nonce, image, self.network, child, role, bootstrap)
275+
runtime.verify_container(
276+
record,
277+
identity,
278+
self.nonce,
279+
image,
280+
self.network,
281+
child,
282+
role,
283+
bootstrap,
284+
cidfile=str(OUTPUT / (role + ".cid")),
285+
)
277286
return record
278287

279288
def boundary(self, images, selected, bootstrap, phase):

0 commit comments

Comments
 (0)