{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# S7 lab notebook \u2014 credentials you can inventory, scope and revoke\n\nThis notebook tests the decisions the lab makes live, before and after you make them: that the credential inventory is complete enough to be useful, that a presigned URL is scope plus a clock, that a per-action scope refuses what it does not name, that a Worker secret rotation is a state machine with a rollback trap, and that the five-row register is internally consistent.\n\nIt does **not** implement SigV4, HMAC-SHA256 for the Worker, or any provider API. It is a model of the *decision* each mechanism makes, written against the data files so a wrong row in your own submission fails an assertion rather than passing silently.\n\nRun it top to bottom. It writes `security_results.json`; submit that file with the evidence bundle.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\n\u0e42\u0e19\u0e49\u0e15\u0e1a\u0e38\u0e4a\u0e01\u0e19\u0e35\u0e49\u0e15\u0e23\u0e27\u0e08\u0e01\u0e32\u0e23\u0e15\u0e31\u0e14\u0e2a\u0e34\u0e19\u0e43\u0e08\u0e17\u0e35\u0e48\u0e41\u0e25\u0e47\u0e1a\u0e17\u0e33\u0e08\u0e23\u0e34\u0e07: \u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e31\u0e1a\u0e23\u0e2d\u0e07\u0e04\u0e23\u0e1a\u0e1e\u0e2d\u0e08\u0e30\u0e43\u0e0a\u0e49\u0e44\u0e14\u0e49\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48 URL \u0e17\u0e35\u0e48\u0e25\u0e07\u0e19\u0e32\u0e21\u0e41\u0e25\u0e49\u0e27\u0e40\u0e1b\u0e47\u0e19\u0e02\u0e2d\u0e1a\u0e40\u0e02\u0e15\u0e1a\u0e27\u0e01\u0e40\u0e27\u0e25\u0e32\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48 \u0e02\u0e2d\u0e1a\u0e40\u0e02\u0e15\u0e41\u0e1a\u0e1a\u0e23\u0e32\u0e22\u0e01\u0e32\u0e23\u0e01\u0e23\u0e30\u0e17\u0e33\u0e1b\u0e0f\u0e34\u0e40\u0e2a\u0e18\u0e2a\u0e34\u0e48\u0e07\u0e17\u0e35\u0e48\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e23\u0e30\u0e1a\u0e38\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48 \u0e01\u0e32\u0e23\u0e2b\u0e21\u0e38\u0e19 Worker secret \u0e40\u0e1b\u0e47\u0e19\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e08\u0e31\u0e01\u0e23\u0e2a\u0e16\u0e32\u0e19\u0e30\u0e17\u0e35\u0e48\u0e21\u0e35\u0e01\u0e31\u0e1a\u0e14\u0e31\u0e01\u0e15\u0e2d\u0e19\u0e22\u0e49\u0e2d\u0e19\u0e40\u0e27\u0e2d\u0e23\u0e4c\u0e0a\u0e31\u0e19\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48 \u0e41\u0e25\u0e30\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e04\u0e27\u0e32\u0e21\u0e40\u0e2a\u0e35\u0e48\u0e22\u0e07\u0e2b\u0e49\u0e32\u0e41\u0e16\u0e27\u0e2a\u0e2d\u0e14\u0e04\u0e25\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19\u0e2b\u0e23\u0e37\u0e2d\u0e44\u0e21\u0e48 \u0e42\u0e19\u0e49\u0e15\u0e1a\u0e38\u0e4a\u0e01\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e43\u0e0a\u0e49 API \u0e08\u0e23\u0e34\u0e07 \u0e41\u0e15\u0e48\u0e08\u0e33\u0e25\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e15\u0e31\u0e14\u0e2a\u0e34\u0e19\u0e43\u0e08\u0e02\u0e2d\u0e07\u0e41\u0e15\u0e48\u0e25\u0e30\u0e01\u0e25\u0e44\u0e01\u0e41\u0e25\u0e30\u0e15\u0e23\u0e27\u0e08\u0e01\u0e31\u0e1a\u0e44\u0e1f\u0e25\u0e4c\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25 \u0e43\u0e2b\u0e49\u0e23\u0e31\u0e19\u0e08\u0e32\u0e01\u0e1a\u0e19\u0e25\u0e07\u0e25\u0e48\u0e32\u0e07 \u0e41\u0e25\u0e49\u0e27\u0e08\u0e30\u0e44\u0e14\u0e49\u0e44\u0e1f\u0e25\u0e4c security_results.json \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e2a\u0e48\u0e07\u0e1e\u0e23\u0e49\u0e2d\u0e21\u0e2b\u0e25\u0e31\u0e01\u0e10\u0e32\u0e19\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\n\u672c notebook \u68c0\u9a8c\u5b9e\u9a8c\u5b9e\u9645\u505a\u51fa\u7684\u51b3\u7b56\uff1a\u51ed\u636e\u6e05\u5355\u662f\u5426\u5b8c\u6574\u5230\u8db3\u4ee5\u4f7f\u7528\uff0c\u7b7e\u540d URL \u662f\u5426\u662f\u8303\u56f4\u52a0\u65f6\u95f4\uff0c\u6309\u64cd\u4f5c\u5212\u5206\u7684\u8303\u56f4\u662f\u5426\u4f1a\u62d2\u7edd\u672a\u5217\u51fa\u7684\u5185\u5bb9\uff0cWorker secret \u7684\u8f6e\u6362\u662f\u5426\u662f\u4e00\u53f0\u5e26\u6709\u7248\u672c\u56de\u9000\u9677\u9631\u7684\u72b6\u6001\u673a\uff0c\u4ee5\u53ca\u4e94\u884c\u98ce\u9669\u767b\u8bb0\u518c\u662f\u5426\u524d\u540e\u4e00\u81f4\u3002\u672c notebook \u4e0d\u8c03\u7528\u771f\u5b9e API\uff0c\u800c\u662f\u6a21\u62df\u6bcf\u79cd\u673a\u5236\u7684\u51b3\u7b56\uff0c\u5e76\u4e0e\u6570\u636e\u6587\u4ef6\u6838\u5bf9\u3002\u8bf7\u4ece\u4e0a\u5230\u4e0b\u8fd0\u884c\uff0c\u6700\u540e\u4f1a\u5f97\u5230\u7528\u4e8e\u968f\u8bc1\u636e\u4e00\u8d77\u63d0\u4ea4\u7684 security_results.json \u6587\u4ef6\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "import hashlib\nimport hmac\nimport json\nimport os\nimport re\nimport sys\nfrom pathlib import Path\n\nSEED = 42\nprint(\"seed\", SEED)\nprint(\"Python\", sys.version.split()[0])\nassert sys.version_info >= (3, 11)\nDEVICE = \"cpu\"\nprint(\"device\", DEVICE, \"(S7 has no accelerator path)\")\n\n\ndef data_dir():\n    candidates = [Path(\"data\"), Path(\"/kaggle/input/security-identity\")]\n    env = os.environ.get(\"COURSE_DATA\")\n    if env:\n        candidates.append(Path(env))\n    required = [\"credential-inventory.json\", \"presign-cases.json\",\n                \"scope-matrix.json\", \"register-template.json\"]\n    for path in candidates:\n        if path and all((path / name).exists() for name in required):\n            return path\n    raise SystemExit(\"data directory not found; run from the week folder or set COURSE_DATA\")\n\nDATA = data_dir()\ninventory = json.loads((DATA / \"credential-inventory.json\").read_text())\npresign_cases = json.loads((DATA / \"presign-cases.json\").read_text())\nscope_rows = json.loads((DATA / \"scope-matrix.json\").read_text())[\"rows\"]\nregister = json.loads((DATA / \"register-template.json\").read_text())\nprint(\"data\", DATA.resolve(), \"|\", len(inventory[\"rows\"]), \"credentials,\",\n      len(presign_cases), \"presign cases,\", len(scope_rows), \"scope rows,\",\n      len(register[\"rows\"]), \"register rows\")\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Step 1 \u2014 an inventory is complete when every row answers five questions\n\nThe lesson says a credential is a scoped capability: scope, clock, custody, revocation, audit. A row that leaves one of those blank is not documentation, it is a hope. This cell checks the schema, checks that every row answers all five, and checks that the file does not contain a live secret \u2014 the inventory records *where* a value lives, never the value.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\n\u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e31\u0e1a\u0e23\u0e2d\u0e07\u0e08\u0e30\u0e2a\u0e21\u0e1a\u0e39\u0e23\u0e13\u0e4c\u0e01\u0e47\u0e15\u0e48\u0e2d\u0e40\u0e21\u0e37\u0e48\u0e2d\u0e17\u0e38\u0e01\u0e41\u0e16\u0e27\u0e15\u0e2d\u0e1a\u0e04\u0e33\u0e16\u0e32\u0e21\u0e2b\u0e49\u0e32\u0e02\u0e49\u0e2d: \u0e02\u0e2d\u0e1a\u0e40\u0e02\u0e15 \u0e40\u0e27\u0e25\u0e32\u0e2b\u0e21\u0e14\u0e2d\u0e32\u0e22\u0e38 \u0e01\u0e32\u0e23\u0e40\u0e01\u0e47\u0e1a\u0e23\u0e31\u0e01\u0e29\u0e32 \u0e01\u0e32\u0e23\u0e40\u0e1e\u0e34\u0e01\u0e16\u0e2d\u0e19 \u0e41\u0e25\u0e30\u0e01\u0e32\u0e23\u0e15\u0e23\u0e27\u0e08\u0e2a\u0e2d\u0e1a \u0e41\u0e16\u0e27\u0e17\u0e35\u0e48\u0e40\u0e27\u0e49\u0e19\u0e0a\u0e48\u0e2d\u0e07\u0e43\u0e14\u0e0a\u0e48\u0e2d\u0e07\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e44\u0e27\u0e49\u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48\u0e40\u0e2d\u0e01\u0e2a\u0e32\u0e23\u0e1b\u0e23\u0e30\u0e01\u0e2d\u0e1a \u0e41\u0e15\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e04\u0e27\u0e32\u0e21\u0e2b\u0e27\u0e31\u0e07\u0e40\u0e17\u0e48\u0e32\u0e19\u0e31\u0e49\u0e19 \u0e40\u0e0b\u0e25\u0e25\u0e4c\u0e19\u0e35\u0e49\u0e15\u0e23\u0e27\u0e08\u0e42\u0e04\u0e23\u0e07\u0e2a\u0e23\u0e49\u0e32\u0e07 \u0e15\u0e23\u0e27\u0e08\u0e27\u0e48\u0e32\u0e17\u0e38\u0e01\u0e41\u0e16\u0e27\u0e15\u0e2d\u0e1a\u0e04\u0e23\u0e1a\u0e17\u0e31\u0e49\u0e07\u0e2b\u0e49\u0e32 \u0e41\u0e25\u0e30\u0e15\u0e23\u0e27\u0e08\u0e27\u0e48\u0e32\u0e44\u0e1f\u0e25\u0e4c\u0e44\u0e21\u0e48\u0e21\u0e35\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e25\u0e31\u0e1a\u0e08\u0e23\u0e34\u0e07 \u2014 \u0e17\u0e30\u0e40\u0e1a\u0e35\u0e22\u0e19\u0e1a\u0e31\u0e19\u0e17\u0e36\u0e01\u0e27\u0e48\u0e32 \"\u0e04\u0e48\u0e32\u0e40\u0e01\u0e47\u0e1a\u0e2d\u0e22\u0e39\u0e48\u0e17\u0e35\u0e48\u0e44\u0e2b\u0e19\" \u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48\u0e15\u0e31\u0e27\u0e04\u0e48\u0e32\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\n\u53ea\u6709\u5f53\u6bcf\u4e00\u884c\u90fd\u56de\u7b54\u4e94\u4e2a\u95ee\u9898\u65f6\uff0c\u51ed\u636e\u6e05\u5355\u624d\u7b97\u5b8c\u6574\uff1a\u8303\u56f4\u3001\u8fc7\u671f\u65f6\u95f4\u3001\u4fdd\u7ba1\u3001\u64a4\u9500\u548c\u5ba1\u8ba1\u3002\u7559\u4e0b\u4efb\u4f55\u4e00\u4e2a\u7a7a\u767d\u7684\u884c\u90fd\u4e0d\u662f\u6587\u6863\uff0c\u800c\u53ea\u662f\u5e0c\u671b\u3002\u672c\u5355\u5143\u683c\u68c0\u67e5\u7ed3\u6784\uff0c\u68c0\u67e5\u6bcf\u4e00\u884c\u662f\u5426\u5b8c\u6574\u56de\u7b54\u4e94\u9879\uff0c\u5e76\u68c0\u67e5\u6587\u4ef6\u4e2d\u6ca1\u6709\u771f\u6b63\u7684\u673a\u5bc6\u2014\u2014\u6e05\u5355\u8bb0\u5f55\u7684\u662f\u201c\u503c\u5b58\u653e\u5728\u54ea\u91cc\u201d\uff0c\u800c\u4e0d\u662f\u503c\u672c\u8eab\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "CLASSES = {\"ssh-key-pair\", \"digitalocean-token\", \"cloudflare-api-token\",\n           \"r2-api-key-pair\", \"worker-secret\"}\nROLES = {\"provisioning\", \"operating\"}\nFIELDS = [\"class\", \"provider\", \"name\", \"role\", \"scope\", \"lifetime\", \"storage\",\n          \"revocation\", \"audit\", \"secret_handle\"]\nSECRET_SHAPES = [\n    re.compile(r\"dop_v1_[A-Za-z0-9]{10,}\"),\n    re.compile(r\"sk-[A-Za-z0-9]{10,}\"),\n    re.compile(r\"-----BEGIN [A-Z ]+ PRIVATE KEY-----\"),\n    re.compile(r\"\\b[A-Fa-f0-9]{40,}\\b\"),\n]\n\nrows = inventory[\"rows\"]\nassert rows, \"the inventory has no rows\"\nids = [row[\"id\"] for row in rows]\nassert len(ids) == len(set(ids)), \"duplicate credential id\"\nassert {row[\"class\"] for row in rows} == CLASSES, \"the inventory must cover all five credential classes\"\n\nfor row in rows:\n    for field in FIELDS:\n        value = row.get(field)\n        assert isinstance(value, str) and value.strip(), f\"{row['id']} has no {field}\"\n    assert row[\"role\"] in ROLES, f\"{row['id']} role {row['role']!r} is not provisioning/operating\"\n    for field in (\"scope\", \"lifetime\", \"storage\", \"revocation\", \"audit\", \"secret_handle\"):\n        for shape in SECRET_SHAPES:\n            assert not shape.search(row[field]), f\"{row['id']}.{field} looks like a live secret\"\n\noperating = [row[\"id\"] for row in rows if row[\"role\"] == \"operating\"]\nprovisioning = [row[\"id\"] for row in rows if row[\"role\"] == \"provisioning\"]\nprint(f\"{len(rows)} credentials: {len(provisioning)} provisioning, {len(operating)} operating\")\nprint(\"with no clock (revoked by hand):\",\n      [row[\"id\"] for row in rows if \"no expiry\" in row[\"lifetime\"].lower()])\ninventory_result = {\n    \"rows\": len(rows),\n    \"classes\": sorted({row[\"class\"] for row in rows}),\n    \"provisioning\": provisioning,\n    \"operating\": operating,\n    \"untimed\": [row[\"id\"] for row in rows if \"no expiry\" in row[\"lifetime\"].lower()],\n}\ninventory_result\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Step 2 \u2014 a presigned URL is scope plus a clock\n\nThe signature names one method, one bucket, one object and an expiry. Four of those five are the scope; the fifth is the clock. The cases in `presign-cases.json` change exactly one thing at a time, so a failure points at the field that is wrong. The model is deliberately not SigV4: it isolates the decision the service makes when the URL arrives.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\n\u0e25\u0e32\u0e22\u0e40\u0e0b\u0e47\u0e19\u0e23\u0e30\u0e1a\u0e38\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e40\u0e21\u0e18\u0e2d\u0e14 \u0e2b\u0e19\u0e36\u0e48\u0e07\u0e1a\u0e31\u0e01\u0e40\u0e01\u0e47\u0e15 \u0e2b\u0e19\u0e36\u0e48\u0e07\u0e2d\u0e2d\u0e1a\u0e40\u0e08\u0e01\u0e15\u0e4c \u0e41\u0e25\u0e30\u0e40\u0e27\u0e25\u0e32\u0e2b\u0e21\u0e14\u0e2d\u0e32\u0e22\u0e38 \u0e2a\u0e35\u0e48\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e41\u0e23\u0e01\u0e04\u0e37\u0e2d\u0e02\u0e2d\u0e1a\u0e40\u0e02\u0e15 \u0e2a\u0e48\u0e27\u0e19\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e17\u0e35\u0e48\u0e2b\u0e49\u0e32\u0e04\u0e37\u0e2d\u0e40\u0e27\u0e25\u0e32\u0e2b\u0e21\u0e14\u0e2d\u0e32\u0e22\u0e38 \u0e40\u0e04\u0e2a\u0e43\u0e19\u0e44\u0e1f\u0e25\u0e4c presign-cases.json \u0e40\u0e1b\u0e25\u0e35\u0e48\u0e22\u0e19\u0e17\u0e35\u0e25\u0e30\u0e2d\u0e22\u0e48\u0e32\u0e07 \u0e17\u0e33\u0e43\u0e2b\u0e49\u0e23\u0e39\u0e49\u0e27\u0e48\u0e32\u0e1f\u0e34\u0e25\u0e14\u0e4c\u0e43\u0e14\u0e1c\u0e34\u0e14 \u0e41\u0e1a\u0e1a\u0e08\u0e33\u0e25\u0e2d\u0e07\u0e19\u0e35\u0e49\u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48 SigV4 \u0e08\u0e23\u0e34\u0e07 \u0e41\u0e15\u0e48\u0e41\u0e22\u0e01\u0e01\u0e32\u0e23\u0e15\u0e31\u0e14\u0e2a\u0e34\u0e19\u0e43\u0e08\u0e17\u0e35\u0e48\u0e1a\u0e23\u0e34\u0e01\u0e32\u0e23\u0e17\u0e33\u0e15\u0e2d\u0e19\u0e23\u0e31\u0e1a URL \u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e43\u0e2b\u0e49\u0e40\u0e2b\u0e47\u0e19\u0e0a\u0e31\u0e14\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\n\u7b7e\u540d\u6307\u5b9a\u4e00\u4e2a\u65b9\u6cd5\u3001\u4e00\u4e2a\u6876\u3001\u4e00\u4e2a\u5bf9\u8c61\u548c\u8fc7\u671f\u65f6\u95f4\u3002\u524d\u56db\u9879\u662f\u8303\u56f4\uff0c\u7b2c\u4e94\u9879\u662f\u8fc7\u671f\u65f6\u95f4\u3002presign-cases.json \u4e2d\u7684\u7528\u4f8b\u6bcf\u6b21\u53ea\u6539\u53d8\u4e00\u9879\uff0c\u56e0\u6b64\u80fd\u770b\u51fa\u54ea\u4e2a\u5b57\u6bb5\u9519\u4e86\u3002\u8fd9\u4e2a\u6a21\u578b\u4e0d\u662f\u771f\u6b63\u7684 SigV4\uff0c\u800c\u662f\u628a\u670d\u52a1\u5728\u63a5\u6536 URL \u65f6\u6240\u505a\u7684\u51b3\u7b56\u5355\u72ec\u5448\u73b0\u51fa\u6765\uff0c\u8ba9\u4eba\u770b\u6e05\u695a\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "TTL = 60\n\n\ndef presign(bucket, key, method, now, ttl=TTL):\n    # The capability a presigner mints: who, what, how, until when.\n    return {\"bucket\": bucket, \"key\": key, \"method\": method, \"expires_at\": now + ttl}\n\n\ndef accepts(capability, bucket, key, method, now):\n    # What the service decides when the URL is used.\n    return (now <= capability[\"expires_at\"]\n            and capability[\"bucket\"] == bucket\n            and capability[\"key\"] == key\n            and capability[\"method\"] == method)\n\n\npresign_results = []\nfor case in presign_cases:\n    capability = presign(\"course-s7-vault\", \"files/asset-0001.txt\", \"GET\", now=0)\n    allowed = accepts(capability, case[\"bucket\"], case[\"key\"], case[\"method\"],\n                      case[\"offset_seconds\"])\n    print(f\"{case['case']:<14} allowed={str(allowed):<5} expected={case['expected']}  {case['why']}\")\n    assert allowed == case[\"expected\"], f\"case {case['case']!r} did not match its expected answer\"\n    presign_results.append({\"case\": case[\"case\"], \"allowed\": allowed,\n                            \"expected\": case[\"expected\"]})\n\nprint(\"\\nthe TTL is the only control: the same capability is reusable until expires_at\")\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Step 3 \u2014 per-action scope refuses what it does not name\n\nScope is not a strength dial. `droplet:read` is a token that reads; it is not \"half a droplet token\". This cell turns the five-class table into a small decision function and checks every row of `scope-matrix.json` against it. A row that expects `false` is as important as a row that expects `true` \u2014 the denials are the blast-radius evidence. One row is a different lesson: the Cloudflare token was created with a single-Worker resource clause, and the API did not enforce it, so the model records `resource_enforced: False` and the row expects success where the label promised a denial.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\n\u0e02\u0e2d\u0e1a\u0e40\u0e02\u0e15\u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48\u0e23\u0e30\u0e14\u0e31\u0e1a\u0e04\u0e27\u0e32\u0e21\u0e41\u0e23\u0e07 `droplet:read` \u0e04\u0e37\u0e2d\u0e42\u0e17\u0e40\u0e04\u0e19\u0e17\u0e35\u0e48\u0e2d\u0e48\u0e32\u0e19\u0e44\u0e14\u0e49 \u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48 \"\u0e42\u0e17\u0e40\u0e04\u0e19\u0e23\u0e30\u0e14\u0e31\u0e1a\u0e04\u0e23\u0e36\u0e48\u0e07\u0e2b\u0e19\u0e36\u0e48\u0e07\" \u0e40\u0e0b\u0e25\u0e25\u0e4c\u0e19\u0e35\u0e49\u0e41\u0e1b\u0e25\u0e07\u0e15\u0e32\u0e23\u0e32\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e23\u0e31\u0e1a\u0e23\u0e2d\u0e07\u0e2b\u0e49\u0e32\u0e1b\u0e23\u0e30\u0e40\u0e20\u0e17\u0e40\u0e1b\u0e47\u0e19\u0e1f\u0e31\u0e07\u0e01\u0e4c\u0e0a\u0e31\u0e19\u0e15\u0e31\u0e14\u0e2a\u0e34\u0e19\u0e43\u0e08\u0e40\u0e25\u0e47\u0e01 \u0e46 \u0e41\u0e25\u0e49\u0e27\u0e15\u0e23\u0e27\u0e08\u0e17\u0e38\u0e01\u0e41\u0e16\u0e27\u0e43\u0e19 scope-matrix.json \u0e41\u0e16\u0e27\u0e17\u0e35\u0e48\u0e04\u0e32\u0e14\u0e27\u0e48\u0e32 false \u0e2a\u0e33\u0e04\u0e31\u0e0d\u0e1e\u0e2d \u0e46 \u0e01\u0e31\u0e1a\u0e41\u0e16\u0e27\u0e17\u0e35\u0e48\u0e04\u0e32\u0e14\u0e27\u0e48\u0e32 true \u0e40\u0e1e\u0e23\u0e32\u0e30\u0e01\u0e32\u0e23\u0e16\u0e39\u0e01\u0e1b\u0e0f\u0e34\u0e40\u0e2a\u0e18\u0e04\u0e37\u0e2d\u0e2b\u0e25\u0e31\u0e01\u0e10\u0e32\u0e19\u0e02\u0e2d\u0e07\u0e23\u0e31\u0e28\u0e21\u0e35\u0e1c\u0e25\u0e01\u0e23\u0e30\u0e17\u0e1a \u0e21\u0e35\u0e41\u0e16\u0e27\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e2a\u0e2d\u0e19\u0e1a\u0e17\u0e40\u0e23\u0e35\u0e22\u0e19\u0e15\u0e48\u0e32\u0e07\u0e2d\u0e2d\u0e01\u0e44\u0e1b: \u0e42\u0e17\u0e40\u0e04\u0e19 Cloudflare \u0e16\u0e39\u0e01\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e42\u0e14\u0e22\u0e23\u0e30\u0e1a\u0e38 Worker \u0e40\u0e14\u0e35\u0e22\u0e27 \u0e41\u0e15\u0e48 API \u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e1a\u0e31\u0e07\u0e04\u0e31\u0e1a\u0e02\u0e49\u0e2d\u0e08\u0e33\u0e01\u0e31\u0e14\u0e19\u0e31\u0e49\u0e19 \u0e41\u0e1a\u0e1a\u0e08\u0e33\u0e25\u0e2d\u0e07\u0e08\u0e36\u0e07\u0e1a\u0e31\u0e19\u0e17\u0e36\u0e01 resource_enforced \u0e40\u0e1b\u0e47\u0e19 False \u0e41\u0e25\u0e30\u0e41\u0e16\u0e27\u0e19\u0e31\u0e49\u0e19\u0e04\u0e32\u0e14\u0e27\u0e48\u0e32\u0e08\u0e30\u0e2a\u0e33\u0e40\u0e23\u0e47\u0e08 \u0e17\u0e31\u0e49\u0e07\u0e17\u0e35\u0e48\u0e1b\u0e49\u0e32\u0e22\u0e1a\u0e2d\u0e01\u0e27\u0e48\u0e32\u0e08\u0e30\u0e16\u0e39\u0e01\u0e1b\u0e0f\u0e34\u0e40\u0e2a\u0e18\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\n\u8303\u56f4\u4e0d\u662f\u5f3a\u5ea6\u7b49\u7ea7\u3002`droplet:read` \u662f\u4e00\u4e2a\u53ea\u80fd\u8bfb\u53d6\u7684 token\uff0c\u800c\u4e0d\u662f\u201c\u4e00\u534a\u5f3a\u5ea6\u7684 token\u201d\u3002\u672c\u5355\u5143\u683c\u628a\u4e94\u7c7b\u51ed\u636e\u7684\u8868\u683c\u8f6c\u6210\u4e00\u4e2a\u5c0f\u5c0f\u7684\u51b3\u7b56\u51fd\u6570\uff0c\u7136\u540e\u68c0\u67e5 scope-matrix.json \u4e2d\u7684\u6bcf\u4e00\u884c\u3002\u9884\u671f\u4e3a false \u7684\u884c\u548c\u9884\u671f\u4e3a true \u7684\u884c\u540c\u6837\u91cd\u8981\uff0c\u56e0\u4e3a\u88ab\u62d2\u7edd\u6b63\u662f\u5f71\u54cd\u8303\u56f4\u7684\u8bc1\u636e\u3002\u6709\u4e00\u884c\u6559\u7684\u662f\u53e6\u4e00\u4e2a\u6559\u8bad\uff1aCloudflare token \u5728\u521b\u5efa\u65f6\u6307\u5b9a\u4e86\u5355\u4e2a Worker\uff0c\u4f46 API \u5e76\u6ca1\u6709\u5f3a\u5236\u6267\u884c\u8fd9\u4e2a\u9650\u5236\uff0c\u56e0\u6b64\u6a21\u578b\u628a resource_enforced \u8bb0\u4e3a False\uff0c\u8be5\u884c\u4e5f\u9884\u671f\u6210\u529f\uff0c\u5c3d\u7ba1\u6807\u6ce8\u8bf4\u5b83\u4f1a\u88ab\u62d2\u7edd\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "# The grant each credential actually carries, encoded from the lesson's table.\nGRANTS = {\n    \"do-read\": {\"actions\": {\"droplet:read\", \"account:read\"}},\n    \"one-worker-editor\": {\"actions\": {\"workers-script:secret-put\", \"workers-script:secret-delete\"},\n                          \"worker\": \"course-s7-capability\",\n                          \"resource_enforced\": False},\n    \"r2-bucket-read\": {\"actions\": {\"s3:GetObject\"}, \"bucket\": \"course-s7-vault\"},\n    \"ssh-removed\": {\"actions\": set()},\n    \"ssh-retained\": {\"actions\": {\"ssh:publickey-login\"}},\n}\n\nCREDENTIAL_GRANT = {\n    \"C3\": \"do-read\",\n    \"C6\": \"one-worker-editor\",\n    \"C4\": \"r2-bucket-read\",\n    \"C7\": \"ssh-removed\",\n    \"C1\": \"ssh-retained\",\n}\n\n\ndef decide(credential, action, resource):\n    grant = GRANTS[CREDENTIAL_GRANT[credential.split()[0]]]\n    if action not in grant[\"actions\"]:\n        return False\n    if \"worker\" in grant and grant.get(\"resource_enforced\", True) and resource != grant[\"worker\"]:\n        return False\n    if \"bucket\" in grant and not resource.startswith(grant[\"bucket\"] + \"/\"):\n        return False\n    return True\n\n\nscope_results = []\nfor row in scope_rows:\n    allowed = decide(row[\"credential\"], row[\"action\"], row[\"resource\"])\n    print(f\"{row['credential']:<28} {row['action']:<26} {str(allowed):<5} expected={row['expected']}  {row['why']}\")\n    assert allowed == row[\"expected\"], f\"scope row {row['credential']} {row['action']} disagrees with its expected answer\"\n    scope_results.append({\"credential\": row[\"credential\"], \"action\": row[\"action\"],\n                          \"resource\": row[\"resource\"], \"allowed\": allowed,\n                          \"expected\": row[\"expected\"]})\nprint(f\"\\n{sum(not r['allowed'] for r in scope_results)} of {len(scope_results)} rows are denials\")\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Step 4 \u2014 the secret state machine, including the rollback trap\n\nA Worker secret is not a value you change; it is a version you add. During rotation the Worker checks against the newest secret, so old signatures fail immediately. But an older *version* still holds the older value, and rolling back to it restores the key you believed was retired. This cell steps the machine and prints the transition that a clever operator gets wrong.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\nWorker secret \u0e44\u0e21\u0e48\u0e43\u0e0a\u0e48\u0e04\u0e48\u0e32\u0e17\u0e35\u0e48\u0e41\u0e01\u0e49\u0e17\u0e31\u0e1a \u0e41\u0e15\u0e48\u0e40\u0e1b\u0e47\u0e19\u0e40\u0e27\u0e2d\u0e23\u0e4c\u0e0a\u0e31\u0e19\u0e17\u0e35\u0e48\u0e40\u0e1e\u0e34\u0e48\u0e21\u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b \u0e23\u0e30\u0e2b\u0e27\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e2b\u0e21\u0e38\u0e19 Worker \u0e08\u0e30\u0e15\u0e23\u0e27\u0e08\u0e01\u0e31\u0e1a secret \u0e43\u0e2b\u0e21\u0e48 \u0e25\u0e32\u0e22\u0e40\u0e0b\u0e47\u0e19\u0e40\u0e01\u0e48\u0e32\u0e08\u0e36\u0e07\u0e43\u0e0a\u0e49\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49\u0e17\u0e31\u0e19\u0e17\u0e35 \u0e41\u0e15\u0e48\u0e27\u0e2d\u0e23\u0e4c\u0e0a\u0e31\u0e19\u0e40\u0e01\u0e48\u0e32\u0e22\u0e31\u0e07\u0e40\u0e01\u0e47\u0e1a\u0e04\u0e48\u0e32\u0e40\u0e01\u0e48\u0e32\u0e44\u0e27\u0e49 \u0e16\u0e49\u0e32\u0e22\u0e49\u0e2d\u0e19\u0e01\u0e25\u0e31\u0e1a\u0e44\u0e1b\u0e40\u0e27\u0e2d\u0e23\u0e4c\u0e0a\u0e31\u0e19\u0e19\u0e31\u0e49\u0e19 \u0e01\u0e38\u0e0d\u0e41\u0e08\u0e17\u0e35\u0e48\u0e04\u0e34\u0e14\u0e27\u0e48\u0e32\u0e40\u0e25\u0e34\u0e01\u0e43\u0e0a\u0e49\u0e41\u0e25\u0e49\u0e27\u0e08\u0e30\u0e01\u0e25\u0e31\u0e1a\u0e21\u0e32 \u0e40\u0e0b\u0e25\u0e25\u0e4c\u0e19\u0e35\u0e49\u0e44\u0e25\u0e48\u0e2a\u0e16\u0e32\u0e19\u0e30\u0e41\u0e25\u0e30\u0e41\u0e2a\u0e14\u0e07\u0e0a\u0e48\u0e27\u0e07\u0e40\u0e1b\u0e25\u0e35\u0e48\u0e22\u0e19\u0e1c\u0e48\u0e32\u0e19\u0e17\u0e35\u0e48\u0e1c\u0e39\u0e49\u0e14\u0e39\u0e41\u0e25\u0e21\u0e31\u0e01\u0e1e\u0e25\u0e32\u0e14\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\nWorker secret \u4e0d\u662f\u4e00\u4e2a\u88ab\u8986\u76d6\u7684\u503c\uff0c\u800c\u662f\u4e00\u4e2a\u88ab\u6dfb\u52a0\u7684\u7248\u672c\u3002\u8f6e\u6362\u671f\u95f4\uff0cWorker \u4f1a\u7528\u65b0\u7684 secret \u6821\u9a8c\uff0c\u56e0\u6b64\u65e7\u7b7e\u540d\u7acb\u5373\u5931\u6548\uff1b\u4f46\u65e7\u7248\u672c\u4ecd\u7136\u4fdd\u5b58\u65e7\u503c\u3002\u5982\u679c\u56de\u9000\u5230\u90a3\u4e2a\u7248\u672c\uff0c\u4f60\u4ee5\u4e3a\u5df2\u7ecf\u505c\u7528\u7684\u5bc6\u94a5\u5c31\u4f1a\u56de\u6765\u3002\u672c\u5355\u5143\u683c\u9010\u6b65\u63a8\u8fdb\u72b6\u6001\uff0c\u5e76\u663e\u793a\u7ba1\u7406\u5458\u5e38\u9519\u8fc7\u7684\u8fc7\u6e21\u9636\u6bb5\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "def sign(secret, asset, exp):\n    return hmac.new(secret.encode(), f\"{asset}:{exp}\".encode(), hashlib.sha256).hexdigest()\n\n\ndef worker_accepts(signature, secret, asset, exp, now):\n    if exp < now:\n        return False\n    return hmac.compare_digest(signature, sign(secret, asset, exp))\n\n\nASSET, EXP, NOW = \"asset-0001\", 1_000, 0\nK1, K2 = \"key-one\", \"key-two\"\nsig1 = sign(K1, ASSET, EXP)\nsig2 = sign(K2, ASSET, EXP)\n\ntransitions = [\n    (\"v1 deployed\", K1, sig1, True),\n    (\"v2 deployed (rotated)\", K2, sig1, False),\n    (\"v2 deployed (rotated)\", K2, sig2, True),\n    (\"rollback to v1 (resurrection)\", K1, sig1, True),\n    (\"secret deleted (no key)\", \"\", sig1, False),\n]\nsecret_rows = []\nfor state, active, signature, expected in transitions:\n    accepted = worker_accepts(signature, active, ASSET, EXP, NOW)\n    print(f\"{state:<30} accepted={str(accepted):<5} expected={expected}\")\n    assert accepted == expected, f\"secret state {state!r} did not match the model\"\n    secret_rows.append({\"state\": state, \"accepted\": accepted})\n\nprint(\"\\nrotation invalidates old signatures; rollback to an old version resurrects them\")\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Step 5 \u2014 the register is a judgement, and it has to score like one\n\nEach row carries an inherent score and a residual score after the existing control. The vocabulary is fixed so Session 8 can append five more rows without renumbering; the ranking tells you which two risks the justification must defend. If a row's residual score is higher than its inherent score, the control made the risk worse and the row is wrong.\n\n<details class=\"th\" lang=\"th\">\n<summary>\u0e2a\u0e23\u0e38\u0e1b\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22</summary>\n\n\u0e41\u0e15\u0e48\u0e25\u0e30\u0e41\u0e16\u0e27\u0e21\u0e35\u0e04\u0e30\u0e41\u0e19\u0e19\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e27\u0e1a\u0e04\u0e38\u0e21\u0e41\u0e25\u0e30\u0e04\u0e30\u0e41\u0e19\u0e19\u0e04\u0e07\u0e40\u0e2b\u0e25\u0e37\u0e2d\u0e2b\u0e25\u0e31\u0e07\u0e04\u0e27\u0e1a\u0e04\u0e38\u0e21 \u0e04\u0e33\u0e28\u0e31\u0e1e\u0e17\u0e4c\u0e16\u0e39\u0e01\u0e01\u0e33\u0e2b\u0e19\u0e14\u0e15\u0e32\u0e22\u0e15\u0e31\u0e27\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e43\u0e2b\u0e49\u0e04\u0e23\u0e31\u0e49\u0e07\u0e17\u0e35\u0e48 8 \u0e40\u0e1e\u0e34\u0e48\u0e21\u0e2b\u0e49\u0e32\u0e41\u0e16\u0e27\u0e44\u0e14\u0e49\u0e42\u0e14\u0e22\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e40\u0e1b\u0e25\u0e35\u0e48\u0e22\u0e19\u0e40\u0e25\u0e02 \u0e41\u0e25\u0e30\u0e01\u0e32\u0e23\u0e08\u0e31\u0e14\u0e2d\u0e31\u0e19\u0e14\u0e31\u0e1a\u0e1a\u0e2d\u0e01\u0e27\u0e48\u0e32\u0e04\u0e27\u0e32\u0e21\u0e40\u0e2a\u0e35\u0e48\u0e22\u0e07\u0e2a\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e41\u0e23\u0e01\u0e17\u0e35\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e40\u0e02\u0e35\u0e22\u0e19\u0e40\u0e2b\u0e15\u0e38\u0e1c\u0e25 defended \u0e04\u0e37\u0e2d\u0e02\u0e49\u0e2d\u0e43\u0e14 \u0e16\u0e49\u0e32\u0e04\u0e30\u0e41\u0e19\u0e19\u0e04\u0e07\u0e40\u0e2b\u0e25\u0e37\u0e2d\u0e2a\u0e39\u0e07\u0e01\u0e27\u0e48\u0e32\u0e04\u0e30\u0e41\u0e19\u0e19\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e27\u0e1a\u0e04\u0e38\u0e21 \u0e41\u0e1b\u0e25\u0e27\u0e48\u0e32\u0e21\u0e32\u0e15\u0e23\u0e01\u0e32\u0e23\u0e04\u0e27\u0e1a\u0e04\u0e38\u0e21\u0e17\u0e33\u0e43\u0e2b\u0e49\u0e41\u0e22\u0e48\u0e25\u0e07 \u0e41\u0e25\u0e30\u0e41\u0e16\u0e27\u0e19\u0e31\u0e49\u0e19\u0e1c\u0e34\u0e14\n</details>\n\n<details class=\"zh\" lang=\"zh-Hans\"><summary>\u4e2d\u6587\u603b\u7ed3</summary>\n\n\u6bcf\u4e00\u884c\u90fd\u6709\u63a7\u5236\u524d\u5206\u6570\u548c\u63a7\u5236\u540e\u7684\u5269\u4f59\u5206\u6570\u3002\u8bcd\u6c47\u8868\u662f\u56fa\u5b9a\u7684\uff0c\u4f7f\u7b2c 8 \u8bfe\u53ef\u4ee5\u589e\u52a0\u4e94\u884c\u800c\u65e0\u9700\u91cd\u65b0\u7f16\u53f7\uff1b\u6392\u540d\u5219\u6307\u51fa\u5fc5\u987b\u5199\u51fa defended \u7406\u7531\u7684\u524d\u4e24\u4e2a\u98ce\u9669\u662f\u54ea\u4e9b\u3002\u5982\u679c\u5269\u4f59\u5206\u6570\u9ad8\u4e8e\u63a7\u5236\u524d\u5206\u6570\uff0c\u8bf4\u660e\u63a7\u5236\u63aa\u65bd\u4f7f\u98ce\u9669\u53d8\u5f97\u66f4\u7cdf\uff0c\u8be5\u884c\u5c31\u662f\u9519\u7684\u3002\n\n</details>\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "ALLOWED_CLASSES = {\"public\", \"internal\", \"personal\", \"sensitive\"}\nALLOWED_TREATMENTS = {\"avoid\", \"mitigate\", \"transfer\", \"accept\"}\nALLOWED_OWNERS = {\"provider\", \"customer\", \"shared\"}\n\nrows = register[\"rows\"]\nassert len(rows) == 5, \"the S7 seed register must have five rows\"\nassert [row[\"id\"] for row in rows] == [\"R01\", \"R02\", \"R03\", \"R04\", \"R05\"], \"row ids must stay R01-R05\"\n\nscored = []\nfor row in rows:\n    assert row[\"data_class\"] in ALLOWED_CLASSES, f\"{row['id']} data_class\"\n    assert row[\"treatment\"] in ALLOWED_TREATMENTS, f\"{row['id']} treatment\"\n    assert row[\"owner\"] in ALLOWED_OWNERS, f\"{row['id']} owner\"\n    for field in (\"likelihood\", \"impact\", \"residual_likelihood\", \"residual_impact\"):\n        assert isinstance(row[field], int) and 1 <= row[field] <= 5, f\"{row['id']}.{field} must be 1-5\"\n    assert row[\"residual_reasoning\"].strip(), f\"{row['id']} needs a reasoning clause\"\n    inherent = row[\"likelihood\"] * row[\"impact\"]\n    residual = row[\"residual_likelihood\"] * row[\"residual_impact\"]\n    assert residual <= inherent, f\"{row['id']} residual {residual} exceeds inherent {inherent}: the control cannot make it worse\"\n    scored.append({\"id\": row[\"id\"], \"inherent\": inherent, \"residual\": residual,\n                   \"treatment\": row[\"treatment\"], \"owner\": row[\"owner\"]})\n\nscored.sort(key=lambda item: (-item[\"residual\"], item[\"id\"]))\nprint(\"residual ranking:\")\nfor item in scored:\n    print(f\"  {item['id']}  inherent={item['inherent']:>2}  residual={item['residual']:>2}  {item['treatment']}\")\ntop = scored[:2]\nprint(\"\\nthe two you justify:\", \", \".join(item[\"id\"] for item in top))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": "results = {\n    \"seed\": SEED,\n    \"device\": DEVICE,\n    \"inventory\": inventory_result,\n    \"presign\": presign_results,\n    \"scope_matrix\": scope_results,\n    \"secret_state\": secret_rows,\n    \"register\": scored,\n    \"top_residual_risks\": [item[\"id\"] for item in scored[:2]],\n}\nout = Path(\"security_results.json\")\nout.write_text(json.dumps(results, indent=2) + \"\\n\", encoding=\"utf-8\")\nprint(\"wrote\", out.resolve())\nprint(json.dumps(results[\"top_residual_risks\"]))\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## What this proves\n\nWrite 150\u2013250 words: what the account-key delete changed and what it did not; why the presigned URL was reusable and could not be revoked; why the Worker's old URL failed at once after rotation, and what a rollback would do; and the two residual risks you would defend, with one sentence each. Attach `security_results.json`, the register, the live evidence from steps 2\u20137 of the brief, and the teardown log.\n\n## Verification\n\n**Mac verified:** run on this MacBook (Python 3.14, standard library only) \u2014 all five steps pass and `security_results.json` is written. **T4/RTX verified:** not applicable; S7 has no accelerator path. If you edit the data files, rerun the notebook: an assertion failure names the row and the field, and the fix is in the data.\n"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
