Resolve verified registry tag conflicts using traced Pimox lineage
This commit is contained in:
parent
ea82de2b90
commit
c6a2758d35
|
|
@ -26,8 +26,15 @@ is prepared instead. An existing destination is checksummed and reused unchanged
|
|||
when it already contains the source files. Otherwise, non-conflicting files are
|
||||
merged in staging and the complete union is verified. The original destination
|
||||
is renamed to a timestamped backup before publishing the staged directory; a
|
||||
publication failure restores it. Conflicting files or a running Docker container
|
||||
with write access to the destination block automatic publication. Destination
|
||||
publication failure restores it. Mutable tag `current/link` conflicts prefer the
|
||||
Pimox source after checking the linked schema-2 manifest/index and all referenced
|
||||
blob hashes. Repository history (`dc59dc8`, October 1, 2026) moved the active
|
||||
registry from Debian to Pimox and routed subsequent endpoint pushes there. This
|
||||
is an explicit lineage policy, not an assumption about filesystem timestamps.
|
||||
Every selection and its old/new checksum is recorded in the migration receipt;
|
||||
the complete original Debian directory remains in the destination backup.
|
||||
Immutable blob conflicts, other unknown file conflicts, or a running Docker
|
||||
container with write access to the destination block automatic publication. Destination
|
||||
checksums must also remain stable throughout reconciliation. Existing data is
|
||||
never silently overwritten or discarded.
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,61 @@ def local_manifest(path):
|
|||
"cd " + shlex.quote(path) + " && find . -type f -print0 | sort -z | xargs -0 -r sha256sum"], timeout=1800)
|
||||
|
||||
|
||||
def resolve_registry_links(args, conflicts, source_files, destination_files):
|
||||
"""Prefer the traced active registry only for verified mutable tag links.
|
||||
|
||||
dc59dc8 moved the registry and its endpoint forwarding from Debian to
|
||||
Pimox. That establishes source lineage, not per-file timestamp ordering.
|
||||
Immutable blob conflicts must never be resolved by host or modification time.
|
||||
"""
|
||||
decisions = []
|
||||
verified = set()
|
||||
|
||||
def source_read(relative):
|
||||
return run(ssh(args.source_host, args.source_user, args.source_key,
|
||||
"sudo -n cat -- " + shlex.quote(str(Path(args.source_path) / relative))), timeout=60)
|
||||
|
||||
def verify_digest(digest, expand_manifest=False, depth=0):
|
||||
if not re.fullmatch(r"sha256:[a-f0-9]{64}", digest):
|
||||
raise RuntimeError("Registry tag contains an unsupported digest")
|
||||
if depth > 12 or len(verified) > 4096:
|
||||
raise RuntimeError("Registry manifest graph exceeds verification bounds")
|
||||
hex_digest = digest.split(":", 1)[1]
|
||||
relative = f"docker/registry/v2/blobs/sha256/{hex_digest[:2]}/{hex_digest}/data"
|
||||
if source_files.get("./" + relative) != hex_digest:
|
||||
raise RuntimeError("Preferred Pimox manifest references missing or invalid blob content")
|
||||
if not expand_manifest or digest in verified:
|
||||
return
|
||||
verified.add(digest)
|
||||
manifest = json.loads(source_read(relative))
|
||||
if not isinstance(manifest, dict) or manifest.get("schemaVersion") != 2:
|
||||
raise RuntimeError("Preferred registry tag is not a supported schema-2 manifest")
|
||||
if "manifests" in manifest:
|
||||
for descriptor in manifest["manifests"]:
|
||||
verify_digest(descriptor["digest"], expand_manifest=True, depth=depth + 1)
|
||||
else:
|
||||
if not isinstance(manifest.get("config"), dict) or not isinstance(manifest.get("layers"), list):
|
||||
raise RuntimeError("Preferred registry image has no complete config/layer descriptors")
|
||||
verify_digest(manifest["config"]["digest"], depth=depth + 1)
|
||||
for descriptor in manifest["layers"]:
|
||||
verify_digest(descriptor["digest"], depth=depth + 1)
|
||||
|
||||
for name in conflicts:
|
||||
match = re.fullmatch(r"\./docker/registry/v2/repositories/(.+)/_manifests/tags/([^/]+)/current/link", name)
|
||||
if not match:
|
||||
raise RuntimeError(f"Conflicting non-tag registry file requires review: {name}; both versions preserved")
|
||||
relative = name.removeprefix("./")
|
||||
preferred = source_read(relative)
|
||||
if hashlib.sha256((preferred + "\n").encode()).hexdigest() != source_files[name] and hashlib.sha256(preferred.encode()).hexdigest() != source_files[name]:
|
||||
raise RuntimeError("Source tag link changed during conflict inspection")
|
||||
verify_digest(preferred, expand_manifest=True)
|
||||
decisions.append({"path": name, "preferred": "source", "source_sha256": source_files[name],
|
||||
"destination_sha256": destination_files[name], "manifest_digest": preferred,
|
||||
"basis": "dc59dc8 moved the active registry and push forwarding to Pimox"})
|
||||
print(f"Registry conflict resolved: {match[1]}:{match[2]} uses verified Pimox manifest {preferred[:23]}... (pipeline lineage dc59dc8)", flush=True)
|
||||
return decisions
|
||||
|
||||
|
||||
def require_no_local_writer(path):
|
||||
docker = shutil.which("docker") or "/usr/bin/docker"
|
||||
if not Path(docker).exists():
|
||||
|
|
@ -188,6 +243,7 @@ def prepare_local(args, path, existing_pv):
|
|||
stage = run(["sudo", "mktemp", "-d", parent + "/.registry-migration.XXXXXX"])
|
||||
digest = None
|
||||
source_files = {}
|
||||
conflict_decisions = []
|
||||
if has_data:
|
||||
source_bytes = int(run(source_ssh("sudo -n du -sb " + shlex.quote(args.source_path))).split()[0])
|
||||
destination_bytes = int(run(["sudo", "du", "-sb", path]).split()[0]) if exists else 0
|
||||
|
|
@ -201,7 +257,7 @@ def prepare_local(args, path, existing_pv):
|
|||
conflicts = [name for name, checksum in source_files.items()
|
||||
if name in destination_files and destination_files[name] != checksum]
|
||||
if conflicts:
|
||||
raise RuntimeError(f"Registry has {len(conflicts)} conflicting source/destination file(s); both copies preserved, automatic overwrite refused")
|
||||
conflict_decisions = resolve_registry_links(args, conflicts, source_files, destination_files)
|
||||
special = run(source_ssh("sudo -n find " + shlex.quote(args.source_path) + " -mindepth 1 ! -type f ! -type d -print -quit"))
|
||||
if special:
|
||||
raise RuntimeError("Source registry contains non-regular files; refusing unsafe archive extraction")
|
||||
|
|
@ -266,7 +322,8 @@ def prepare_local(args, path, existing_pv):
|
|||
"source_path": args.source_path, "copied": has_data,
|
||||
"manifest_sha256": digest, "destination_backup": backup,
|
||||
"reused_destination": reuse,
|
||||
"staged_source_backup": stage}) + "\n")
|
||||
"staged_source_backup": stage,
|
||||
"conflict_decisions": conflict_decisions}) + "\n")
|
||||
receipt_tmp.chmod(0o600)
|
||||
os.replace(receipt_tmp, receipt)
|
||||
print(f"Registry storage ready at {path}; original source retained", flush=True)
|
||||
|
|
@ -353,6 +410,6 @@ def configure_local_registry_client(args):
|
|||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (RuntimeError, OSError, ValueError, subprocess.SubprocessError) as error:
|
||||
except (RuntimeError, OSError, ValueError, KeyError, TypeError, subprocess.SubprocessError) as error:
|
||||
print(f"Registry reconciliation refused: {error}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue