Use explicit authenticated cipher for registry bulk transfer
This commit is contained in:
parent
40aff369bf
commit
0de563f3ea
|
|
@ -61,3 +61,13 @@ Discovery overrides, when inventory uses different locations:
|
||||||
Registry paths must be specific directories below `/data`. Migration requires
|
Registry paths must be specific directories below `/data`. Migration requires
|
||||||
passwordless sudo on the destination, source worker and Proxmox host. This is a
|
passwordless sudo on the destination, source worker and Proxmox host. This is a
|
||||||
copy, not ongoing replication or failover between registries.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,14 @@ def run(command, **kwargs):
|
||||||
timeout=kwargs.pop("timeout", 60), **kwargs).stdout.strip()
|
timeout=kwargs.pop("timeout", 60), **kwargs).stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def ssh(host, user, key, command):
|
def ssh(host, user, key, command, cipher=None):
|
||||||
return ["ssh", "-i", key, "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes",
|
options = ["ssh", "-T", "-i", key, "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes",
|
||||||
"-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=accept-new",
|
"-o", "ConnectTimeout=10", "-o", "StrictHostKeyChecking=accept-new"]
|
||||||
f"{user}@{host}", command]
|
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():
|
def main():
|
||||||
|
|
@ -38,6 +42,8 @@ def main():
|
||||||
"hypervisor-user", "hypervisor-key", "source-vmid", "state-dir", "result"):
|
"hypervisor-user", "hypervisor-key", "source-vmid", "state-dir", "result"):
|
||||||
parser.add_argument("--" + name, required=True)
|
parser.add_argument("--" + name, required=True)
|
||||||
parser.add_argument("--registry-endpoint", 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()
|
args = parser.parse_args()
|
||||||
for path in (args.destination_path, args.source_path):
|
for path in (args.destination_path, args.source_path):
|
||||||
if not path.startswith("/data/") or ".." in Path(path).parts or path.rstrip("/") == "/data":
|
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"))
|
special = run(source_ssh("sudo -n find " + shlex.quote(args.source_path) + " -mindepth 1 ! -type f ! -type d -print -quit"))
|
||||||
if special:
|
if special:
|
||||||
raise RuntimeError("Source registry contains non-regular files; refusing unsafe archive extraction")
|
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 = state / "diagnostics"
|
||||||
diagnostics.mkdir(parents=True, exist_ok=True, mode=0o700)
|
diagnostics.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||||
transfer_id = str(time.time_ns())
|
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:
|
with source_log.open("w+b") as source_errors, destination_log.open("w+b") as destination_errors:
|
||||||
source_log.chmod(0o600)
|
source_log.chmod(0o600)
|
||||||
destination_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:
|
try:
|
||||||
destination = subprocess.run(["sudo", "-n", "tar", "-C", stage, "-xpf", "-", "--no-same-owner"], stdin=source.stdout, stderr=destination_errors, timeout=1800)
|
destination = subprocess.run(["sudo", "-n", "tar", "-C", stage, "-xpf", "-", "--no-same-owner"], stdin=source.stdout, stderr=destination_errors, timeout=1800)
|
||||||
source.stdout.close()
|
source.stdout.close()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue