Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,26 @@ environment. Verification machinery is consumed from the `receipt`
package with this repository's trust pins committed in
`scripts/receipt_pins.py`; see `releases/README.md` (immutable
post-genesis, like everything under `releases/`) for the schema, offline
verification procedure, and security limits.
verification procedure, and security limits. The gate surface,
`APPEND_GATE_SPEC.gate_surface` in `scripts/receipt_pins.py`, lists the
files in the base checkout that decide the gate's verdict:

- the gate's scripts, the trust pins, the anchors, and the append workflow;
- the files that build its interpreter and environment: `pyproject.toml`,
`uv.lock`, `uv.toml`, `.python-version`, `.python-versions`, `.venv`,
`hatch.toml`, `hatch_build.py`, `sitecustomize.py` (in `scripts/` and at
the root) and `scripts/__pycache__`;
- every `.gitattributes` git applies to these files when it checks out the
judge: at the root and in `releases/`, which decide the anchor bytes, and
in `scripts/`, `.github/` and `.github/workflows/`. Receipt already refuses
`filter`, `ident` and `working-tree-encoding` on the gate's scripts and the
workflow, and line endings do not change how Python reads a script, so
these three cannot change a verdict today; listing them keeps that from
depending on the receipt version.

The gate refuses a pull request that changes any of them together with the
ledger, and names them when a pull request changes only them. Not covered
yet: a new module on the judge's import path that shadows one of its imports,
under `scripts/` or at the root (the editable install adds the root), and the
project's own build inputs such as `README.md`. Closing that means running the
judge isolated (`python -I`) without installing this project.
66 changes: 66 additions & 0 deletions scripts/receipt_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,79 @@
(f"releases/anchors/{LEDGER_SPEC.producer_public_key_filename}"),
}
),
# The files in the judging (base) checkout that decide the gate's verdict:
# the gate's code and pins, the trust anchors, the files that build its
# interpreter and environment, the append workflow, and the .gitattributes
# files git applies to any of them. A proposal that changes one of them
# together with the ledger is refused as mixed, and a proposal that
# changes only these is reported by name. A "dir/**" entry matches only
# paths below dir, so each one is also listed bare: otherwise a symlink or
# file committed at dir itself would be unclassified, and dropped on the
# data path.
#
# Not covered: modules on the judge's import path that this list cannot
# name in advance.
# - The judge runs a script in scripts/, so scripts/ is sys.path[0], and
# both pull request jobs also put it on PYTHONPATH. A new module there
# shadows an import: a scripts/tempfile.py, a scripts/receipt/ package,
# or another spelling of sitecustomize or receipt_pins (a package, a
# sourceless .pyc, an extension module).
# - uv installs this project editable, and the .pth file that adds puts
# the repository root on sys.path. So a new module at the root, such as
# a sitecustomize/ package, can be imported at startup, and the editable
# build also reads README.md.
# Listing all of scripts/ would close the first, but it would also refuse
# a catalog-builder change shipped with its regenerated
# ledger/series_catalog.json (as in #128), which the catalog tests require
# to land together. The fix for both is in how the workflow runs the
# judge: isolated (python -I), without installing this project.
gate_surface=frozenset(
{
"scripts/check_thesis_facts_append.py",
"scripts/verify_release_chain.py",
"scripts/canonical_json.py",
"scripts/cut_release_manifest.py",
"scripts/receipt_pins.py",
# Python runs a sitecustomize.py it finds on PYTHONPATH, or on
# the path the editable install adds, at startup, and loads an
# unchecked-hash .pyc from __pycache__ in place of its source.
"scripts/sitecustomize.py",
"sitecustomize.py",
"scripts/__pycache__",
"scripts/__pycache__/**",
".github/workflows/thesis-facts-append.yml",
# `uv sync --locked --no-dev --project <base>` builds the judge's
# environment from these, including the receipt version that
# implements the gate. uv also reads the project's uv.toml and
# .python-version (or .python-versions), and reuses a .venv it
# finds there. It installs this project with hatchling, which
# reads hatch.toml and runs a hatch_build.py hook when one is
# configured.
"pyproject.toml",
"uv.lock",
"uv.toml",
".python-version",
".python-versions",
".venv",
".venv/**",
"hatch.toml",
"hatch_build.py",
# Git applies the .gitattributes in each directory above a file
# when it checks out the judge, so every one above an entry here
# is listed. The root and releases/ files decide the bytes of the
# anchors the judge pins. The scripts/ file reaches the gate's
# Python, and the .github/ files reach no entry here but the
# workflow, which the judge does not read. Receipt refuses filter,
# ident and working-tree-encoding on every surface path, and
# Python reads either line ending, so these three cannot change a
# verdict today. They are listed so that this does not depend on
# the receipt version.
".gitattributes",
"releases/.gitattributes",
"scripts/.gitattributes",
".github/.gitattributes",
".github/workflows/.gitattributes",
"releases/anchors",
"releases/anchors/**",
}
),
Expand Down
74 changes: 74 additions & 0 deletions tests/test_receipt_shim_transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,80 @@ def test_original_oracle_fixtures_are_authenticated(name: str) -> None:
assert _sha256(ORIGINAL_FIXTURES / name) == ORIGINAL_HASHES[name]


