noqt commited on
Commit
9be12d2
·
unverified ·
1 Parent(s): d3c5597

Publish hosted-proof receipt schema (#31)

Browse files

* docs: publish hosted proof receipt schema

* test: bind receipt schema to hosted workflow

* fix: enforce executable receipt latency bound

.github/workflows/ci.yml CHANGED
@@ -26,7 +26,7 @@ jobs:
26
  python-version: ${{ matrix.python-version }}
27
 
28
  - name: Install test tooling
29
- run: python -m pip install ruff==0.16.1 PyYAML==6.0.3
30
 
31
  - name: Lint
32
  if: matrix.python-version == '3.11'
 
26
  python-version: ${{ matrix.python-version }}
27
 
28
  - name: Install test tooling
29
+ run: python -m pip install jsonschema==4.26.0 ruff==0.16.1 PyYAML==6.0.3
30
 
31
  - name: Lint
32
  if: matrix.python-version == '3.11'
.github/workflows/containment-probe.yml CHANGED
@@ -274,7 +274,7 @@ jobs:
274
  type(latency) not in {int, float}
275
  or not math.isfinite(latency)
276
  or latency < 0
277
- or latency > 120_000
278
  ):
279
  unexpected()
280
  print(json.dumps(receipt, sort_keys=True, separators=(",", ":")))
@@ -308,7 +308,7 @@ jobs:
308
  run: |
309
  {
310
  printf '## Share what happened\n\n'
311
- printf 'Passed, refused safely, or hit friction? '
312
  printf '[Send the result to Lumi Eggcracker](%s).\n\n' "$RESULT_FORM_URL"
313
  printf 'The short form asks for this public run and the outcome:\n\n'
314
  printf '`%s`\n' "$WORKFLOW_RUN_URL"
 
274
  type(latency) not in {int, float}
275
  or not math.isfinite(latency)
276
  or latency < 0
277
+ or latency > 20_000
278
  ):
279
  unexpected()
280
  print(json.dumps(receipt, sort_keys=True, separators=(",", ":")))
 
308
  run: |
