Take authorized_keys on the cidata drive instead of ssh.json

The JSON wrapper was the one piece of autoinstall input that wasn't an
existing format: the other files are the configurator's own output, and
the keys end up in sshd's authorized_keys anyway. So take that file
directly -- one key per line, comments and key options work as they do
everywhere else -- and drop the parsing in between. The only thing JSON
bought was parse-error detection, and the phase still fails loudly when
the file carries no usable keys.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier HanssonandClaude Fable 5 committed 2026-08-04 06:08:33 -07:00
1 parent be68a76a44
commit f11a70c6ba
9 files changed
+80 -86

No files matched your search

@@ -18,7 +18,7 @@ class InstallContext:
full_name: str
email: str
encrypt: bool
ssh_keys_path: Path | None
authorized_keys_path: Path | None
user_configuration: dict
user_credentials: dict
@@ -60,7 +60,7 @@ class InstallContext:
full_name=_read_text(os.environ.get("OMARCHY_INSTALL_FULL_NAME_FILE")),
email=_read_text(os.environ.get("OMARCHY_INSTALL_EMAIL_FILE")),
encrypt=_read_text(os.environ.get("OMARCHY_INSTALL_ENCRYPT_FILE")).lower() in ("true", "yes", "1"),
ssh_keys_path=_optional_path(os.environ.get("OMARCHY_INSTALL_SSH_KEYS_FILE")),
authorized_keys_path=_optional_path(os.environ.get("OMARCHY_INSTALL_AUTHORIZED_KEYS_FILE")),
user_configuration=user_configuration,
user_credentials=json.loads(creds_path.read_text()),
arch_config_path=arch_config_path,
@@ -107,8 +107,8 @@ def _default_omarchy_install(user_configuration: dict) -> dict[str, Any]:
def _optional_path(path: str | None) -> Path | None:
"""A path the caller always passes but that need not exist. The live ISO
passes --ssh-keys-file on every install; only autoinstall drives put a file
there."""
passes --authorized-keys-file on every install; only autoinstall drives put
a file there."""
if not path:
return None
p = Path(path)
@@ -22,7 +22,6 @@ Phase ordering (full-disk and protected/pre-mounted):
from __future__ import annotations
import hashlib
import json
import os
import re
import shutil
@@ -1314,10 +1313,10 @@ def configure_login(ctx: InstallContext) -> None:
# ─────────────────────────────────────────────────────────────────────────────
def configure_ssh_access(ctx: InstallContext) -> None:
if ctx.ssh_keys_path is None:
if ctx.authorized_keys_path is None:
return
keys = _authorized_keys(ctx.ssh_keys_path)
keys = _authorized_keys(ctx.authorized_keys_path)
info(f"› installing {len(keys)} SSH key(s) for {ctx.username}")
ssh_dir = ctx.target / "home" / ctx.username / ".ssh"
@@ -1362,21 +1361,20 @@ def configure_ssh_access(ctx: InstallContext) -> None:
def _authorized_keys(path: Path) -> list[str]:
"""Parse the autoinstall ssh.json: a JSON array of public key strings.
"""Read the autoinstall authorized_keys: sshd's own format, one public key
per line, with blank lines and # comments dropped.
Raise rather than skip on anything unusable. An install that "succeeds"
into a machine nobody can log into is worse than one that stops with the
reason on screen.
"""
try:
keys = json.loads(path.read_text())
except (OSError, json.JSONDecodeError) as exc:
raise RuntimeError(f"{path} is not readable JSON: {exc}") from exc
lines = path.read_text().splitlines()
except OSError as exc:
raise RuntimeError(f"{path} is not readable: {exc}") from exc
if not isinstance(keys, list) or not all(isinstance(key, str) for key in keys):
raise RuntimeError(f"{path} must be a JSON array of public key strings")
keys = [key.strip() for key in keys if key.strip()]
keys = [line.strip() for line in lines]
keys = [key for key in keys if key and not key.startswith("#")]
if not keys:
raise RuntimeError(f"{path} contains no SSH keys")