Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-perception): align SBOM with archive and report upstream component revisions (#4180)

Francesco Bonacci13f1907e350b
diff --git a/.github/scripts/perception_release.py b/.github/scripts/perception_release.py
index 2ec81d85c8..0b3726e65b 100644
--- a/.github/scripts/perception_release.py
+++ b/.github/scripts/perception_release.py
@@ -477,13 +477,50 @@ def spdx_id(value: str) -> str:
return "SPDXRef-" + re.sub(r"[^A-Za-z0-9.-]", "-", value)
+# Cua-authored ledger documents copied to the archive root beside the artifacts.
+STAGED_LEDGERS = {"modelLedger": "modelLedger.json", "sourceLedger": "sourceLedger.json"}
+CUA_METADATA_LICENSE = "MIT"
+
+
def generated_documents(
- manifest: Mapping[str, Any], executed_evidence: Mapping[str, Any]
+ manifest: Mapping[str, Any], executed_evidence: Mapping[str, Any], payload_root: Path
) -> tuple[dict[str, Any], dict[str, Any]]:
artifacts = sorted(manifest["artifacts"], key=lambda item: (item["kind"], item["name"]))
namespace_seed = sha256(
f"{manifest['sourceSha']}:{manifest['target']['triple']}:{manifest['version']}".encode()
).hexdigest()
+ # SBOM file entries use the exact archive paths produced by package_candidate.
+ # extension.json and metadata/* are deliberately absent: they are generated after
+ # (or contain) this SBOM, so describing them here would be circular. extension.json
+ # binds every other staged file, including metadata/sbom.spdx.json, by SHA-256.
+ sbom_files = [
+ {
+ "fileName": f"./{staged_artifact_path(item).as_posix()}",
+ "SPDXID": spdx_id(f"File-{item['kind']}-{item['name']}"),
+ "checksums": [{"algorithm": "SHA256", "checksumValue": item["sha256"]}],
+ "licenseConcluded": item["license"]["spdx"],
+ "licenseInfoInFiles": [item["license"]["spdx"]],
+ "copyrightText": "NOASSERTION",
+ }
+ for item in artifacts
+ ]
+ for field, staged_name in STAGED_LEDGERS.items():
+ if not manifest.get(field):
+ continue
+ sbom_files.append({
+ "fileName": f"./{staged_name}",
+ "SPDXID": spdx_id(f"File-ledger-{staged_name}"),
+ "checksums": [{
+ "algorithm": "SHA256",
+ "checksumValue": file_digest(confined_file(payload_root, str(manifest[field]))),
+ }],
+ "licenseConcluded": CUA_METADATA_LICENSE,
+ "licenseInfoInFiles": [CUA_METADATA_LICENSE],
+ "copyrightText": "NOASSERTION",
+ })
+ package_license = " AND ".join(
+ sorted({entry["licenseConcluded"] for entry in sbom_files})
+ )
sbom = {
"spdxVersion": "SPDX-2.3",
"dataLicense": "CC0-1.0",
@@ -498,29 +535,19 @@ def generated_documents(
"versionInfo": manifest["version"],
"downloadLocation": "NOASSERTION",
"filesAnalyzed": True,
- "licenseConcluded": "NOASSERTION",
- "licenseDeclared": "NOASSERTION",
- "copyrightText": "NOASSERTION",
- }
- ],
- "files": [
- {
- "fileName": f"./{KIND_DIRECTORIES[item['kind']]}/{item['name']}",
- "SPDXID": spdx_id(f"File-{item['kind']}-{item['name']}"),
- "checksums": [{"algorithm": "SHA256", "checksumValue": item["sha256"]}],
- "licenseConcluded": item["license"]["spdx"],
- "licenseInfoInFiles": [item["license"]["spdx"]],
+ "licenseConcluded": package_license,
+ "licenseDeclared": package_license,
"copyrightText": "NOASSERTION",
}
- for item in artifacts
],
+ "files": sbom_files,
"relationships": [
{
"spdxElementId": "SPDXRef-Package-cua-perception",
"relationshipType": "CONTAINS",
- "relatedSpdxElement": spdx_id(f"File-{item['kind']}-{item['name']}"),
+ "relatedSpdxElement": entry["SPDXID"],
}
- for item in artifacts
+ for entry in sbom_files
],
}
provenance = {
@@ -588,14 +615,15 @@ def extension_manifest(stage: Path, manifest: Mapping[str, Any], payload_root: P
"conversion_sha256": item["sha256"],
"license_file": notice_bindings[item["license"]["notice"]],
})
+ identities = component_identities(manifest, payload_root, model_entries)
components = [
{
"name": item["name"],
- "version": manifest["version"],
+ "version": identities[item["name"]][0],
"license": item["license"]["spdx"],
"notice": f"notices/{Path(item['license']['notice']).name}",
"source_uri": item["license"]["source"],
- "source_revision": manifest["sourceSha"],
+ "source_revision": identities[item["name"]][1],
"notice_file": notice_bindings[item["license"]["notice"]],
}
for item in artifacts
@@ -634,6 +662,63 @@ def extension_manifest(stage: Path, manifest: Mapping[str, Any], payload_root: P
}
+def component_identities(
+ manifest: Mapping[str, Any],
+ payload_root: Path,
+ model_entries: Mapping[str, Mapping[str, Any]],
+) -> dict[str, tuple[str, str]]:
+ """Return (version, source_revision) for each non-notice component.
+
+ Third-party components report their upstream identity; Cua-built items keep the
+ extension version and the Cua source commit.
+ """
+ artifacts = manifest["artifacts"]
+ cua_identity = (manifest["version"], manifest["sourceSha"])
+ source_ledger = read_json(confined_file(payload_root, str(manifest["sourceLedger"])))
+ source_entries = {entry["artifact"]: entry for entry in source_ledger["sources"]}
+ cua_source = corresponding_source_artifact(manifest)["name"]
+ identities: dict[str, tuple[str, str]] = {}
+ for item in artifacts:
+ kind = item["kind"]
+ if kind == "notice":
+ continue
+ if kind == "model":
+ revision = str(model_entries[item["name"]]["revision"])
+ identities[item["name"]] = (revision, revision)
+ elif kind == "dictionary":
+ repository = item["license"]["source"]
+ revisions = {
+ str(model_entries[model["name"]]["revision"])
+ for model in artifacts
+ if model["kind"] == "model" and model["license"]["source"] == repository
+ }
+ if len(revisions) != 1:
+ raise CandidateError(
+ f"dictionary {item['name']} must share exactly one model revision from "
+ f"{repository}; found {sorted(revisions)}"
+ )
+ revision = revisions.pop()
+ identities[item["name"]] = (revision, revision)
+ elif kind == "runtime":
+ model_manifest = next(entry for entry in artifacts if entry["kind"] == "model-manifest")
+ document = read_json(confined_file(payload_root, model_manifest["path"]))
+ version = str(document.get("onnx_runtime", {}).get("version", "")).strip()
+ if not version:
+ raise CandidateError("model-manifest.json does not declare onnx_runtime.version")
+ identities[item["name"]] = (version, f"v{version}")
+ elif kind == "source" and item["name"] != cua_source:
+ entry = source_entries.get(item["name"])
+ revision = str(entry.get("revision", "")).strip() if entry else ""
+ if not revision:
+ raise CandidateError(f"source ledger lacks a revision for {item['name']}")
+ identities[item["name"]] = (revision, revision)
+ else:
+ # worker, model-manifest, the Cua source archive, supplied verification
+ # reports, review recordings, and other Cua-authored items.
+ identities[item["name"]] = cua_identity
+ return identities
+
+
def validate_extension_manifest_bindings(extension: Mapping[str, Any]) -> None:
declared = {item["path"]: item["sha256"] for item in extension["files"]}
@@ -799,11 +884,11 @@ def package_candidate(
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(confined_file(payload_root, item["path"]), destination)
destination.chmod(0o755 if item["kind"] in {"worker", "runtime"} else 0o644)
- for field in ("modelLedger", "sourceLedger"):
- if field in manifest:
- shutil.copyfile(confined_file(payload_root, manifest[field]), stage / f"{field}.json")
+ for field, staged_name in STAGED_LEDGERS.items():
+ if manifest.get(field):
+ shutil.copyfile(confined_file(payload_root, manifest[field]), stage / staged_name)
- sbom, provenance = generated_documents(manifest, executed_evidence)
+ sbom, provenance = generated_documents(manifest, executed_evidence, payload_root)
runtime = runtime_contract(manifest)
canonical_json(stage / "metadata/artifact-manifest.json", manifest)
canonical_json(stage / "metadata/sbom.spdx.json", sbom)
diff --git a/.github/scripts/tests/test_cua_perception_release_topology.py b/.github/scripts/tests/test_cua_perception_release_topology.py
index f746c8f8c2..d688fef899 100644
--- a/.github/scripts/tests/test_cua_perception_release_topology.py
+++ b/.github/scripts/tests/test_cua_perception_release_topology.py
@@ -427,6 +427,183 @@ def test_packages_deterministically_with_catalog_sbom_and_redacted_provenance(
release.verify_checksums(first / "checksums.txt")
+def third_party_fixture(tmp_path: Path) -> tuple[Path, Path]:
+ """Fixture with upstream provenance shaped like a real staging candidate."""
+ payload, manifest_path = fixture(tmp_path)
+ manifest = json.loads(manifest_path.read_text())
+ model_ledger = json.loads((payload / "model-ledger.json").read_text())
+ source_ledger = json.loads((payload / "source-ledger.json").read_text())
+ upstream = {
+ "libonnxruntime.so": ("https://github.com/microsoft/onnxruntime", "MIT"),
+ "fixture-model.onnx": ("https://huggingface.co/microsoft/OmniParser-v2.0", "AGPL-3.0-only"),
+ "ocr-det.onnx": ("https://huggingface.co/PaddlePaddle/det", "Apache-2.0"),
+ "ocr-rec.onnx": ("https://huggingface.co/PaddlePaddle/rec", "Apache-2.0"),
+ "ocr-dictionary.txt": ("https://huggingface.co/PaddlePaddle/rec", "Apache-2.0"),
+ }
+ revisions = {"fixture-model.onnx": "icon-rev", "ocr-det.onnx": "det-rev", "ocr-rec.onnx": "rec-rev"}
+ for item in manifest["artifacts"]:
+ if item["name"] in upstream:
+ item["license"]["source"], item["license"]["spdx"] = upstream[item["name"]]
+ for entry in model_ledger["models"]:
+ entry["revision"] = revisions[entry["artifact"]]
+ entry["license"] = upstream[entry["artifact"]][1]
+ exporter = b"exporter source\n"
+ exporter_path = payload / "payload/source/exporter/onnx-1.17.0.tar.gz"
+ exporter_path.parent.mkdir(parents=True, exist_ok=True)
+ exporter_path.write_bytes(exporter)
+ manifest["artifacts"].append({
+ "kind": "source",
+ "name": "onnx-1.17.0.tar.gz",
+ "path": "payload/source/exporter/onnx-1.17.0.tar.gz",
+ "sha256": digest(exporter),
+ "size": len(exporter),
+ "license": {
+ "spdx": "BSD-3-Clause",
+ "source": "https://github.com/onnx/onnx",
+ "notice": "payload/NOTICE",
+ },
+ })
+ source_ledger["sources"].append({
+ "artifact": "onnx-1.17.0.tar.gz",
+ "artifactSha256": digest(exporter),
+ "artifactSize": len(exporter),
+ "repository": "https://github.com/onnx/onnx",
+ "revision": "57b9c6a4f6eebb09ae1b34cfb632078518f72832",
+ "license": "BSD-3-Clause",
+ "durableLocation": "candidate archive source/exporter/",
+ "sourceOfferStatus": "bundled",
+ "contentKind": "exporter-source",
+ "format": "file",
+ })
+ icon_source = b"icon weights\n"
+ (payload / "payload/source/upstream").mkdir(parents=True)
+ (payload / "payload/source/upstream/icon.pt").write_bytes(icon_source)
+ manifest["artifacts"].append({
+ "kind": "source",
+ "name": "icon.pt",
+ "path": "payload/source/upstream/icon.pt",
+ "sha256": digest(icon_source),
+ "size": len(icon_source),
+ "license": {
+ "spdx": "AGPL-3.0-only",
+ "source": "https://huggingface.co/microsoft/OmniParser-v2.0",
+ "notice": "payload/NOTICE",
+ },
+ })
+ source_ledger["sources"].append({
+ "artifact": "icon.pt",
+ "artifactSha256": digest(icon_source),
+ "artifactSize": len(icon_source),
+ "repository": "https://huggingface.co/microsoft/OmniParser-v2.0",
+ "revision": "icon-rev",
+ "license": "AGPL-3.0-only",
+ "durableLocation": "candidate archive source/upstream/",
+ "sourceOfferStatus": "bundled",
+ "contentKind": "model-source-input",
+ "format": "file",
+ })
+ binding = {
+ "artifact": "icon.pt",
+ "path": "payload/source/upstream/icon.pt",
+ "sha256": digest(icon_source),
+ "size": len(icon_source),
+ }
+ for entry in model_ledger["models"]:
+ if entry["artifact"] == "fixture-model.onnx":
+ entry["sourceArtifact"] = binding
+ (payload / "model-ledger.json").write_text(json.dumps(model_ledger))
+ (payload / "source-ledger.json").write_text(json.dumps(source_ledger))
+ manifest_path.write_text(json.dumps(manifest))
+ return payload, manifest_path
+
+
+def package_third_party_fixture(tmp_path: Path) -> tuple[Path, Path, Path]:
+ payload, manifest_path = third_party_fixture(tmp_path)
+ evidence = tmp_path / "executed.json"
+ release.run_candidate_gates(manifest_path, payload, evidence)
+ archive = release.package_candidate(
+ manifest_path, payload, tmp_path / "out", executed_evidence_path=evidence
+ )
+ return payload, manifest_path, archive
+
+
+def test_sbom_files_match_archive_paths_and_digests(tmp_path: Path) -> None:
+ _, _, archive = package_third_party_fixture(tmp_path)
+ with tarfile.open(archive) as candidate:
+ archived = {
+ member.name: digest(candidate.extractfile(member).read())
+ for member in candidate.getmembers()
+ if member.isfile()
+ }
+ sbom = json.loads(candidate.extractfile("metadata/sbom.spdx.json").read())
+ assert sbom == json.loads((tmp_path / "out/sbom.spdx.json").read_text())
+ file_names = set()
+ for entry in sbom["files"]:
+ assert entry["fileName"].startswith("./") and "//" not in entry["fileName"]
+ relative = entry["fileName"][2:]
+ assert relative in archived, relative
+ assert entry["checksums"] == [{"algorithm": "SHA256", "checksumValue": archived[relative]}]
+ file_names.add(relative)
+ assert {
+ "model-manifest.json",
+ "modelLedger.json",
+ "sourceLedger.json",
+ "source/cua-perception-source.tar.gz",
+ "source/exporter/onnx-1.17.0.tar.gz",
+ "source/upstream/icon.pt",
+ } <= file_names
+ # Only generated metadata and extension.json (which binds the SBOM) are excluded.
+ assert {
+ name for name in archived if name not in file_names
+ } == {name for name in archived if name.startswith("metadata/")} | {"extension.json"}
+ ledgers = {entry["fileName"]: entry for entry in sbom["files"] if "Ledger" in entry["fileName"]}
+ assert all(entry["licenseConcluded"] == "MIT" for entry in ledgers.values())
+ package = sbom["packages"][0]
+ expected_license = "AGPL-3.0-only AND Apache-2.0 AND BSD-3-Clause AND CC0-1.0 AND MIT"
+ assert package["licenseDeclared"] == package["licenseConcluded"] == expected_license
+ related = {item["relatedSpdxElement"] for item in sbom["relationships"]}
+ assert related == {entry["SPDXID"] for entry in sbom["files"]}
+ assert len(related) == len(sbom["files"])
+
+
+def test_components_report_upstream_identity_for_third_party_items(tmp_path: Path) -> None:
+ _, manifest_path, archive = package_third_party_fixture(tmp_path)
+ manifest = json.loads(manifest_path.read_text())
+ with tarfile.open(archive) as candidate:
+ extension = json.loads(candidate.extractfile("extension.json").read())
+ components = {
+ item["name"]: (item["version"], item["source_revision"]) for item in extension["components"]
+ }
+ cua = (manifest["version"], manifest["sourceSha"])
+ assert components["libonnxruntime.so"] == ("1", "v1")
+ assert components["fixture-model.onnx"] == ("icon-rev", "icon-rev")
+ assert components["ocr-det.onnx"] == ("det-rev", "det-rev")
+ assert components["ocr-dictionary.txt"] == ("rec-rev", "rec-rev")
+ onnx_revision = "57b9c6a4f6eebb09ae1b34cfb632078518f72832"
+ assert components["onnx-1.17.0.tar.gz"] == (onnx_revision, onnx_revision)
+ assert components["icon.pt"] == ("icon-rev", "icon-rev")
+ assert components["cua-perception-worker"] == cua
+ assert components["model-manifest.json"] == cua
+ assert components["cua-perception-source.tar.gz"] == cua
+ assert components["health.json"] == cua
+ assert all(version and revision for version, revision in components.values())
+
+
+def test_dictionary_identity_requires_one_model_revision(tmp_path: Path) -> None:
+ payload, manifest_path = third_party_fixture(tmp_path)
+ manifest = json.loads(manifest_path.read_text())
+ for item in manifest["artifacts"]:
+ if item["name"] == "ocr-det.onnx":
+ item["license"]["source"] = "https://huggingface.co/PaddlePaddle/rec"
+ manifest_path.write_text(json.dumps(manifest))
+ evidence = tmp_path / "executed.json"
+ release.run_candidate_gates(manifest_path, payload, evidence)
+ with pytest.raises(release.CandidateError, match="exactly one model revision"):
+ release.package_candidate(
+ manifest_path, payload, tmp_path / "out", executed_evidence_path=evidence
+ )
+
+
@pytest.mark.parametrize(
("binding_owner", "binding_field"),
[