309
  {
310
  printf '## Share what happened\n\n'
311
+ printf 'Passed, returned a redacted failure, or hit friction? '
312
  printf '[Send the result to Lumi Eggcracker](%s).\n\n' "$RESULT_FORM_URL"
313
  printf 'The short form asks for this public run and the outcome:\n\n'
314
  printf '`%s`\n' "$WORKFLOW_RUN_URL"
CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ Use Python 3.11 or newer. The ordinary unit suite does not grant permission to
24
  run native root or containment tests on your workstation.
25
 
26
  ```sh
27
- python -m pip install ruff==0.16.1 PyYAML==6.0.3
28
  ruff check src tests scripts
29
  PYTHONPATH=src python -m unittest discover -s tests -v
30
  ```
 
24
  run native root or containment tests on your workstation.
25
 
26
  ```sh
27
+ python -m pip install jsonschema==4.26.0 ruff==0.16.1 PyYAML==6.0.3
28
  ruff check src tests scripts
29
  PYTHONPATH=src python -m unittest discover -s tests -v
30
  ```
TRY_IT.md CHANGED
@@ -50,8 +50,15 @@ run prints a JSON receipt with `"result":"TERMINATED"`,
50
  `"target_survivors":0` and `"canary_survived":true`, followed by
51
  `FORK_PROBE_RESULT=PASS`.
52
 
53
- If it passes, refuses safely or gives you confusing friction, [send the public
54
- run](https://github.com/noqt/Lumi-Eggcracker/issues/new?template=hosted_probe_result.yml).
 
 
 
 
 
 
 
55
  The short form asks for the workflow URL and what happened. That is useful
56
  evidence either way.
57
 
 
50
  `"target_survivors":0` and `"canary_survived":true`, followed by
51
  `FORK_PROBE_RESULT=PASS`.
52
 
53
+ Automations can validate that current PASS receipt, or a redacted refusal or
54
+ failure receipt, against the versioned [hosted-proof receipt v1 schema](schemas/hosted-proof-receipt-v1.schema.json).
55
+ Schema validation checks structure only. It does not authenticate the run,
56
+ source commit or tree, workflow or host, and it does not claim that the host is
57
+ suitable for production or that Eggcracker detected a real workload. The v1
58
+ file remains compatible; an incompatible contract uses a new versioned path.
59
+
60
+ If it passes, returns a redacted failure or gives you confusing friction,
61
+ [send the public run](https://github.com/noqt/Lumi-Eggcracker/issues/new?template=hosted_probe_result.yml).
62
  The short form asks for the workflow URL and what happened. That is useful
63
  evidence either way.
64
 
schemas/hosted-proof-receipt-v1.schema.json ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/schemas/hosted-proof-receipt-v1.schema.json",
4
+ "title": "Lumi Eggcracker hosted-proof receipt v1",
5
+ "description": "Public contract for the current hosted containment proof's success and redacted refusal-or-failure receipts.",
6
+ "oneOf": [
7
+ {
8
+ "title": "Successful containment proof",
9
+ "type": "object",
10
+ "additionalProperties": false,
11
+ "required": [
12
+ "canary_survived",
13
+ "changes_made",
14
+ "cleanup_complete",
15
+ "descendant_cgroups_checked",
16
+ "installation_performed",
17
+ "journal_history_may_persist",
18
+ "mode",
19
+ "network_requests_made",
20
+ "primitive",
21
+ "result",
22
+ "root_populated",
23
+ "source_commit",
24
+ "source_tree_sha256",
25
+ "target_processes",
26
+ "target_survivors",
27
+ "trigger_to_empty_ms",
28
+ "workload_detection_performed"
29
+ ],
30
+ "properties": {
31
+ "canary_survived": {
32
+ "const": true
33
+ },
34
+ "changes_made": {
35
+ "const": true
36
+ },
37
+ "cleanup_complete": {
38
+ "const": true
39
+ },
40
+ "descendant_cgroups_checked": {
41
+ "type": "integer",
42
+ "minimum": 1
43
+ },
44
+ "installation_performed": {
45
+ "const": false
46
+ },
47
+ "journal_history_may_persist": {
48
+ "const": true
49
+ },
50
+ "mode": {
51
+ "const": "containment-primitive-probe"
52
+ },
53
+ "network_requests_made": {
54
+ "const": false
55
+ },
56
+ "primitive": {
57
+ "const": "pidfd-stop+cgroup.kill"
58
+ },
59
+ "result": {
60
+ "const": "TERMINATED"
61
+ },
62
+ "root_populated": {
63
+ "const": 0
64
+ },
65
+ "source_commit": {
66
+ "type": "string",
67
+ "pattern": "^[0-9a-f]{40}$"
68
+ },
69
+ "source_tree_sha256": {
70
+ "type": "string",
71
+ "pattern": "^[0-9a-f]{64}$"
72
+ },
73
+ "target_processes": {
74
+ "const": 2
75
+ },
76
+ "target_survivors": {
77
+ "const": 0
78
+ },
79
+ "trigger_to_empty_ms": {
80
+ "type": "number",
81
+ "minimum": 0,
82
+ "maximum": 20000
83
+ },
84
+ "workload_detection_performed": {
85
+ "const": false
86
+ }
87
+ }
88
+ },
89
+ {
90
+ "title": "Redacted probe refusal or failure",
91
+ "type": "object",
92
+ "additionalProperties": false,
93
+ "required": [
94
+ "mode",
95
+ "reason_code",
96
+ "result"
97
+ ],
98
+ "properties": {
99
+ "mode": {
100
+ "const": "containment-primitive-probe"
101
+ },
102
+ "reason_code": {
103
+ "type": "string",
104
+ "enum": [
105
+ "ACTIVE_INSTALLATION_REFUSED",
106
+ "BOOT_IDENTITY_DRIFT",
107
+ "CANARY_DIED",
108
+ "CANARY_IDENTITY_UNAVAILABLE",
109
+ "CANARY_INSIDE_TARGET_OWNER",
110
+ "CGROUP_CONTROL_SHORT_WRITE",
111
+ "CGROUP_IDENTITY_INVALID",
112
+ "CGROUP_IDENTITY_UNAVAILABLE",
113
+ "CGROUP_PROCESS_LIST_INVALID",
114
+ "CGROUP_PROCESS_READ_FAILED",
115
+ "CGROUP_V2_UNAVAILABLE",
116
+ "CLEANUP_INCOMPLETE",
117
+ "CONTAINER_UNSUPPORTED",
118
+ "CONTROL_GROUP_DRIFT",
119
+ "CONTROL_GROUP_INVALID",
120
+ "DISPOSABLE_HOST_ACK_REQUIRED",
121
+ "EMPTY_PROOF_TIMEOUT",
122
+ "EMPTY_PROOF_UNAVAILABLE",
123
+ "HELD_PIDFD_CLEANUP_FAILED",
124
+ "HOST_COMMAND_FAILED",
125
+ "HOST_IDENTITY_UNAVAILABLE",
126
+ "INTERRUPTED",
127
+ "INVOCATION_ID_DRIFT",
128
+ "INVOCATION_ID_INVALID",
129
+ "NATIVE_LINUX_REQUIRED",
130
+ "OWNER_CGROUP_IDENTITY_DRIFT",
131
+ "OWNER_TASK_CONTROLS_MISSING",
132
+ "OWNER_TASK_LIMIT_INVALID",
133
+ "OWNER_TASK_LIMIT_UNAVAILABLE",
134
+ "PIDFD_LIVENESS_FAILED",
135
+ "PIDFD_UNAVAILABLE",
136
+ "PIDS_CONTROLLER_UNAVAILABLE",
137
+ "PROBE_INCOMPLETE",
138
+ "PROBE_STAGE_FAILED",
139
+ "PROCESS_CGROUP_INVALID",
140
+ "PROCESS_CGROUP_UNAVAILABLE",
141
+ "PROCESS_IDENTITY_DRIFT",
142
+ "RECEIPT_SCHEMA_INVALID",
143
+ "REQUIRED_COMMAND_MISSING",
144
+ "ROOT_REQUIRED",
145
+ "SOURCE_COMMIT_INVALID",
146
+ "SOURCE_COMMIT_UNAVAILABLE",
147
+ "SOURCE_GIT_IDENTITY_REQUIRED",
148
+ "SOURCE_IDENTITY_DRIFT",
149
+ "SOURCE_IDENTITY_INVALID",
150
+ "SOURCE_REFERENCE_INVALID",
151
+ "SOURCE_TREE_UNAVAILABLE",
152
+ "SYSTEMD_PID1_REQUIRED",
153
+ "TARGET_CGROUP_CONTROLS_MISSING",
154
+ "TARGET_CGROUP_CREATE_FAILED",
155
+ "TARGET_CGROUP_EVENTS_INVALID",
156
+ "TARGET_CGROUP_IDENTITY_DRIFT",
157
+ "TARGET_OUTSIDE_CAPTURED_CGROUP",
158
+ "TARGET_READINESS_TIMEOUT",
159
+ "UBUNTU_2404_REQUIRED",
160
+ "UNIT_COLLISION",
161
+ "UNIT_IDENTITY_UNAVAILABLE",
162
+ "UNIT_NAME_INVALID",
163
+ "UNIT_START_FAILED",
164
+ "UNIT_STATE_UNAVAILABLE",
165
+ "WSL_UNSUPPORTED"
166
+ ]
167
+ },
168
+ "result": {
169
+ "const": "FAILED"
170
+ }
171
+ }
172
+ }
173
+ ]
174
+ }
tests/test_hosted_proof_receipt_schema.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import ast
4
+ import json
5
+ import re
6
+ import unittest
7
+ from pathlib import Path
8
+
9
+ from jsonschema import ValidationError
10
+ from jsonschema.validators import validator_for
11
+
12
+ from lumi_eggcracker import containment_probe as probe
13
+
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+ SCHEMA_PATH = ROOT / "schemas" / "hosted-proof-receipt-v1.schema.json"
16
+ WORKFLOW_PATH = ROOT / ".github" / "workflows" / "containment-probe.yml"
17
+
18
+
19
+ def workflow_failure_codes() -> set[str]:
20
+ workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
21
+ match = re.search(r"allowed_failures = (\{.*?^\s*\})", workflow, re.MULTILINE | re.DOTALL)
22
+ if match is None:
23
+ raise AssertionError("hosted workflow failure allowlist is missing")
24
+ values = ast.literal_eval(match.group(1))
25
+ if not isinstance(values, set) or not all(isinstance(value, str) for value in values):
26
+ raise AssertionError("hosted workflow failure allowlist is invalid")
27
+ return values
28
+
29
+
30
+ def workflow_latency_maximum_ms() -> int:
31
+ workflow = WORKFLOW_PATH.read_text(encoding="utf-8")
32
+ match = re.search(r"or latency > ([0-9_]+)", workflow)
33
+ if match is None:
34
+ raise AssertionError("hosted workflow latency bound is missing")
35
+ return int(match.group(1).replace("_", ""))
36
+
37
+
38
+ def success_receipt() -> dict[str, object]:
39
+ return {
40
+ "canary_survived": True,
41
+ "changes_made": True,
42
+ "cleanup_complete": True,
43
+ "descendant_cgroups_checked": 1,
44
+ "installation_performed": False,
45
+ "journal_history_may_persist": True,
46
+ "mode": "containment-primitive-probe",
47
+ "network_requests_made": False,
48
+ "primitive": "pidfd-stop+cgroup.kill",
49
+ "result": "TERMINATED",
50
+ "root_populated": 0,
51
+ "source_commit": "a" * 40,
52
+ "source_tree_sha256": "b" * 64,
53
+ "target_processes": 2,
54
+ "target_survivors": 0,
55
+ "trigger_to_empty_ms": 1.25,
56
+ "workload_detection_performed": False,
57
+ }
58
+
59
+
60
+ class HostedProofReceiptSchemaTests(unittest.TestCase):
61
+ @classmethod
62
+ def setUpClass(cls) -> None:
63
+ cls.schema = json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))
64
+ validator_class = validator_for(cls.schema)
65
+ validator_class.check_schema(cls.schema)
66
+ cls.validator = validator_class(cls.schema)
67
+ cls.success = cls.schema["oneOf"][0]
68
+ cls.failure = cls.schema["oneOf"][1]
69
+
70
+ def test_schema_identity_is_public_and_versioned(self) -> None:
71
+ self.assertEqual("https://json-schema.org/draft/2020-12/schema", self.schema["$schema"])
72
+ self.assertEqual(
73
+ "https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/"
74
+ "schemas/hosted-proof-receipt-v1.schema.json",
75
+ self.schema["$id"],
76
+ )
77
+
78
+ def test_success_contract_matches_runtime_keys_and_validates_current_shape(self) -> None:
79
+ required = set(self.success["required"])
80
+ properties = set(self.success["properties"])
81
+ self.assertEqual(probe.SUCCESS_KEYS, required)
82
+ self.assertEqual(probe.SUCCESS_KEYS, properties)
83
+ self.assertFalse(self.success["additionalProperties"])
84
+ self.validator.validate(success_receipt())
85
+
86
+ def test_success_latency_bound_matches_probe_and_hosted_workflow(self) -> None:
87
+ maximum = self.success["properties"]["trigger_to_empty_ms"]["maximum"]
88
+ self.assertEqual(probe.TOTAL_TIMEOUT_SECONDS * 1000, maximum)
89
+ self.assertEqual(workflow_latency_maximum_ms(), maximum)
90
+
91
+ def test_success_constants_match_current_probe(self) -> None:
92
+ constants = {
93
+ name: value["const"]
94
+ for name, value in self.success["properties"].items()
95
+ if "const" in value
96
+ }
97
+ self.assertEqual(
98
+ {
99
+ "canary_survived": True,
100
+ "changes_made": True,
101
+ "cleanup_complete": True,
102
+ "installation_performed": False,
103
+ "journal_history_may_persist": True,
104
+ "mode": "containment-primitive-probe",
105
+ "network_requests_made": False,
106
+ "primitive": "pidfd-stop+cgroup.kill",
107
+ "result": "TERMINATED",
108
+ "root_populated": 0,
109
+ "target_processes": 2,
110
+ "target_survivors": 0,
111
+ "workload_detection_performed": False,
112
+ },
113
+ constants,
114
+ )
115
+
116
+ def test_failure_contract_matches_every_workflow_accepted_code(self) -> None:
117
+ codes = workflow_failure_codes()
118
+ self.assertEqual(codes, set(self.failure["properties"]["reason_code"]["enum"]))
119
+ self.assertEqual(set(probe.failure_receipt("ROOT_REQUIRED")), set(self.failure["required"]))
120
+ self.assertEqual(set(self.failure["required"]), set(self.failure["properties"]))
121
+ self.assertFalse(self.failure["additionalProperties"])
122
+ for code in codes:
123
+ with self.subTest(code=code):
124
+ self.validator.validate(probe.failure_receipt(code))
125
+
126
+ def test_unknown_failure_code_and_extra_properties_are_rejected(self) -> None:
127
+ invalid_receipts = [
128
+ probe.failure_receipt("UNRECOGNIZED_SAFE_REFUSAL"),
129
+ {**probe.failure_receipt("ROOT_REQUIRED"), "detail": "/private/path"},
130
+ {**success_receipt(), "detail": "unexpected"},
131
+ ]
132
+ for receipt in invalid_receipts:
133
+ with self.subTest(receipt=receipt), self.assertRaises(ValidationError):
134
+ self.validator.validate(receipt)
135
+
136
+ def test_wrong_constants_and_types_are_rejected(self) -> None:
137
+ wrong_result = {**success_receipt(), "result": "FAILED"}
138
+ wrong_latency = {**success_receipt(), "trigger_to_empty_ms": "1.25"}
139
+ excessive_latency = {**success_receipt(), "trigger_to_empty_ms": 20_000.001}
140
+ wrong_failure_result = {**probe.failure_receipt("ROOT_REQUIRED"), "result": "TERMINATED"}
141
+ for receipt in (wrong_result, wrong_latency, excessive_latency, wrong_failure_result):
142
+ with self.subTest(receipt=receipt), self.assertRaises(ValidationError):
143
+ self.validator.validate(receipt)
144
+
145
+
146
+ if __name__ == "__main__":
147
+ unittest.main()