def _original_surface(name: str) -> frozenset[str]:
"""Read one surface literal from the authenticated original gate."""

import ast

module = ast.parse(
(ORIGINAL_FIXTURES / "check_thesis_facts_append.py").read_text(encoding="utf-8")
)
for node in module.body:
if (
isinstance(node, ast.Assign)
and [getattr(target, "id", None) for target in node.targets] == [name]
and isinstance(node.value, ast.Call)
):
return frozenset(ast.literal_eval(node.value.args[0]))
raise AssertionError(f"{name} not found in the original gate")


def test_the_shim_gate_surface_deliberately_widens_the_originals() -> None:
"""The one place the pair is meant to disagree about classification.

The originals' GATE_SURFACE predates scripts/receipt_pins.py, where the
shim's trust pins now live, and never listed the files that build the
judge's interpreter and environment or the .gitattributes git checks it
out with. The shim's surface covers every original entry and adds exactly
those, so a proposal that changes one of them is refused as mixed (with
rows) or named as gate-only (alone), where the original judged it as plain
data.
No case in this file changes such a file, so the byte-identity asserted
here is unaffected; tests/test_thesis_append_shim_isolation.py holds the
shim to the wider surface.
"""

from receipt.append_gate import _matches_surface

from scripts.receipt_pins import APPEND_GATE_SPEC

original_gate = _original_surface("GATE_SURFACE")
shim_gate = APPEND_GATE_SPEC.gate_surface
for entry in original_gate:
if entry.endswith("/**"):
assert entry in shim_gate, entry
else:
assert _matches_surface(entry, shim_gate), entry
assert _original_surface("DATA_SURFACE") == APPEND_GATE_SPEC.data_surface
widened = {
"scripts/receipt_pins.py",
"scripts/sitecustomize.py",
"sitecustomize.py",
"scripts/__pycache__",
"scripts/__pycache__/**",
"pyproject.toml",
"uv.lock",
"uv.toml",
".python-version",
".python-versions",
".venv",
".venv/**",
"hatch.toml",
"hatch_build.py",
".gitattributes",
"releases/.gitattributes",
"scripts/.gitattributes",
".github/.gitattributes",
".github/workflows/.gitattributes",
"releases/anchors",
}
assert shim_gate - original_gate == widened
for entry in widened:
named = entry.removesuffix("/**")
assert not _matches_surface(named, original_gate), entry
assert _matches_surface(named, shim_gate), entry


@pytest.fixture(scope="session")
def original_oracle(tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
"""Copy the authenticated original scripts into one executable tree."""
Expand Down
Loading
Loading