From 0de563f3ea25f03f96860f4787ef86ed4ecacc28 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Mon, 2 Nov 2026 21:56:26 -0600 Subject: [PATCH] Use explicit authenticated cipher for registry bulk transfer --- bootstrap/apps/README.md | 10 ++++++++++ scripts/registry-storage-reconcile.py | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bootstrap/apps/README.md b/bootstrap/apps/README.md index a80ba27..eddfb6b 100644 --- a/bootstrap/apps/README.md +++ b/bootstrap/apps/README.md @@ -61,3 +61,13 @@ Discovery overrides, when inventory uses different locations: Registry paths must be specific directories below `/data`. Migration requires passwordless sudo on the destination, source worker and Proxmox host. This is a copy, not ongoing replication or failover between registries. + +Bulk transfer uses a fresh, non-multiplexed SSH connection with AES-256-GCM, +compression disabled and mandatory source/destination SHA-256 verification. +`LAB_REGISTRY_TRANSFER_CIPHER` can select another supported authenticated cipher +(`aes128-gcm@openssh.com` or `chacha20-poly1305@openssh.com`). Negotiation and +transfer errors are retained in private diagnostic files. A MAC/authentication +failure aborts transfer and never publishes partial storage. Repeated SSH MAC +errors, especially alongside TLS bad-record-MAC failures, require investigation +of the endpoints and network path; cipher selection alone does not prove that +the underlying issue is repaired. diff --git a/scripts/registry-storage-reconcile.py b/scripts/registry-storage-reconcile.py index 215ea85..5184ee9 100644 --- a/scripts/registry-storage-reconcile.py +++ b/scripts/registry-storage-reconcile.py @@ -25,10 +25,14 @@ def run(command, **kwargs): timeout=kwargs.pop("timeout", 60), **kwargs).stdout.strip() -def ssh(host, user, key, command): - return ["ssh", "-i", key, "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes", - "-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=accept-new", - f"{user}@{host}", command] +def ssh(host, user, key, command, cipher=None): + options = ["ssh", "-T", "-i", key, "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes", + "-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=accept-new"] + if cipher: + options.extend(["-v", "-o", f"Ciphers={cipher}", "-o", "Compression=no", + "-o", "ControlMaster=no", "-o", "ControlPath=none", + "-o", "ServerAliveInterval=15", "-o", "ServerAliveCountMax=2"]) + return [*options, f"{user}@{host}", command] def main(): @@ -38,6 +42,8 @@ def main(): "hypervisor-user", "hypervisor-key", "source-vmid", "state-dir", "result"): parser.add_argument("--" + name, required=True) parser.add_argument("--registry-endpoint", required=True) + parser.add_argument("--transfer-cipher", default=os.environ.get("LAB_REGISTRY_TRANSFER_CIPHER", "aes256-gcm@openssh.com"), + choices=("aes256-gcm@openssh.com", "aes128-gcm@openssh.com", "chacha20-poly1305@openssh.com")) args = parser.parse_args() for path in (args.destination_path, args.source_path): if not path.startswith("/data/") or ".." in Path(path).parts or path.rstrip("/") == "/data": @@ -261,7 +267,7 @@ def prepare_local(args, path, existing_pv): 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") - print(f"Copying registry data from {args.source_host}:{args.source_path} into staging storage", flush=True) + print(f"Copying registry data from {args.source_host}:{args.source_path} into staging storage using {args.transfer_cipher}", flush=True) diagnostics = state / "diagnostics" diagnostics.mkdir(parents=True, exist_ok=True, mode=0o700) transfer_id = str(time.time_ns()) @@ -270,7 +276,10 @@ def prepare_local(args, path, existing_pv): with source_log.open("w+b") as source_errors, destination_log.open("w+b") as destination_errors: source_log.chmod(0o600) destination_log.chmod(0o600) - source = subprocess.Popen(source_ssh("sudo -n tar -C " + shlex.quote(args.source_path) + " -cpf - ."), stdout=subprocess.PIPE, stderr=source_errors) + source_command = ssh(args.source_host, args.source_user, args.source_key, + "sudo -n tar -C " + shlex.quote(args.source_path) + " -cpf - .", + cipher=args.transfer_cipher) + source = subprocess.Popen(source_command, stdout=subprocess.PIPE, stderr=source_errors) try: destination = subprocess.run(["sudo", "-n", "tar", "-C", stage, "-xpf", "-", "--no-same-owner"], stdin=source.stdout, stderr=destination_errors, timeout=1800) source.stdout.close()